public static String getApplication(Invocation invocation, String defaultValue) { if (invocation == null || invocation.getAttachments() == null) { throw new IllegalArgumentException("Bad invocation instance"); } return invocation.getAttachment(DUBBO_APPLICATION_KEY, defaultValue); }
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request, TransactionResponseImpl response) { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); transactionInterceptor.beforeSendRequest(request); if (request.getTransactionContext() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput output = new HessianOutput(baos); try { output.writeObject(request.getTransactionContext()); } catch (IOException ex) { logger.error("Error occurred in remote call!", ex); throw new RemotingException(ex.getMessage()); } String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray()); attachments.put(TransactionContext.class.getName(), transactionContextContent); } }
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request, TransactionResponseImpl response) { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); transactionInterceptor.beforeSendRequest(request); if (request.getTransactionContext() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput output = new HessianOutput(baos); try { output.writeObject(request.getTransactionContext()); } catch (IOException ex) { logger.error("Error occurred in remote call!", ex); throw new RemotingException(ex.getMessage()); } String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray()); attachments.put(TransactionContext.class.getName(), transactionContextContent); } }
RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());
RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());
public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); RpcResult result = (RpcResult) invoker.invoke(invocation); Object value = result.getValue(); if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) { CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value; result.setValue(null); result.setException(null); if (wrapped.isFailure()) { result.setException(wrapped.getError()); } else { result.setValue(wrapped.getValue()); } } return result; }
public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); RpcResult result = (RpcResult) invoker.invoke(invocation); Object value = result.getValue(); if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) { CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value; result.setValue(null); result.setException(null); if (wrapped.isFailure()) { result.setException(wrapped.getError()); } else { result.setValue(wrapped.getValue()); } // String propagatedBy = (String) wrapped.getVariable(RemoteCoordinator.class.getName()); // String identifier = compensableCoordinator.getIdentifier(); } return result; }
if (kind.equals(Kind.CLIENT)) { span = tracer.nextSpan(); injector.inject(span.context(), invocation.getAttachments()); } else { TraceContextOrSamplingFlags extracted = extractor.extract(invocation.getAttachments()); span = extracted.context() != null ? tracer.joinSpan(extracted.context())
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (omegaContext != null) { invocation.getAttachments().put(GLOBAL_TX_ID_KEY, omegaContext.globalTxId()); invocation.getAttachments().put(LOCAL_TX_ID_KEY, omegaContext.localTxId()); } if (omegaContext != null && omegaContext.globalTxId() != null) { LOG.debug("Added {} {} and {} {} to dubbo invocation", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(), LOCAL_TX_ID_KEY, omegaContext.localTxId()}); } else { LOG.debug("Cannot inject transaction ID, as the OmegaContext is null or cannot get the globalTxId."); } if (invoker != null) { return invoker.invoke(invocation); } return null; } }
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (omegaContext != null) { String globalTxId = invocation.getAttachment(GLOBAL_TX_ID_KEY); if (globalTxId == null) { LOG.debug("Cannot inject transaction ID, no such omega context global id: {}", GLOBAL_TX_ID_KEY); } else { omegaContext.setGlobalTxId(globalTxId); omegaContext.setLocalTxId(invocation.getAttachment(LOCAL_TX_ID_KEY)); LOG.debug("Added {} {} and {} {} to omegaContext", new Object[] {GLOBAL_TX_ID_KEY, omegaContext.globalTxId(), LOCAL_TX_ID_KEY, omegaContext.localTxId()}); } invocation.getAttachments().put(GLOBAL_TX_ID_KEY, null); invocation.getAttachments().put(LOCAL_TX_ID_KEY, null); } else { LOG.debug("Cannot inject transaction ID, as the OmegaContext is null."); } try { if (invoker != null) { return invoker.invoke(invocation); } else { return null; } } finally { if (omegaContext != null) { omegaContext.clear(); } } } }
@Override public void put(String key, String value) { inv.getAttachments().put(key, value); }
public static String getApplication(Invocation invocation, String defaultValue) { if (invocation == null || invocation.getAttachments() == null) { throw new IllegalArgumentException("Bad invocation instance"); } return invocation.getAttachment(DUBBO_APPLICATION_KEY, defaultValue); }
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { invocation.getAttachments().putAll(RpcContext.getContext().getAttachments()); return invoker.invoke(invocation); } }
public RpcInvocation(Invocation invocation) { this(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); }
public RpcInvocation(Invocation invocation) { this(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); }
public RpcInvocation(Invocation invocation) { this(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); }
public RpcInvocation(Invocation invocation) { this(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); }
protected Span extractTraceInfo(Tracer tracer, Invoker<?> invoker, Invocation inv) { String operationName = JbootDubboTracingFilterKits.buildOperationName(invoker, inv); Tracer.SpanBuilder span = tracer.buildSpan(operationName); try { SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(inv.getAttachments())); if (spanContext != null) { span.asChildOf(spanContext); } } catch (Exception e) { span.withTag("Error", "extract from request fail, error msg:" + e.getMessage()); } return span.startManual(); }
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException { String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY); if (ConfigUtils.isNotEmpty(token)) { Class<?> serviceType = invoker.getInterface(); Map<String, String> attachments = inv.getAttachments(); String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY); if (! token.equals(remoteToken)) { throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider " + RpcContext.getContext().getLocalHost()); } } return invoker.invoke(inv); }
public Result invoke(Invoker<?> invoker, Invocation inv) throws JahhanException { String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY); if (ConfigUtils.isNotEmpty(token)) { Class<?> serviceType = invoker.getInterface(); Map<String, String> attachments = inv.getAttachments(); String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY); if (! token.equals(remoteToken)) { throw new JahhanException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider " + RpcContext.getContext().getLocalHost()); } } return invoker.invoke(inv); }