public void invokeAsyncResponse(Message msg) { msg = processResponse(msg); // Handle async response Relates_To message ID value @SuppressWarnings("unchecked") AsyncResponseInvoker<RuntimeEndpointReference> respInvoker = (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); // TODO - this deals with the Local case only - not distributed if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) { RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress(); msg.setFrom(responseEPR); String msgID = respInvoker.getRelatesToMsgID(); msg.getHeaders().put("RELATES_TO", msgID); } // end if InvokerAsyncResponse thePrevious = (InvokerAsyncResponse)getPrevious(); if (thePrevious != null ) thePrevious.invokeAsyncResponse(msg); } // end method invokeAsyncResponse
/** * Fetches the Endpoint identified by an endpoint URI * - the Endpoint is retrieved from the DomainRegistry * @param uri - the URI of the Endpoint * @return - the Endpoint corresponding to the URI, or null if no Endpoint is found which has the * supplied URI */ private RuntimeEndpoint retrieveEndpoint(String uri) { if( uri == null ) return null; if( domainRegistry == null ) domainRegistry = getEndpointRegistry( uri ); if( domainRegistry == null ) return null; // TODO what if more than one Endpoint gets returned?? return (RuntimeEndpoint) domainRegistry.findEndpoint(uri).get(0); } // end method retrieveEndpoint
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); requestEndpoint = retrieveEndpoint(endpointURI); responseEndpointReference = retrieveEndpointReference(endpointReferenceURI); messageFactory = getMessageFactory(); if (responseTargetAddress instanceof EndpointReference){ // fix the target as in this case it will be an EPR EndpointReference epr = (EndpointReference)responseTargetAddress; responseTargetAddress = (T)retrieveEndpointReference(epr.getURI()); } // end if } // end method readObject
public Message processRequest(Message msg){ if (passByValue) { Object transformedBody = bindingSCATransformer.transformInput(msg.getBody()); msg.setBody(transformedBody); } // end if ep.getInvocationChains(); if ( !ep.getCallbackEndpointReferences().isEmpty() ) { RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) ep.getCallbackEndpointReferences().get(0); // Place a link to the callback EPR into the message headers... msg.getHeaders().put("ASYNC_CALLBACK", asyncEPR ); } // end if if( ep.isAsyncInvocation() ) { // Get the message ID String msgID = (String)msg.getHeaders().get("MESSAGE_ID"); String operationName = msg.getOperation().getName(); // Create a response invoker and add it to the message headers AsyncResponseInvoker<RuntimeEndpointReference> respInvoker = new AsyncResponseInvoker<RuntimeEndpointReference>(ep, null, epr, msgID, operationName, getMessageFactory()); respInvoker.setBindingType("SCA_LOCAL"); msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker); } // end if return msg; } // end method processRequest
if ( respInvoker == null ) return msg; String responseAddress = respInvoker.getResponseTargetAddress(); String relatedMsg = respInvoker.getRelatesToMsgID();
/** * Setup the necessary infrastructure for the Async response handling * @param msg * @param callbackAddress */ private void setupAsyncResponse(Message msg, String callbackAddress) { if( !endpoint.isAsyncInvocation() ) return; endpoint.createAsyncServerCallback(); RuntimeEndpointReference asyncCallback = endpoint.getAsyncServerCallback(); // Create a response invoker, containing the callback address and add it to the message headers AsyncResponseInvoker<String> respInvoker = new AsyncResponseInvoker<String>(endpoint, asyncCallback, callbackAddress, (String)msg.getHeaders().get(Constants.MESSAGE_ID), msg.getOperation().getName(), messageFactory); msg.getHeaders().put(Constants.ASYNC_RESPONSE_INVOKER, respInvoker); } // end method setupAsyncResponse
/** * Create an Async Response Endpoint * @param msg - the Tuscany message * @param respInvoker - the AsyncResponseInvoker for the async response * @return - an Endpoint which embodies the callback address */ private Endpoint createAsyncResponseEndpoint(Message msg, AsyncResponseInvoker<String> respInvoker) { String callbackAddress = respInvoker.getResponseTargetAddress(); if( callbackAddress == null ) return null; // Get the necessary factories ExtensionPointRegistry registry = endpointReference.getCompositeContext().getExtensionPointRegistry(); FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); RuntimeAssemblyFactory assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); WebServiceBindingFactory webServiceBindingFactory = (WebServiceBindingFactory)modelFactories.getFactory(WebServiceBindingFactory.class); // Create the endpoint RuntimeEndpoint callbackEndpoint = (RuntimeEndpoint)assemblyFactory.createEndpoint(); // Add a binding WebServiceBinding cbBinding = webServiceBindingFactory.createWebServiceBinding(); cbBinding.setURI(callbackAddress); callbackEndpoint.setBinding(cbBinding); // Embed the response Address URI callbackEndpoint.setURI(callbackAddress); callbackEndpoint.setUnresolved(true); return callbackEndpoint; } // end method createAsyncResponseEndpoint
public Message processRequest(Message msg){ if (passByValue) { Object transformedBody = bindingSCATransformer.transformInput(msg.getBody()); msg.setBody(transformedBody); } // end if ep.getInvocationChains(); if ( !ep.getCallbackEndpointReferences().isEmpty() ) { RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) ep.getCallbackEndpointReferences().get(0); // Place a link to the callback EPR into the message headers... msg.getHeaders().put("ASYNC_CALLBACK", asyncEPR ); } // end if if( ep.isAsyncInvocation() ) { // Get the message ID String msgID = (String)msg.getHeaders().get("MESSAGE_ID"); String operationName = msg.getOperation().getName(); // Create a response invoker and add it to the message headers AsyncResponseInvoker<RuntimeEndpointReference> respInvoker = new AsyncResponseInvoker<RuntimeEndpointReference>(ep, null, epr, msgID, operationName, getMessageFactory()); respInvoker.setBindingType("SCA_LOCAL"); msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker); } // end if return msg; } // end method processRequest
new AsyncResponseInvoker<String>(endpoint, null, asyncRespAddr, msgID, operationName, getMessageFactory()); msg.getHeaders().put("ASYNC_RESPONSE_INVOKER", respInvoker);
public void invokeAsyncResponse(Message msg) { msg = processResponse(msg); // Handle async response Relates_To message ID value @SuppressWarnings("unchecked") AsyncResponseInvoker<RuntimeEndpointReference> respInvoker = (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); // TODO - this deals with the Local case only - not distributed if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) { RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress(); msg.setFrom(responseEPR); String msgID = respInvoker.getRelatesToMsgID(); msg.getHeaders().put("RELATES_TO", msgID); } // end if InvokerAsyncResponse thePrevious = (InvokerAsyncResponse)getPrevious(); if (thePrevious != null ) thePrevious.invokeAsyncResponse(msg); } // end method invokeAsyncResponse
if( context != null ) { registry = context.getExtensionPointRegistry(); domainRegistry = getEndpointRegistry( registry ); if( domainRegistry != null ) { this.registry = registry; if( registry != null ) { domainRegistry = getEndpointRegistry( registry );
AsyncResponseInvoker<?> respInvoker = (AsyncResponseInvoker<?>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) { RuntimeEndpointReference responseEPR = (RuntimeEndpointReference)respInvoker.getResponseTargetAddress(); msg.setFrom(responseEPR); String msgID = respInvoker.getRelatesToMsgID(); msg.getHeaders().put("RELATES_TO", msgID);
AsyncResponseInvoker<?> respInvoker = (AsyncResponseInvoker<?>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) { RuntimeEndpointReference responseEPR = (RuntimeEndpointReference)respInvoker.getResponseTargetAddress(); msg.setFrom(responseEPR); String msgID = respInvoker.getRelatesToMsgID(); msg.getHeaders().put("RELATES_TO", msgID);