From 93e8a5439342f2543907da37c33e38e0c37b00e0 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 30 Jun 2010 10:06:46 +0000 Subject: TUSCANY-3614 - first pass at support for rpc/lit. Does the right sort of thing now but some of the code is in the wrong place so some refactoring still to do git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@959254 13f79535-47bb-0310-9956-ffa450edef68 --- .../provider/Axis2ReferenceBindingInvoker.java | 86 ++++++++++++++++++++-- .../provider/Axis2ReferenceBindingProvider.java | 15 ++++ .../provider/Axis2ServiceBindingProvider.java | 14 ++++ .../ws/axis2/provider/TuscanyServiceProvider.java | 78 +++++++++++++++++++- 4 files changed, 184 insertions(+), 9 deletions(-) (limited to 'sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main') diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java index 47eefa4641..4d71e97568 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java @@ -21,14 +21,20 @@ package org.apache.tuscany.sca.binding.ws.axis2.provider; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; +import javax.wsdl.BindingOperation; import javax.wsdl.Operation; import javax.wsdl.PortType; +import javax.wsdl.extensions.soap.SOAPBinding; import javax.xml.namespace.QName; +import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNode; import org.apache.axiom.soap.SOAPBody; import org.apache.axiom.soap.SOAPEnvelope; @@ -99,6 +105,15 @@ public class Axis2ReferenceBindingInvoker implements Invoker { final OperationClient operationClient = createOperationClient(msg); msg.setBindingContext(operationClient); msg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(msg); + + if (wsBinding.isRpcLiteral()){ + // remove the wrapping element containing + // the operation response name + OMElement operationResponseElement = msg.getBody(); + if (operationResponseElement != null){ + msg.setBody(operationResponseElement.getChildElements().next()); + } + } } catch (AxisFault e) { if (e.getDetail() != null ) { @@ -120,15 +135,74 @@ public class Axis2ReferenceBindingInvoker implements Invoker { SOAPEnvelope env = soapFactory.getDefaultEnvelope(); Object[] args = (Object[])msg.getBody(); if (args != null && args.length > 0) { - 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."); + + 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.getWSDLDefinition().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); diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java index 27b90b0251..b73bfdd5c1 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java @@ -40,7 +40,9 @@ import javax.xml.transform.dom.DOMSource; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.soap.SOAPBody; import org.apache.axiom.soap.SOAPFactory; import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.EndpointReferenceHelper; @@ -122,6 +124,19 @@ public class Axis2ReferenceBindingProvider extends Axis2BaseBindingProvider impl for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { pp.configureBinding(this); } + + // check the WSDL style as we currently only support some of them + if (wsBinding.isRpcEncoded()){ + throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint reference " + endpointReference); + } + + if (wsBinding.isDocEncoded()){ + throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint reference " + endpointReference); + } + + if (wsBinding.isDocLiteralUnwrapped()){ + //throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint reference " + endpointReference); + } } public void start() { diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java index 925ecbc8f7..103180f534 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java @@ -166,6 +166,20 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem // TODO - do we need to go back to configurator? } wsBinding.setURI(deployedURI); + + // Check the WSDL style as we only support some of them + + if (wsBinding.isRpcEncoded()){ + throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint " + endpoint); + } + + if (wsBinding.isDocEncoded()){ + throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint " + endpoint); + } + + // if (wsBinding.isDocLiteralUnwrapped()){ + // throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint " + endpoint); + // } } private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java index 4e3e085ee8..a09d18c1dd 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/TuscanyServiceProvider.java @@ -20,11 +20,19 @@ package org.apache.tuscany.sca.binding.ws.axis2.provider; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.logging.Logger; +import javax.wsdl.BindingOperation; import javax.xml.namespace.QName; +import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNode; +import org.apache.axiom.soap.SOAPBody; import org.apache.axiom.soap.SOAPHeader; import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.AddressingConstants; @@ -42,6 +50,7 @@ import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.oasisopen.sca.ServiceRuntimeException; public class TuscanyServiceProvider { private static final Logger logger = Logger.getLogger(TuscanyServiceProvider.class.getName()); @@ -101,10 +110,35 @@ public class TuscanyServiceProvider { // create a message object and set the args as its body Message msg = messageFactory.createMessage(); - Object[] args = new Object[] {requestOM}; - msg.setBody(args); msg.setOperation(operation); msg.setBindingContext(inMC); + + if (wsBinding.isRpcLiteral()){ + // remove the wrapping element containing + // the operation name + Iterator iter = requestOM.getChildElements(); + List list = new ArrayList(); + while(iter.hasNext()){ + OMNode node = (OMNode)iter.next(); + list.add(node); + } + + Object[] args = list.toArray(); + msg.setBody(args); + + } else if (wsBinding.isRpcEncoded()){ + throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint " + endpoint); + } else if (wsBinding.isDocEncoded()){ + throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint " + endpoint); + //} else if (wsBinding.isDocLiteralUnwrapped()){ + // throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint " + endpoint); + } else if (wsBinding.isDocLiteralWrapped() || + wsBinding.isDocLiteralUnwrapped()){ + Object[] args = new Object[] {requestOM}; + msg.setBody(args); + } else { + throw new ServiceRuntimeException("Unrecognized WSDL style for endpoint " + endpoint); + } //FIXME: can we use the Axis2 addressing support for this? SOAPHeader header = inMC.getEnvelope().getHeader(); @@ -141,7 +175,45 @@ public class TuscanyServiceProvider { if(response.isFault()) { throw new InvocationTargetException((Throwable) response.getBody()); } - return response.getBody(); + + OMElement responseOM = response.getBody(); + + if (wsBinding.isRpcLiteral()){ + // add the response wrapping element + 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.getBindingOutput().getExtensibilityElements()){ + if (ext instanceof javax.wsdl.extensions.soap.SOAPBody){ + wrapperNamespace = ((javax.wsdl.extensions.soap.SOAPBody)ext).getNamespaceURI(); + break loopend; + } + } + } + } + } + + if (wrapperNamespace == null){ + wrapperNamespace = wsBinding.getWSDLDefinition().getNamespace(); + } + + QName operationResponseQName = new QName(wrapperNamespace, + msg.getOperation().getName() + "Response"); + OMElement operationResponseElement = factory.createOMElement(operationResponseQName); + operationResponseElement.addChild(responseOM); + responseOM = operationResponseElement; + } + + return responseOM; } // end method private static String WS_REF_PARMS = "WS_REFERENCE_PARAMETERS"; -- cgit v1.2.3