}
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.getServiceClient().createClient(wsdlOperationName);
operationClient.setOptions(options);
ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
// set callback endpoint and callback ID for WS-Addressing header
EndpointReference fromEPR = null;
org.apache.tuscany.sca.runtime.EndpointReference callbackEPR = parameters.getCallbackReference();
if (callbackEPR != null) {
fromEPR = new EndpointReference(callbackEPR.getBinding().getURI());
}
Object callbackID = parameters.getCallbackID();
if (callbackID != null) {
if (fromEPR == null) {
fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
}
//FIXME: serialize callback ID to XML in case it is not a string
fromEPR.addReferenceParameter(CALLBACK_ID_REFPARM_QN, callbackID.toString());
}
// set conversation ID for WS-Addressing header
Object conversationId = parameters.getConversationID();
if (conversationId != null) {
if (fromEPR == null) {
fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
}
//FIXME: serialize conversation ID to XML in case it is not a string
fromEPR.addReferenceParameter(CONVERSATION_ID_REFPARM_QN, conversationId.toString());
}
// add WS-Addressing header
//FIXME: is there any way to use the Axis2 addressing support for this?
if (fromEPR != null) {
SOAPEnvelope sev = requestMC.getEnvelope();
SOAPHeader sh = sev.getHeader();
OMElement epr =
EndpointReferenceHelper.toOM(sev.getOMFactory(),
fromEPR,
QNAME_WSA_FROM,
AddressingConstants.Final.WSA_NAMESPACE);
sh.addChild(epr);
requestMC.setFrom(fromEPR);
}
// Set any message headers required by policy
// Get the header from the tuscany message
// If its not already an OM convert it to OM
// add it to the envelope header
// if target endpoint was not specified when this invoker was created,
// use dynamically specified target endpoint passed in on this call
if (options.getTo() == null) {
org.apache.tuscany.sca.runtime.EndpointReference ep = msg.getTo();
if (ep != null) {
requestMC.setTo(new EndpointReference(ep.getURI()));
} else {
throw new RuntimeException("Unable to determine destination endpoint");
}
} else {
requestMC.setTo(new EndpointReference(options.getTo().getAddress()));
}
// 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();