You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ng...@apache.org on 2008/08/26 22:11:09 UTC
svn commit: r689197 - in /webservices/axis2/trunk/java/modules/metadata:
src/org/apache/axis2/jaxws/description/
src/org/apache/axis2/jaxws/description/impl/
src/org/apache/axis2/jaxws/description/validator/
src/org/apache/axis2/jaxws/server/config/ te...
Author: ngallardo
Date: Tue Aug 26 13:11:09 2008
New Revision: 689197
URL: http://svn.apache.org/viewvc?rev=689197&view=rev
Log:
Use the @RespectBinding annotation and the @Addressing in combination for additional configuration.
Modified:
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/validator/EndpointDescriptionValidator.java
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/server/config/RespectBindingConfigurator.java
webservices/axis2/trunk/java/modules/metadata/test-resources/wsdl/RespectBinding.wsdl
webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/feature/RespectBindingFeatureTests.java
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java?rev=689197&r1=689196&r2=689197&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/EndpointDescription.java Tue Aug 26 13:11:09 2008
@@ -30,6 +30,8 @@
import javax.xml.ws.handler.PortInfo;
import javax.xml.ws.soap.SOAPBinding;
+import java.util.List;
+
/**
* An EndpointDescription corresponds to a particular Service Implementation. It can correspond to
* either either a client to that impl or the actual service impl.
@@ -190,6 +192,23 @@
public void setRespectBinding(boolean respect);
/**
+ * Adds the QName to a list of binding types that are required to be
+ * supported by the endpoint as defined in the WSDL.
+ *
+ * @param name
+ * @return
+ */
+ public boolean addRequiredBinding(QName name);
+
+ /**
+ * Returns a list of all known bindings that should be supported based
+ * on the information in the WSDL.
+ *
+ * @return
+ */
+ public List getRequiredBindings();
+
+ /**
* Return the DescriptionBuilderComposite, if any, used to build this service description.
* @return
*/
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java?rev=689197&r1=689196&r2=689197&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java Tue Aug 26 13:11:09 2008
@@ -181,6 +181,7 @@
// ANNOTATION: @RespectBinding
private Boolean respectBinding = false;
+ private List requiredBindings;
private Integer portCompositeIndex = null;
@@ -1521,7 +1522,21 @@
public void setRespectBinding(boolean r) {
respectBinding = r;
}
-
+
+
+ public boolean addRequiredBinding(QName name) {
+ if (requiredBindings == null)
+ requiredBindings = new ArrayList();
+
+ return requiredBindings.add(name);
+ }
+
+ public List getRequiredBindings() {
+ if (requiredBindings == null)
+ requiredBindings = new ArrayList();
+ return requiredBindings;
+ }
+
/*
* (non-Javadoc)
* @see org.apache.axis2.jaxws.description.EndpointDescription#getMTOMThreshold()
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/validator/EndpointDescriptionValidator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/validator/EndpointDescriptionValidator.java?rev=689197&r1=689196&r2=689197&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/validator/EndpointDescriptionValidator.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/validator/EndpointDescriptionValidator.java Tue Aug 26 13:11:09 2008
@@ -29,8 +29,16 @@
import javax.wsdl.Port;
import javax.wsdl.Service;
+import javax.xml.namespace.QName;
+import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.http.HTTPBinding;
+import javax.xml.ws.soap.AddressingFeature;
import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.spi.WebServiceFeatureAnnotation;
+
+import java.lang.annotation.Annotation;
+import java.util.Iterator;
+import java.util.List;
/**
*
@@ -211,10 +219,43 @@
addValidationFailure(this, "Annotation @RespectBinding requires that a WSDL file be specified.");
return Validator.INVALID;
}
+
+ // We will validate the configured bindings based on their mapping
+ // to a known WebServiceFeature element. If there is not a WebServiceFeature
+ // annotation for a given binding, a validation error will be returned.
+ List required = endpointDesc.getRequiredBindings();
+ if (required.size() > 0) {
+ Iterator i = required.iterator();
+ while (i.hasNext()) {
+ QName name = (QName) i.next();
+ String featureName = getFeatureForBinding(name);
+ if (featureName != null && featureName.length() > 0) {
+ EndpointDescriptionJava edj = (EndpointDescriptionJava) endpointDesc;
+ Annotation anno = edj.getAnnoFeature(featureName);
+ WebServiceFeatureAnnotation feature = getFeatureFromAnnotation(anno);
+
+ if (feature == null) {
+ addValidationFailure(this, "Annotation @RespectBinding was enabled, but the " +
+ "corresponding feature " + featureName + " was not enabled.");
+ return Validator.INVALID;
+ }
+ }
+ else {
+ addValidationFailure(this, "Annotation @RespectBinding was enabled, but extensibility element " +
+ name + " was not recognized.");
+ return Validator.INVALID;
+ }
+ }
+
+ }
}
return Validator.VALID;
}
+ private WebServiceFeatureAnnotation getFeatureFromAnnotation(Annotation a) {
+ return a.annotationType().getAnnotation(WebServiceFeatureAnnotation.class);
+ }
+
private static String bindingHumanReadableDescription(String ns) {
if (SOAPBinding.SOAP11HTTP_BINDING.equals(ns)) {
return "SOAP 1.1 HTTP Binding";
@@ -238,4 +279,13 @@
return "Unknown Binding";
}
}
+
+ private static String getFeatureForBinding(QName name) {
+ if (name.equals(new QName("http://www.w3.org/2006/05/addressing/wsdl", "UsingAddressing"))) {
+ return AddressingFeature.ID;
+ }
+ else {
+ return null;
+ }
+ }
}
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/server/config/RespectBindingConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/server/config/RespectBindingConfigurator.java?rev=689197&r1=689196&r2=689197&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/server/config/RespectBindingConfigurator.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/server/config/RespectBindingConfigurator.java Tue Aug 26 13:11:09 2008
@@ -21,13 +21,23 @@
import org.apache.axis2.jaxws.description.EndpointDescription;
import org.apache.axis2.jaxws.description.EndpointDescriptionJava;
+import org.apache.axis2.jaxws.description.EndpointDescriptionWSDL;
import org.apache.axis2.jaxws.feature.ServerConfigurator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.wsdl.Binding;
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap12.SOAP12Binding;
import javax.xml.ws.RespectBinding;
import javax.xml.ws.RespectBindingFeature;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
/**
* An implementation of the <code>ServerConfigurator</code> interface that will
* configure the endpoint based on the presence of a <code>RespectBinding</code>
@@ -50,6 +60,65 @@
log.debug("Setting respectBinding to " + annotation.enabled());
}
endpointDescription.setRespectBinding(annotation.enabled());
+
+ // Once we know that @RespectBinding is enabled, we have to find
+ // any binding extensibility elements available and see which ones
+ // have the "required" flag set to true.
+ EndpointDescriptionWSDL edw = (EndpointDescriptionWSDL) endpointDescription;
+ Binding bnd = edw.getWSDLBinding();
+ if (bnd != null) {
+ List l = bnd.getExtensibilityElements();
+ if (l == null || l.size() == 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("No extensibility elements found.");
+ }
+ }
+ else {
+ if (log.isDebugEnabled()) {
+ log.debug("Checking list of " + l.size() + " extensibility elements for required bindings.");
+ }
+
+ Iterator i = l.iterator();
+ List unusedElements = new ArrayList();
+ while (i.hasNext()) {
+ ExtensibilityElement e = (ExtensibilityElement) i.next();
+ if (e instanceof SOAPBinding || e instanceof SOAP12Binding)
+ continue;
+
+ if (e instanceof UnknownExtensibilityElement) {
+ UnknownExtensibilityElement ue = (UnknownExtensibilityElement) e;
+ String reqd = ue.getElement().getAttribute("required");
+ if (reqd.equals("true") || reqd.equals("TRUE")) {
+ if (log.isDebugEnabled()) {
+ log.debug("Found a required element: " + e.getElementType());
+ }
+ endpointDescription.addRequiredBinding(e.getElementType());
+ }
+ else {
+ unusedElements.add(e.getElementType());
+ }
+ }
+ else {
+ if (e.getRequired() != null && e.getRequired()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Found a required element: " + e.getElementType());
+ }
+ endpointDescription.addRequiredBinding(e.getElementType());
+ }
+ else {
+ unusedElements.add(e.getElementType());
+ }
+ }
+
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("The following extensibility elements were found, but were not required.");
+ for (int n = 0; n < unusedElements.size(); ++n)
+ log.debug("[" + i + "] - " + unusedElements.get(n));
+ }
+ }
+ }
}
else {
if (log.isDebugEnabled()) {
@@ -57,7 +126,7 @@
}
}
}
-
+
/*
* (non-Javadoc)
* @see org.apache.axis2.jaxws.feature.ServerConfigurator#supports(java.lang.String)
Modified: webservices/axis2/trunk/java/modules/metadata/test-resources/wsdl/RespectBinding.wsdl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/test-resources/wsdl/RespectBinding.wsdl?rev=689197&r1=689196&r2=689197&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/test-resources/wsdl/RespectBinding.wsdl (original)
+++ webservices/axis2/trunk/java/modules/metadata/test-resources/wsdl/RespectBinding.wsdl Tue Aug 26 13:11:09 2008
@@ -21,6 +21,7 @@
xmlns:tns="http://jaxws.axis2.apache.org/metadata/feature/respectbinding"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
targetNamespace="http://jaxws.axis2.apache.org/metadata/feature/respectbinding">
<types>
<xsd:schema targetNamespace="http://jaxws.axis2.apache.org/metadata/feature/respectbinding"
@@ -68,7 +69,9 @@
<output>
<soap:body use="literal" />
</output>
- </operation>
+ </operation>
+
+ <wsaw:UsingAddressing required="true" />
</binding>
<service name="EchoMessageService">
@@ -78,6 +81,9 @@
<port binding="tns:EchoMessageBinding" name="DisabledServicePort">
<soap:address location="http://localhost:8080/unknown"/>
</port>
+ <port binding="tns:EchoMessageBinding" name="CompleteServicePort">
+ <soap:address location="http://localhost:8080/unknown"/>
+ </port>
</service>
</definitions>
Modified: webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/feature/RespectBindingFeatureTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/feature/RespectBindingFeatureTests.java?rev=689197&r1=689196&r2=689197&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/feature/RespectBindingFeatureTests.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/test/org/apache/axis2/jaxws/description/feature/RespectBindingFeatureTests.java Tue Aug 26 13:11:09 2008
@@ -30,11 +30,11 @@
import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.ws.RespectBinding;
+import javax.xml.ws.soap.Addressing;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
public class RespectBindingFeatureTests extends TestCase {
@@ -43,15 +43,15 @@
private static final String serviceName = "EchoMessageService";
private static final String portTypeName = "EchoMessagePortType";
-
private static final String plainServicePortName = "PlainServicePort";
private static final String disabledServicePortName = "DisabledServicePort";
private static final String defaultServicePortName = "DefaultServicePort";
+ private static final String completeServicePortName = "CompleteServicePort";
private static final String wsdlLocation = "test-resources/wsdl/RespectBinding.wsdl";
/*
- * RespectBinding should be disabled because a WSDL file was not included.
+ * RespectBinding processing should fail because a WSDL file was not included.
*/
public void testPlain() throws Exception {
@@ -111,10 +111,33 @@
composite.setwsdlURL(wsdlUrl);
composite.setWsdlDefinition(wrapper.getDefinition());
+ List<ServiceDescription> sdList = null;
+ try {
+ sdList = DescriptionFactory.createServiceDescriptionFromDBCMap(map);
+ }
+ catch (Exception e) {
+ // An exception is expected.
+ }
+
+ assertTrue("The ServiceDescriptions should not have been built.", sdList == null);
+ }
+
+ public void testRespectBindingComplete() throws Exception {
+ JavaClassToDBCConverter converter = new JavaClassToDBCConverter(CompleteService.class);
+ HashMap<String, DescriptionBuilderComposite> map = converter.produceDBC();
+
+ DescriptionBuilderComposite composite = map.get(CompleteService.class.getName());
+
+ URL wsdlUrl = new URL("file:./" + wsdlLocation);
+ WSDL4JWrapper wrapper = new WSDL4JWrapper(wsdlUrl, false, 0);
+
+ composite.setwsdlURL(wsdlUrl);
+ composite.setWsdlDefinition(wrapper.getDefinition());
+
List<ServiceDescription> sdList = DescriptionFactory.createServiceDescriptionFromDBCMap(map);
ServiceDescription sd = sdList.get(0);
- EndpointDescription ed = sd.getEndpointDescription(new QName(ns, defaultServicePortName));
+ EndpointDescription ed = sd.getEndpointDescription(new QName(ns, completeServicePortName));
assertTrue("The EndpointDescription should not be null.", ed != null);
boolean respect = ed.respectBinding();
@@ -152,6 +175,19 @@
return "";
}
}
+
+ @WebService(targetNamespace=ns,
+ serviceName=serviceName,
+ portName=completeServicePortName,
+ name=portTypeName,
+ wsdlLocation=wsdlLocation)
+ @RespectBinding
+ @Addressing
+ class CompleteService {
+ public String echo(String input) {
+ return "";
+ }
+ }
}