diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca')
3 files changed, 146 insertions, 20 deletions
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 126847da59..22ea63bd89 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 @@ -154,18 +154,24 @@ public interface WebServiceBinding extends Binding { void setBinding(javax.wsdl.Binding binding); /** - * Returns the WSDL definition. + * Returns the WSDL definition that was specified by the + * user either via and interface.wsdl or via a wsdlElement + * on the binding. This may be empty if no WSDL was specified + * explicitly in which case the generated WSDL should contain + * a full WSDL description + * * @return the WSDL definition */ - WSDLDefinition getWSDLDefinition(); + WSDLDefinition getUserSpecifiedWSDLDefinition(); /** * Sets the WSDL definition if one was specified by the user in the - * composite file + * composite file either via and interface.wsdl or via a wsdlElement + * on the binding * * @param wsdlDefinition the WSDL definition */ - void setDefinition(WSDLDefinition wsdlDefinition); + void setUserSpecifiedWSDLDefinition(WSDLDefinition wsdlDefinition); /** * Returns the WSDL namespace. @@ -215,29 +221,51 @@ public interface WebServiceBinding extends Binding { */ void setGeneratedWSDLDocument(Definition definition); + /** + * Returns string from the WSDL that represents the SOAP binding transport + */ + String getBindingTransport(); - /* + /** * 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(); + + /** + * Returns true if the WSDL style is doc/literal + * and the mapping to the interface is bare + */ + boolean isDocLiteralBare(); + + /** + * Returns true is the WSBinding is configured, via WSDL, + * to use an HTTP transport + */ + boolean isHTTPTransport(); + + /** + * Returns true is the WSBinding is configured, via WSDL, + * to use a JMS transport + */ + boolean isJMSTransport(); } 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 544e543c88..9cda2978d3 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 @@ -138,10 +138,9 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi public Binding getBinding() { if (binding == null) { - if (getWSDLDefinition() != null && wsdlDefinition.getBinding() != null) { + if (getUserSpecifiedWSDLDefinition() != null && wsdlDefinition.getBinding() != null) { binding = wsdlDefinition.getBinding(); - setIsDocumentStyle(); - setIsLiteralEncoding(); + determineWSDLCharacteristics(); } } return binding; @@ -202,8 +201,7 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi public void setBinding(Binding binding) { this.binding = binding; - setIsDocumentStyle(); - setIsLiteralEncoding(); + determineWSDLCharacteristics(); } public void setBindingName(QName bindingName) { @@ -246,7 +244,7 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi this.serviceName = serviceName; } - public WSDLDefinition getWSDLDefinition() { + public WSDLDefinition getUserSpecifiedWSDLDefinition() { if (wsdlDefinition == null) { Interface iface = bindingInterfaceContract.getInterface(); if (iface instanceof WSDLInterface) { @@ -256,7 +254,7 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi return wsdlDefinition; } - public void setDefinition(WSDLDefinition wsdlDefinition) { + public void setUserSpecifiedWSDLDefinition(WSDLDefinition wsdlDefinition) { this.wsdlDefinition = wsdlDefinition; } @@ -306,8 +304,7 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi public void setGeneratedWSDLDocument(Definition definition) { this.generatedWSDLDocument = definition; - setIsDocumentStyle(); - setIsLiteralEncoding(); + determineWSDLCharacteristics(); } public QName getType() { @@ -335,6 +332,16 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi public void setOperationSelector(OperationSelector operationSelector) { } + /** + * Some items get calculated and cached as they are used are runtime + * to decide what message processing is required + */ + protected void determineWSDLCharacteristics() { + setIsDocumentStyle(); + setIsLiteralEncoding(); + setIsMessageWrapped(); + } + protected void setIsDocumentStyle() { if (binding == null){ @@ -392,7 +399,9 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi } protected void setIsMessageWrapped() { - isMessageWrapped = getBindingInterfaceContract().getInterface().getOperations().get(0).isWrapperStyle(); + if (getBindingInterfaceContract() != null){ + isMessageWrapped = getBindingInterfaceContract().getInterface().getOperations().get(0).isWrapperStyle(); + } } public boolean isRpcEncoded() { @@ -416,4 +425,30 @@ class WebServiceBindingImpl implements WebServiceBinding, PolicySubject, Extensi setIsMessageWrapped(); return (isDocumentStyle) && (isLiteralEncoding) &&(isMessageWrapped); } + + public boolean isDocLiteralBare() { + setIsMessageWrapped(); + return (isDocumentStyle) && (isLiteralEncoding); + } + + public boolean isHTTPTransport() { + return getBindingTransport().equals("http://schemas.xmlsoap.org/soap/http"); + } + + public boolean isJMSTransport() { + return getBindingTransport().equals("http://schemas.xmlsoap.org/soap/jms"); + } + + public String getBindingTransport() { + if (binding != null){ + for (Object ext : binding.getExtensibilityElements()){ + if (ext instanceof SOAPBinding){ + return ((SOAPBinding)ext).getTransportURI(); + } + } + } + + // if no binding is explicitly specified by the user then default to http + return "http://schemas.xmlsoap.org/soap/http"; + } } diff --git a/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java index ee03aeee21..0b81dbbb5a 100644 --- a/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java +++ b/sca-java-2.x/trunk/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java @@ -24,6 +24,8 @@ import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import javax.wsdl.Binding; @@ -31,6 +33,7 @@ import javax.wsdl.Port; import javax.wsdl.PortType; import javax.wsdl.Service; import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPBinding; import javax.wsdl.extensions.soap12.SOAP12Address; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; @@ -132,6 +135,10 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem if (name != null) { wsBinding.setName(name); } + + // a collection of endpoint specifications so that we can test that + // only one is present + List<String> endpointSpecifications = new ArrayList<String>(); // Read URI String uri = getURIString(reader, URI); @@ -149,6 +156,7 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem } catch (URISyntaxException ex){ error(monitor, "InvalidURISyntax", reader, ex.getMessage()); } + endpointSpecifications.add("uri"); } // BWS20020 @@ -182,6 +190,8 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem // Read a wsdl.service localName = localName.substring("wsdl.service(".length(), localName.length() - 1); wsBinding.setServiceName(new QName(namespace, localName)); + + endpointSpecifications.add("#wsdl.service"); } else if (localName.startsWith("wsdl.port")) { @@ -195,6 +205,8 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); wsBinding.setPortName(localName.substring(s + 1)); } + + endpointSpecifications.add("#wsdl.port"); } else if (localName.startsWith("wsdl.endpoint")) { // Read a wsdl.endpoint @@ -207,6 +219,7 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); wsBinding.setEndpointName(localName.substring(s + 1)); } + } else if (localName.startsWith("wsdl.binding")) { // Read a wsdl.binding @@ -237,7 +250,9 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem error(monitor, "MustUseWsdlBinding", reader, wsdlElement); throw new ContributionReadException(wsdlElement + " must use wsdl.binding when using wsa:EndpointReference"); } + wsBinding.setEndPointReference(EndPointReferenceHelper.readEndPointReference(reader)); + endpointSpecifications.add("wsa:EndpointReference"); } } break; @@ -248,6 +263,11 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem break; } } + + if (endpointSpecifications.size() > 1){ + error(monitor, "MultipleEndpointsSpecified", reader, endpointSpecifications.toString() ); + } + return wsBinding; } @@ -344,7 +364,7 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem wsdlDefinition.getImportedDefinitions().addAll(resolved.getImportedDefinitions()); wsdlDefinition.getXmlSchemas().addAll(resolved.getXmlSchemas()); wsdlDefinition.setUnresolved(false); - model.setDefinition(wsdlDefinition); + model.setUserSpecifiedWSDLDefinition(wsdlDefinition); if (model.getBindingName() != null) { WSDLObject<Binding> binding = wsdlDefinition.getWSDLObject(Binding.class, model.getBindingName()); if (binding != null) { @@ -396,11 +416,54 @@ public class WebServiceBindingProcessor extends BaseStAXArtifactProcessor implem interfaceContract.setInterface(wsdlInterface); model.setBindingInterfaceContract(interfaceContract); } + + validateWSDL(context, model); + } else { + if (model.getBindingName() != null){ + error(monitor, "WsdlBindingDoesNotMatch", model, model.getBindingName()); + } + + if (model.getServiceName() != null){ + error(monitor, "WsdlServiceDoesNotMatch", model, model.getServiceName()); + } } policyProcessor.resolvePolicies(model, resolver, context); } + private void validateWSDL(ProcessorContext context, WebServiceBinding model) { + WSDLDefinition wsdlDefinition = model.getUserSpecifiedWSDLDefinition(); + + Port port = model.getPort(); + + if (port != null){ + validateWSDLPort(context, model, port); + } + + Binding binding = model.getBinding(); + + if (binding != null){ + validateWSDLBinding(context, model, binding); + } + } + + private void validateWSDLPort(ProcessorContext context, WebServiceBinding model, Port port){ + + validateWSDLBinding(context, model, port.getBinding()); + + } + + private void validateWSDLBinding(ProcessorContext context, WebServiceBinding model, Binding binding){ + // BWS20005 & BWS20010 + // Check that the WSDL binding is of a supported type + if (!model.isHTTPTransport() && !model.isJMSTransport()){ + error(context.getMonitor(), + "InvalidWSDLBindingTransport", + model, + model.getBindingTransport()); + } + } + private PortType getPortType(WebServiceBinding model) { PortType portType = null; if (model.getPort() != null) { |