diff options
Diffstat (limited to 'sca-java-2.x/trunk')
8 files changed, 329 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/itest/ws/pom.xml b/sca-java-2.x/trunk/itest/ws/pom.xml index bcaf958df0..f042aa4b6d 100644 --- a/sca-java-2.x/trunk/itest/ws/pom.xml +++ b/sca-java-2.x/trunk/itest/ws/pom.xml @@ -51,6 +51,7 @@ <module>contribution-callback-fullspec</module> <module>contribution-callback-promotion</module> <module>contribution-doc-lit-wrapped</module> + <module>contribution-rpc-lit</module> <module>external-client</module> <module>external-service</module> <module>launcher-axis2</module> 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<OMNode> list = new ArrayList<OMNode>();
+ 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";
diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java index 47cf44265f..4ecde7f4d3 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WSDLServiceGenerator.java @@ -31,6 +31,8 @@ import java.util.logging.Logger; import javax.wsdl.Binding; import javax.wsdl.Definition; import javax.wsdl.Import; +import javax.wsdl.Message; +import javax.wsdl.Part; import javax.wsdl.Port; import javax.wsdl.PortType; import javax.wsdl.Service; @@ -260,6 +262,23 @@ public class WSDLServiceGenerator { } helper.createBindingOperations(def, binding, portType); binding.setUndefined(false); + + // set binding style based on the interface specified by the + // user if one is available + // TODO - set encoding style also currently default to literal + if (wsdlDefinition != null && wsdlDefinition.getDefinition() != null){ + Message firstMessage = (Message)wsdlDefinition.getDefinition().getMessages().values().iterator().next(); + Part firstPart = (Part)firstMessage.getParts().values().iterator().next(); + if (firstPart.getTypeName() != null){ + for (Object ext : binding.getExtensibilityElements()){ + if (ext instanceof SOAPBinding){ + ((SOAPBinding)ext).setStyle("rpc"); + break; + } + } + } + } + def.addBinding(binding); String endpointURI = computeActualURI(wsBinding, null); diff --git a/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java b/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java index c8ae5827a1..126847da59 100644 --- a/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java +++ b/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java @@ -214,5 +214,30 @@ public interface WebServiceBinding extends Binding { * @param definition the generated WSDL definitions document */ void setGeneratedWSDLDocument(Definition definition); - -} + + + /* + * Returns true if the WSDL style is rpc/encoded + */ + boolean isRpcEncoded(); + + /* + * Returns true if the WSDL style is rpc/literal + */ + boolean isRpcLiteral(); + + /* + * Returns true if the WSDL style is doc/encoded + */ + boolean isDocEncoded(); + + /* + * Returns true is the WSDL style is doc/literal + */ + boolean isDocLiteralUnwrapped(); + + /* + * Returns true if the WSDL style is doc/literal/wrapped + */ + boolean isDocLiteralWrapped(); +} diff --git a/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java b/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java index 9fc60c2224..544e543c88 100644 --- a/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java +++ b/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java @@ -23,9 +23,15 @@ import java.util.ArrayList; import java.util.List; import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; import javax.wsdl.Definition; +import javax.wsdl.Message; +import javax.wsdl.Part; import javax.wsdl.Port; import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPBinding; +import javax.wsdl.extensions.soap.SOAPBody; +import javax.wsdl.extensions.soap12.SOAP12Body; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Extensible; @@ -71,6 +77,9 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi private InterfaceContract bindingInterfaceContract; private Element endPointReference; private Definition generatedWSDLDocument; + private boolean isDocumentStyle; + private boolean isLiteralEncoding; + private boolean isMessageWrapped; protected WebServiceBindingImpl() { } @@ -131,6 +140,8 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi if (binding == null) { if (getWSDLDefinition() != null && wsdlDefinition.getBinding() != null) { binding = wsdlDefinition.getBinding(); + setIsDocumentStyle(); + setIsLiteralEncoding(); } } return binding; @@ -191,6 +202,8 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi public void setBinding(Binding binding) { this.binding = binding; + setIsDocumentStyle(); + setIsLiteralEncoding(); } public void setBindingName(QName bindingName) { @@ -293,6 +306,8 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi public void setGeneratedWSDLDocument(Definition definition) { this.generatedWSDLDocument = definition; + setIsDocumentStyle(); + setIsLiteralEncoding(); } public QName getType() { @@ -318,5 +333,87 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi } public void setOperationSelector(OperationSelector operationSelector) { - } + } + + protected void setIsDocumentStyle() { + + if (binding == null){ + if (wsdlDefinition != null && wsdlDefinition.getDefinition() != null){ + Message firstMessage = (Message)wsdlDefinition.getDefinition().getMessages().values().iterator().next(); + Part firstPart = (Part)firstMessage.getParts().values().iterator().next(); + if (firstPart.getTypeName() != null){ + isDocumentStyle = false; + return; + } + } + + // default to document style + isDocumentStyle = true; + return; + } else { + for (Object ext : binding.getExtensibilityElements()){ + if (ext instanceof SOAPBinding){ + if (((SOAPBinding)ext).getStyle().equals("rpc")){ + isDocumentStyle = false; + return; + } else { + isDocumentStyle = true; + return; + } + } + } + isDocumentStyle = true; + return; + } + + } + + protected void setIsLiteralEncoding() { + + if (binding == null){ + // default to literal encoding + isLiteralEncoding = true; + return; + } else { + for(Object ext : ((BindingOperation)binding.getBindingOperations().get(0)).getBindingInput().getExtensibilityElements()){ + if (ext instanceof SOAPBody){ + if (((SOAPBody)ext).getUse().equals("literal")){ + isLiteralEncoding = true; + return; + } else { + isLiteralEncoding = false; + return; + } + } + } + isLiteralEncoding = true; + return; + } + } + + protected void setIsMessageWrapped() { + isMessageWrapped = getBindingInterfaceContract().getInterface().getOperations().get(0).isWrapperStyle(); + } + + public boolean isRpcEncoded() { + return (!isDocumentStyle) && (!isLiteralEncoding); + } + + public boolean isRpcLiteral() { + return (!isDocumentStyle) && (isLiteralEncoding); + } + + public boolean isDocEncoded() { + return (isDocumentStyle) && (!isLiteralEncoding); + } + + public boolean isDocLiteralUnwrapped() { + setIsMessageWrapped(); + return (isDocumentStyle) && (isLiteralEncoding) && (!isMessageWrapped); + } + + public boolean isDocLiteralWrapped() { + setIsMessageWrapped(); + return (isDocumentStyle) && (isLiteralEncoding) &&(isMessageWrapped); + } } |