Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
  */
 
 package org.apache.tuscany.sca.core.invocation;
 
 import java.util.List;
 import java.util.Map;
 
A class that wraps the mechanics for sending async responses and hides the decision about whether the response will be processed natively or non-natively This class is generic, based on the type of targetAddress information required by the Binding that creates it
 
 public class AsyncResponseInvoker<T> implements InvokerAsyncResponseSerializable {
    
    
 
 	private static final long serialVersionUID = -7992598227671386588L;
 	
 	private transient RuntimeEndpoint requestEndpoint;
     private transient RuntimeEndpointReference responseEndpointReference
     private T responseTargetAddress;
     private String relatesToMsgID;
     private String operationName;
     private transient MessageFactory messageFactory;
     private String bindingType = "";
     private boolean isNativeAsync;
     
     private String endpointURI;
     private String endpointReferenceURI;
     private String domainURI;
 
 	private transient EndpointRegistry endpointRegistry;
 	private transient ExtensionPointRegistry registry;
     
     public AsyncResponseInvoker(RuntimeEndpoint requestEndpoint,
 			RuntimeEndpointReference responseEndpointReference,
 			T responseTargetAddressString relatesToMsgID
 			String operationNameMessageFactory messageFactory) {
 		super();
 		this. = requestEndpoint;
 		this. = responseEndpointReference;
 		this. = responseTargetAddress;
 		this. = relatesToMsgID;
 		this. = operationName;
 		this. = messageFactory;
 		
 		CompositeContext context = null;
 		if(requestEndpoint != null ) {
 			 = requestEndpoint.getURI();
 			context = requestEndpoint.getCompositeContext(); 
// end if
		if(responseEndpointReference != null ) {
			 = responseEndpointReference.getURI();
			context = responseEndpointReference.getCompositeContext();
		}
		ifcontext != null ) {
			 = context.getDomainURI();
// end if
        if ((requestEndpoint.getBindingProvider() instanceof EndpointAsyncProvider) &&
                (((EndpointAsyncProvider)requestEndpoint.getBindingProvider()).supportsNativeAsync())){
        	 = true;
        } else {
        	 = false;
        } // end if
// end constructor

    
If you have a Tuscany message you can call this
    public void invokeAsyncResponse(Message responseMessage) {
    	responseMessage.getHeaders().put(.this);
    	responseMessage.getHeaders().put(.);
    	
        if (){
            // process the response as a native async response
            .invokeAsyncResponse(responseMessage);
        } else {
            // process the response as a non-native async response
            .invoke(responseMessage);
        }
    } // end method invokeAsyncReponse(Message)
    
    public T getResponseTargetAddress() {
	}
	public void setResponseTargetAddress(T responseTargetAddress) {
		this. = responseTargetAddress;
	}
	}
	public void setRelatesToMsgID(String relatesToMsgID) {
		this. = relatesToMsgID;
	}

Invokes the async response where the parameter is Java bean(s) - this method creates a Tuscany message

Parameters:
args the response data
headers - any header
    public void invokeAsyncResponse(Object argsMap<StringObjectheaders) {
        
        Message msg = .createMessage();
        msg.setOperation(getOperationargs ));
        
        // If this is not native async, then any Throwable is being passed as a parameter and
        // requires wrapping
        if( ! && args instanceof Throwable ) {
        	args = new AsyncFaultWrapper( (Throwableargs ); 
        } // end if
        
        // If this is not native async, then the message must contain an array of args since
        // this is what is expected when invoking an EPR for the async response...
        if( ! ) {
        	Object[] objs = new Object[1];
        	objs[0] = args;
        	args = objs;
        } // end if
        msg.setTo();
        
        ifheaders != null ) {
        	msg.getHeaders().putAll(headers);
        }
        
        ifargs instanceof Throwable ) {
        	msg.setFaultBody(args);
        } else {
        	msg.setBody(args);
        } // end if
        
        invokeAsyncResponse(msg);
        
    } // end method invokeAsyncResponse(Object)
	private Operation getOperationObject args ) {
		if ) {
			for (Operation op : ops) {
				if.equals(op.getName()) ) return op;
// end for
			return null;
else {
			 = "setResponse";
			ifargs instanceof Throwable ) {  = "setWrappedFault"; }
			for (Operation op : ops) {
				if.equals(op.getName()) ) return op;
// end for
			return null;
// end if 
// end getOperation
	public void setBindingType(String bindingType) {
		this. = bindingType;
// end method setBindingType
	public String getBindingType() {
		return ;
// end method getBindingType
	return this.;
    }
    }
			RuntimeEndpointReference responseEndpointReference) {
		this. = responseEndpointReference;
    }
    @SuppressWarnings("unchecked")
    {
	    in.defaultReadObject();
	    
	    
	    
	    if ( instanceof EndpointReference){
	        // fix the target as in this case it will be an EPR
	    } // end if    
    } // end method readObject	

    
Gets a message factory

Returns:
    private MessageFactory getMessageFactory() {
// end method getMessageFactory
Fetches the EndpointReference identified by an endpoint reference URI

Parameters:
uri - the URI of the endpoint reference
Returns:
- the EndpointReference matching the supplied URI - null if no EPR is found which matches the URI
		ifuri == null ) return null;
    	if == null ) return null;
		// If there is more than EndpointReference with the uri...
		ifrefs.isEmpty() ) return null;
		// TODO: what if there is more than 1 EPR with the given URI?
		return (RuntimeEndpointReferencerefs.get(0);
// end method retrieveEndpointReference
Fetches the Endpoint identified by an endpoint URI - the Endpoint is retrieved from the EndpointRegistry

Parameters:
uri - the URI of the Endpoint
Returns:
- the Endpoint corresponding to the URI, or null if no Endpoint is found which has the supplied URI
		ifuri == null ) return null;
		if == null )  = getEndpointRegistryuri );
		if == null ) return null;
		// TODO what if more than one Endpoint gets returned??
// end method retrieveEndpoint
Gets the EndpointRegistry which contains an Endpoint with the supplied URI

Parameters:
uri - The URI of an Endpoint
Returns:
- the EndpointRegistry containing the Endpoint with the supplied URI - null if no such EndpointRegistry can be found
		ExtensionPointRegistry registry   = null;
		EndpointRegistry endpointRegistry = null;
		CompositeContext context = CompositeContext.getCurrentCompositeContext();
		ifcontext == null &&  != null ) context = .getCompositeContext();
		ifcontext != null ) {
			registry = context.getExtensionPointRegistry();
			endpointRegistry = getEndpointRegistryregistry );
			ifendpointRegistry != null ) {
				this. = registry;
				return endpointRegistry;
// end if
// end if
		// Deal with the case where there is no context available
    	forNodeFactory factory : NodeFactory.getNodeFactories() ) {
    		registry = factory.getExtensionPointRegistry();
    		ifregistry != null ) {
    			// Find the actual Endpoint in the EndpointRegistry
        		endpointRegistry = getEndpointRegistryregistry );
                
                ifendpointRegistry != null ) {
                    forEndpoint endpoint : endpointRegistry.findEndpoint(uri) ) {
                    	// TODO: For the present, simply return the first registry with a matching endpoint
                    	this. = registry;
                    	return endpointRegistry;
                    } // end for
                } // end if 
    		} // end if
        } // end for
		return null;
// end method getEndpointRegistry
	
    
Get the EndpointRegistry

Parameters:
registry - the ExtensionPoint registry
Returns:
the EndpointRegistry - will be null if the EndpointRegistry cannot be found
        DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(registry);
        
        ifdomainRegistryFactory == null ) return null;
        
        // Find the first endpoint registry that matches the domain name 
        if != null ) {
	        forEndpointRegistry endpointRegistry : domainRegistryFactory.getEndpointRegistries() ) {
	        	if.equalsendpointRegistry.getDomainURI() ) ) return endpointRegistry;
	        } // end for
        } // end if
        
        // if there was no domainName to match, simply return the first EndpointRegistry...
        EndpointRegistry endpointRegistry = (EndpointRegistrydomainRegistryFactory.getEndpointRegistries().toArray()[0];
        
    	
    	return endpointRegistry;
    } // end method 
// end class
New to GrepCode? Check out our FAQ X