/** * Set the WorkContext for the current thread. * The current work context is returned and must be restored after the invocation is complete. * Typical usage would be: * <pre> * WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext); * try { * ... invoke user code ... * } finally { * PojoWorkContextTunnel.setThreadWorkContext(old); * } * </pre> * @param context * @return the current work context for the thread; this must be restored after the invocation is made */ public static Message setMessageContext(Message context) { Message old = CONTEXT.get(); CONTEXT.set(context); PREVIOUS_CONTEXT.set(old); // TUSCANY-3770: Remove thread context information when the request invocation has completed if (context == msg) { removeMessageContext(); removePreviousMessageContext(); } return old; }
/** * Sets the values of various headers in the response message */ private void setResponseHeaders() { // Is there an existing message context? Message msgContext = ThreadMessageContext.getMessageContext(); if( msgContext == null ) { // Create a message context msgContext = msgFactory.createMessage(); } // end if // Add in the header for the RelatesTo Message ID msgContext.getHeaders().put(Constants.RELATES_TO, messageID); ThreadMessageContext.setMessageContext(msgContext); } // end method setResponseHeaders
public Subject getSecuritySubject() { Message msgContext = ThreadMessageContext.getMessageContext(); if (msgContext == null){ // message in thread context could be null if the user has // spun up a new thread inside their component implementation return null; } Subject subject = null; for (Object header : msgContext.getHeaders().values()){ if (header instanceof Subject){ subject = (Subject)header; break; } } return subject; }
ThreadMessageContext.removeMessageContext();
public Message invokeBinding(Message msg) { Message context = ThreadMessageContext.setMessageContext(msg); try { return invocable.getBindingInvocationChain().getHeadInvoker().invoke(msg); } finally { ThreadMessageContext.setMessageContext(context); } } // end method invokeBinding
/** * @return */ public static RuntimeComponent getCurrentComponent() { Message message = ThreadMessageContext.getMessageContext(); if (message != null) { Endpoint to = message.getTo(); if (to == null) { return null; } RuntimeComponent component = (RuntimeComponent)message.getTo().getComponent(); return component; } return null; }
ThreadMessageContext.removeMessageContext();
/** * Async Invoke of the Binding Chain * @param msg - the message to use in the invocation */ public void invokeBindingAsync(Message msg) { Message context = ThreadMessageContext.setMessageContext(msg); try { ((InvokerAsyncRequest)invocable.getBindingInvocationChain().getHeadInvoker()).invokeAsyncRequest(msg); } catch (Throwable t ) { // TODO - consider what best to do with exception t.printStackTrace(); } finally { ThreadMessageContext.setMessageContext(context); } // end try } // end method invokeBindingAsync
/** * Set the WorkContext for the current thread. * The current work context is returned and must be restored after the invocation is complete. * Typical usage would be: * <pre> * WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext); * try { * ... invoke user code ... * } finally { * PojoWorkContextTunnel.setThreadWorkContext(old); * } * </pre> * @param context * @return the current work context for the thread; this must be restored after the invocation is made */ public static Message setMessageContext(Message context) { Message old = CONTEXT.get(); CONTEXT.set(context); PREVIOUS_CONTEXT.set(old); // TUSCANY-3770: Remove thread context information when the request invocation has completed if (context == msg) { removeMessageContext(); removePreviousMessageContext(); } return old; }
msg.setBody(args); Message msgContext = ThreadMessageContext.getMessageContext(); ThreadMessageContext.setMessageContext(msg); return; } finally { ThreadMessageContext.setMessageContext(msgContext);
/** * @return */ public static RuntimeComponent getCurrentComponent() { Message message = ThreadMessageContext.getMessageContext(); if (message != null) { Endpoint to = message.getTo(); if (to == null) { return null; } RuntimeComponent component = (RuntimeComponent)message.getTo().getComponent(); return component; } return null; }
public void run() { Message context = ThreadMessageContext.setMessageContext(msg); try { Message response = null; Throwable ex = null; try { response = next.invoke(msg); } catch (Throwable t) { ex = t; } // Tuscany-2225 - Did the @OneWay method complete successfully? // (i.e. no exceptions) if (response != null && response.isFault()) { // The @OneWay method threw an Exception. Lets log it and // then pass it on to the WorkScheduler so it can notify any // listeners ex = (Throwable)response.getBody(); } if (ex != null) { LOGGER.log(Level.SEVERE, "Exception from @OneWay invocation", ex); throw new ServiceRuntimeException("Exception from @OneWay invocation", ex); } } finally { ThreadMessageContext.setMessageContext(context); } } });
msg.setBody(args); Message msgContext = ThreadMessageContext.getMessageContext(); ThreadMessageContext.setMessageContext(msg); ThreadMessageContext.setMessageContext(msgContext);
public String getServiceName() { Message msgContext = ThreadMessageContext.getMessageContext(); if (msgContext != null && msgContext.getTo() != null){ return msgContext.getTo().getService().getName(); } else { // message in thread context could be null (or the default message where to == null) // if the user has spun up a new thread inside their component implementation return null; } }
public Message invoke(InvocationChain chain, Message msg) { if (invocable instanceof Endpoint) { msg.setTo((Endpoint)invocable); } else if (invocable instanceof EndpointReference) { msg.setFrom((EndpointReference)invocable); } Invoker headInvoker = chain.getHeadInvoker(); Operation operation = chain.getTargetOperation(); msg.setOperation(operation); Message msgContext = ThreadMessageContext.setMessageContext(msg); try { return headInvoker.invoke(msg); } finally { ThreadMessageContext.setMessageContext(msgContext); } }
msg.setBody(args); Message msgContext = ThreadMessageContext.getMessageContext(); ThreadMessageContext.setMessageContext(msg); ThreadMessageContext.setMessageContext(msgContext);
public <B> ServiceReference<B> getServiceReference() { Message msgContext = ThreadMessageContext.getMessageContext(); if (msgContext == null || msgContext.getTo() == null){ // message in thread context could be null (or the default message where to == null) // if the user has spun up a new thread inside their component implementation return null; } // FIXME: [rfeng] Is this the service reference matching the caller side? RuntimeEndpoint to = (RuntimeEndpoint) msgContext.getTo(); RuntimeComponent component = (RuntimeComponent) to.getComponent(); ServiceReference<B> callableReference = component.getComponentContext().getServiceReference(null, to); return callableReference; }
Message msgContext = ThreadMessageContext.setMessageContext(msg); try { try { ThreadMessageContext.setMessageContext(msgContext);
this.callbackEPRs = callbackEPRs; Message msgContext = ThreadMessageContext.getMessageContext();
@SuppressWarnings("unchecked") public <CB> ServiceReference<CB> getCallbackReference() { Message msgContext = ThreadMessageContext.getMessageContext(); if (msgContext == null || msgContext.getTo() == null){ // message in thread context could be null (or the default message where to == null) // if the user has spun up a new thread inside their component implementation return null; } Endpoint to = msgContext.getTo(); RuntimeComponentService service = (RuntimeComponentService) to.getService(); RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference(); if (callbackReference == null) { return null; } JavaInterface javaInterface = (JavaInterface) callbackReference.getInterfaceContract().getInterface(); Class<CB> javaClass = (Class<CB>)javaInterface.getJavaClass(); List<EndpointReference> wires = callbackReference.getEndpointReferences(); ServiceReferenceImpl ref = new CallbackServiceReferenceImpl(javaClass, wires); return ref; } }