final MessageContext requestMC = new MessageContext();
requestMC.setEnvelope(env);
// Axis2 operationClients can not be shared so create a new one for each request
final OperationClient operationClient = serviceClient.createClient(wsdlOperationName);
operationClient.setOptions(options);
Endpoint callbackEndpoint;
AsyncResponseInvoker<String> respInvoker = (AsyncResponseInvoker<String>) msg.getHeaders().get(Constants.ASYNC_RESPONSE_INVOKER);
if( respInvoker != null ) {
callbackEndpoint = createAsyncResponseEndpoint( msg, respInvoker );
msg.setTo(callbackEndpoint);
} else {
callbackEndpoint = msg.getFrom().getCallbackEndpoint();
} // end if
SOAPEnvelope sev = requestMC.getEnvelope();
SOAPHeader sh = sev.getHeader();
// Add WS-Addressing header for the invocation of a bidirectional service
if (callbackEndpoint != null) {
// Load the actual callback endpoint URI into an Axis EPR ready to form the content of the wsa:From header
// In Tuscany the ws binding is used as a remote delegate for the sca binding
// so we have to take care to pass the sca uri in the delegate case.
EndpointReference fromEPR = null;
if (callbackEndpoint.getBinding().getType().equals(SCABinding.TYPE)){
fromEPR = new EndpointReference(callbackEndpoint.getURI());
} else {
fromEPR = new EndpointReference(callbackEndpoint.getBinding().getURI());
}
// pass the callback structure URI as a reference parameter
// this allows callback endpoints to be looked up via the registry when
// the ws binding is being used as a delegate from the sca binding
//fromEPR.addReferenceParameter(QNAME_CALLACK_EP_URI, callbackEndpoint.getURI());
addWSAFromHeader( sh, fromEPR );
addWSAActionHeader( sh );
addWSAMessageIDHeader( sh, (String)msg.getHeaders().get("MESSAGE_ID"));
requestMC.setFrom(fromEPR);
} // end if
String toAddress = getToAddress( msg );
requestMC.setTo( new EndpointReference(toAddress) );
// For callback references, add wsa:To, wsa:Action and wsa:RelatesTo headers
if( isInvocationForCallback( msg ) ) {
addWSAToHeader( sh, toAddress, msg );
addWSAActionHeader( sh );
addWSARelatesTo( sh, msg );
} // end if
// Allow privileged access to read properties. Requires PropertiesPermission read in security policy.
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() throws AxisFault {
operationClient.addMessageContext(requestMC);
return null;
}
});
} catch (PrivilegedActionException e) {
throw (AxisFault)e.getException();