in modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java [154:291]
protected OperationClient createOperationClient(Message msg) throws AxisFault {
SOAPEnvelope env = soapFactory.getDefaultEnvelope();
Object[] args = (Object[])msg.getBody();
if (args != null && args.length > 0) {
if (wsBinding.isRpcLiteral()){
// create the wrapping element containing
// the operation name
OMFactory factory = OMAbstractFactory.getOMFactory();
String wrapperNamespace = null;
// the rpc style creates a wrapper with a namespace where the namespace is
// defined on the wsdl binding operation. If no binding is provided by the
// user then default to the namespace of the WSDL itself.
if (wsBinding.getBinding() != null){
Iterator iter = wsBinding.getBinding().getBindingOperations().iterator();
loopend:
while(iter.hasNext()){
BindingOperation bOp = (BindingOperation)iter.next();
if (bOp.getName().equals(msg.getOperation().getName())){
for (Object ext : bOp.getBindingInput().getExtensibilityElements()){
if (ext instanceof javax.wsdl.extensions.soap.SOAPBody){
wrapperNamespace = ((javax.wsdl.extensions.soap.SOAPBody)ext).getNamespaceURI();
break loopend;
}
}
}
}
}
if (wrapperNamespace == null){
wrapperNamespace = wsBinding.getUserSpecifiedWSDLDefinition().getNamespace();
}
QName operationQName = new QName(wrapperNamespace,
msg.getOperation().getName());
OMElement operationNameElement = factory.createOMElement(operationQName);
// add the parameters as children of the operation name element
for (Object bc : args) {
if (bc instanceof OMElement) {
operationNameElement.addChild((OMElement)bc);
} else {
throw new IllegalArgumentException( "Can't handle mixed payloads between OMElements and other types for endpoint reference " + endpointReference);
}
}
SOAPBody body = env.getBody();
body.addChild(operationNameElement);
} else if (wsBinding.isRpcEncoded()){
throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint reference " + endpointReference);
} else if (wsBinding.isDocEncoded()){
throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint reference " + endpointReference);
// } else if (wsBinding.isDocLiteralUnwrapped()){
// throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint reference " + endpointReference);
} else if (wsBinding.isDocLiteralWrapped() ||
wsBinding.isDocLiteralUnwrapped()){
// it's doc/lit
SOAPBody body = env.getBody();
for (Object bc : args) {
if (bc instanceof OMElement) {
body.addChild((OMElement)bc);
} else {
throw new IllegalArgumentException( "Can't handle mixed payloads between OMElements and other types for endpoint reference " + endpointReference);
}
}
} else {
throw new ServiceRuntimeException("Unrecognized WSDL style for endpoint reference " + endpointReference);
}
}
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();
}
return operationClient;
} // end method createOperationClient