Author: richard.opalka(a)jboss.com
Date: 2010-05-12 10:26:09 -0400 (Wed, 12 May 2010)
New Revision: 12216
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/policy/
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/policy/AddressingPolicyAssertionDeployer.java
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/FeatureSet.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java
Log:
[JBWS-3022] implementing @AddressingFeature policy deployer
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java 2010-05-12
13:37:05 UTC (rev 12215)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/client/ClientFeatureProcessor.java 2010-05-12
14:26:09 UTC (rev 12216)
@@ -101,15 +101,42 @@
@SuppressWarnings("unchecked")
private static <T> void processAddressingFeature(WebServiceFeature feature,
EndpointMetaData epMetaData, T stub)
{
- if (feature instanceof AddressingFeature && feature.isEnabled())
+ if (feature instanceof AddressingFeature)
{
- BindingExt bindingExt = (BindingExt)((BindingProvider)stub).getBinding();
+ BindingExt bindingExt = (BindingExt) ((BindingProvider) stub).getBinding();
List<Handler> handlers = bindingExt.getHandlerChain(HandlerType.POST);
- handlers.add(new WSAddressingClientHandler());
- bindingExt.setHandlerChain(handlers, HandlerType.POST);
+ int addressingHandlerIndex = getAddressingHandlerIndex(handlers);
+
+ if (feature.isEnabled())
+ {
+ if (addressingHandlerIndex == -1)
+ {
+ handlers.add(new WSAddressingClientHandler());
+ bindingExt.setHandlerChain(handlers, HandlerType.POST);
+ }
+ }
+ else if (addressingHandlerIndex != -1)
+ {
+ handlers.remove(addressingHandlerIndex);
+ bindingExt.setHandlerChain(handlers, HandlerType.POST);
+ }
}
}
+ private static int getAddressingHandlerIndex(final List<Handler> handlers)
+ {
+ if (handlers != null)
+ {
+ for (int i = 0; i < handlers.size(); i++)
+ {
+ if (handlers.get(i) instanceof WSAddressingClientHandler)
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
/**
* Setup http chunked encoding
*
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java 2010-05-12
13:37:05 UTC (rev 12215)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java 2010-05-12
14:26:09 UTC (rev 12216)
@@ -23,8 +23,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@@ -201,78 +199,6 @@
}
}
- /**
- * The getPort method returns a stub. A service client uses this stub to invoke
operations on the target service endpoint.
- * The serviceEndpointInterface specifies the service endpoint interface that is
supported by the created dynamic proxy or stub instance.
- */
- @Override
- public <T> T getPort(QName portName, Class<T> seiClass)
- {
- assertSEIConstraints(seiClass);
-
- if (serviceMetaData == null)
- throw new WebServiceException("Service meta data not available");
-
- // com/sun/ts/tests/jaxws/api/javax_xml_ws/Service#GetPort1NegTest1WithWsdl
- EndpointMetaData epMetaData = serviceMetaData.getEndpoint(portName);
- if (epMetaData == null && serviceMetaData.getEndpoints().size() > 0)
- throw new WebServiceException("Cannot get port meta data for: " +
portName);
-
- // This is the case when the service could not be created from wsdl
- if (serviceMetaData.getEndpoints().size() == 0)
- {
- log.warn("Cannot get port meta data for: " + portName);
-
- QName portType = getPortTypeName(seiClass);
- epMetaData = new ClientEndpointMetaData(serviceMetaData, portName, portType,
Type.JAXWS);
- }
-
- String seiClassName = seiClass.getName();
- epMetaData.setServiceEndpointInterfaceName(seiClassName);
-
- return getPortInternal(epMetaData, seiClass);
- }
-
- /**
- * The getPort method returns a stub. A service client uses this stub to invoke
operations on the target service endpoint.
- * The serviceEndpointInterface specifies the service endpoint interface that is
supported by the created dynamic proxy or stub instance.
- */
- @Override
- public <T> T getPort(Class<T> seiClass)
- {
- assertSEIConstraints(seiClass);
-
- if (serviceMetaData == null)
- throw new WebServiceException("Service meta data not available");
-
- String seiClassName = seiClass.getName();
- EndpointMetaData epMetaData =
serviceMetaData.getEndpointByServiceEndpointInterface(seiClassName);
-
- if (epMetaData == null && serviceMetaData.getEndpoints().size() == 1)
- {
- epMetaData = serviceMetaData.getEndpoints().get(0);
- epMetaData.setServiceEndpointInterfaceName(seiClassName);
- }
- else
- {
- QName portTypeName = getPortTypeName(seiClass);
- for (EndpointMetaData epmd : serviceMetaData.getEndpoints())
- {
- if (portTypeName.equals(epmd.getPortTypeName()))
- {
- epmd.setServiceEndpointInterfaceName(seiClass.getName());
- epMetaData = epmd;
- break;
- }
- }
- }
-
- if (epMetaData == null)
- throw new WebServiceException("Cannot get port meta data for: " +
seiClassName);
-
- return getPortInternal(epMetaData, seiClass);
- }
-
private <T> QName getPortTypeName(Class<T> seiClass)
{
if (!seiClass.isAnnotationPresent(WebService.class))
@@ -309,7 +235,9 @@
}
}
- return (T)createProxy(seiClass, epMetaData);
+ T port = (T)createProxy(seiClass, epMetaData);
+ initWebserviceFeatures(port, epMetaData.getFeatures().getFeatures());
+ return port;
}
private void assertSEIConstraints(Class seiClass)
@@ -573,6 +501,78 @@
return port;
}
+ /**
+ * The getPort method returns a stub. A service client uses this stub to invoke
operations on the target service endpoint.
+ * The serviceEndpointInterface specifies the service endpoint interface that is
supported by the created dynamic proxy or stub instance.
+ */
+ @Override
+ public <T> T getPort(QName portName, Class<T> seiClass)
+ {
+ assertSEIConstraints(seiClass);
+
+ if (serviceMetaData == null)
+ throw new WebServiceException("Service meta data not available");
+
+ // com/sun/ts/tests/jaxws/api/javax_xml_ws/Service#GetPort1NegTest1WithWsdl
+ EndpointMetaData epMetaData = serviceMetaData.getEndpoint(portName);
+ if (epMetaData == null && serviceMetaData.getEndpoints().size() > 0)
+ throw new WebServiceException("Cannot get port meta data for: " +
portName);
+
+ // This is the case when the service could not be created from wsdl
+ if (serviceMetaData.getEndpoints().size() == 0)
+ {
+ log.warn("Cannot get port meta data for: " + portName);
+
+ QName portType = getPortTypeName(seiClass);
+ epMetaData = new ClientEndpointMetaData(serviceMetaData, portName, portType,
Type.JAXWS);
+ }
+
+ String seiClassName = seiClass.getName();
+ epMetaData.setServiceEndpointInterfaceName(seiClassName);
+
+ return getPortInternal(epMetaData, seiClass);
+ }
+
+ /**
+ * The getPort method returns a stub. A service client uses this stub to invoke
operations on the target service endpoint.
+ * The serviceEndpointInterface specifies the service endpoint interface that is
supported by the created dynamic proxy or stub instance.
+ */
+ @Override
+ public <T> T getPort(Class<T> seiClass)
+ {
+ assertSEIConstraints(seiClass);
+
+ if (serviceMetaData == null)
+ throw new WebServiceException("Service meta data not available");
+
+ String seiClassName = seiClass.getName();
+ EndpointMetaData epMetaData =
serviceMetaData.getEndpointByServiceEndpointInterface(seiClassName);
+
+ if (epMetaData == null && serviceMetaData.getEndpoints().size() == 1)
+ {
+ epMetaData = serviceMetaData.getEndpoints().get(0);
+ epMetaData.setServiceEndpointInterfaceName(seiClassName);
+ }
+ else
+ {
+ QName portTypeName = getPortTypeName(seiClass);
+ for (EndpointMetaData epmd : serviceMetaData.getEndpoints())
+ {
+ if (portTypeName.equals(epmd.getPortTypeName()))
+ {
+ epmd.setServiceEndpointInterfaceName(seiClass.getName());
+ epMetaData = epmd;
+ break;
+ }
+ }
+ }
+
+ if (epMetaData == null)
+ throw new WebServiceException("Cannot get port meta data for: " +
seiClassName);
+
+ return getPortInternal(epMetaData, seiClass);
+ }
+
private <T> void initWebserviceFeatures(T stub, WebServiceFeature... features)
{
if (features != null)
Added:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/policy/AddressingPolicyAssertionDeployer.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/policy/AddressingPolicyAssertionDeployer.java
(rev 0)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/policy/AddressingPolicyAssertionDeployer.java 2010-05-12
14:26:09 UTC (rev 12216)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.addressing.policy;
+
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.soap.AddressingFeature;
+import javax.xml.ws.soap.AddressingFeature.Responses;
+
+import org.apache.ws.policy.PrimitiveAssertion;
+import org.jboss.ws.extensions.policy.deployer.domainAssertion.AssertionDeployer;
+import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAssertion;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
+import org.jboss.wsf.common.addressing.AddressingConstants;
+
+/**
+ * Associates AddressingFeature with endpoint meta data if not set yet.
+ *
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
+public class AddressingPolicyAssertionDeployer implements AssertionDeployer
+{
+
+ @Override
+ public void deployClientSide(final PrimitiveAssertion assertion, final
ExtensibleMetaData extensibleMD)
+ throws UnsupportedAssertion
+ {
+ this.deploy(assertion, extensibleMD);
+ }
+
+ @Override
+ public void deployServerSide(final PrimitiveAssertion assertion, final
ExtensibleMetaData extensibleMD)
+ throws UnsupportedAssertion
+ {
+ this.deploy(assertion, extensibleMD);
+ }
+
+ private static void deploy(final PrimitiveAssertion assertion, final
ExtensibleMetaData extensibleMD)
+ throws UnsupportedAssertion
+ {
+ if (extensibleMD instanceof EndpointMetaData)
+ {
+ final EndpointMetaData endpointMD = (EndpointMetaData) extensibleMD;
+ final AddressingFeature addressingFeature =
endpointMD.getFeature(AddressingFeature.class);
+
+ if (addressingFeature == null)
+ {
+ final boolean enabled = true;
+ final boolean required = !assertion.isOptional();
+ final Responses responses = getResponses(assertion);
+
+ endpointMD.addFeature(new AddressingFeature(enabled, required, responses));
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Responses getResponses(final PrimitiveAssertion assertion)
+ {
+ final QName assertionQName = assertion.getName();
+
+ if
(AddressingConstants.Metadata.Elements.ANONYMOUSRESPONSES_QNAME.equals(assertionQName))
+ {
+ return AddressingFeature.Responses.ANONYMOUS;
+ }
+ if
(AddressingConstants.Metadata.Elements.NONANONYMOUSRESPONSES_QNAME.equals(assertionQName))
+ {
+ return AddressingFeature.Responses.NON_ANONYMOUS;
+ }
+
+ List terms = assertion.getTerms();
+ if (terms != null)
+ {
+ for (final Object term : terms)
+ {
+ if (term instanceof PrimitiveAssertion)
+ {
+ return getResponses((PrimitiveAssertion) term);
+ }
+ }
+ }
+
+ return AddressingFeature.Responses.ALL;
+ }
+
+}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java 2010-05-12
13:37:05 UTC (rev 12215)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java 2010-05-12
14:26:09 UTC (rev 12216)
@@ -33,6 +33,7 @@
import org.apache.ws.policy.XorCompositeAssertion;
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
+import org.jboss.ws.extensions.addressing.policy.AddressingPolicyAssertionDeployer;
import org.jboss.ws.extensions.policy.deployer.domainAssertion.AssertionDeployer;
import org.jboss.ws.extensions.policy.deployer.domainAssertion.NopAssertionDeployer;
import
org.jboss.ws.extensions.policy.deployer.domainAssertion.WSSecurityAssertionDeployer;
@@ -42,6 +43,7 @@
import org.jboss.ws.extensions.wsrm.policy.RM10PolicyAssertionDeployer;
import org.jboss.ws.extensions.wsrm.policy.RM11PolicyAssertionDeployer;
import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
+import org.jboss.wsf.common.addressing.AddressingConstants;
/**
* @author Stefano Maestri <mailto:stefano.maestri@javalinux.it>
@@ -60,6 +62,7 @@
me.domainDeployerMap.put("http://www.jboss.com/ws-security/schema/jb...;,
WSSecurityAssertionDeployer.class);
me.domainDeployerMap.put("http://docs.oasis-open.org/ws-rx/wsrmp/200...;,
RM11PolicyAssertionDeployer.class);
me.domainDeployerMap.put("http://schemas.xmlsoap.org/ws/2005/02/rm/p...;,
RM10PolicyAssertionDeployer.class);
+ me.domainDeployerMap.put(AddressingConstants.Metadata.NS,
AddressingPolicyAssertionDeployer.class);
me.domainDeployerMap.put("http://www.w3.org/2006/05/addressing/wsdl&...;,
NopAssertionDeployer.class);
}
@@ -90,6 +93,7 @@
instance.domainDeployerMap.put("http://docs.oasis-open.org/ws-rx/wsr...;,
NopAssertionDeployer.class);
instance.domainDeployerMap.put("http://schemas.xmlsoap.org/ws/2005/0...;,
NopAssertionDeployer.class);
instance.domainDeployerMap.put("http://www.w3.org/2006/05/addressing...;,
NopAssertionDeployer.class);
+ instance.domainDeployerMap.put(AddressingConstants.Metadata.NS,
NopAssertionDeployer.class);
return instance;
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/FeatureSet.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/FeatureSet.java 2010-05-12
13:37:05 UTC (rev 12215)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/metadata/umdm/FeatureSet.java 2010-05-12
14:26:09 UTC (rev 12216)
@@ -62,5 +62,18 @@
{
this.features.add(feature);
}
+
+ public WebServiceFeature[] getFeatures()
+ {
+ final WebServiceFeature[] retVal = new WebServiceFeature[this.features.size()];
+
+ int i = 0;
+ for (final WebServiceFeature feature : this.features)
+ {
+ retVal[i++] = feature;
+ }
+
+ return retVal;
+ }
}
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java 2010-05-12
13:37:05 UTC (rev 12215)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Reader.java 2010-05-12
14:26:09 UTC (rev 12216)
@@ -341,7 +341,11 @@
{
boolean result = false;
Element srcElement = extElement.getElement();
- if (Constants.URI_WS_POLICY.equals(srcElement.getNamespaceURI()))
+ final boolean is200409PolicyNamespace =
Constants.URI_WS_POLICY.equals(srcElement.getNamespaceURI());
+ final boolean is200702PolicyNamespace =
WSDLGenerator.WSP_NS.equals(srcElement.getNamespaceURI());
+ final boolean isPolicyNamespace = is200702PolicyNamespace ||
is200409PolicyNamespace;
+
+ if (isPolicyNamespace)
{
//copy missing namespaces from the source element to our element
Element element = (Element)srcElement.cloneNode(true);
@@ -361,6 +365,7 @@
result = true;
}
}
+
return result;
}