Author: thomas.diesler(a)jboss.com
Date: 2007-10-09 06:58:37 -0400 (Tue, 09 Oct 2007)
New Revision: 4701
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
Modified:
stack/native/trunk/ant-import/build-bin-dist.xml
stack/native/trunk/ant-import/build-thirdparty.xml
stack/native/trunk/ant-import/macros-deploy-native.xml
stack/native/trunk/build.xml
stack/native/trunk/src/main/java/javax/xml/ws/Binding21.java
stack/native/trunk/src/main/java/org/jboss/ws/core/ConfigProvider.java
stack/native/trunk/src/main/java/org/jboss/ws/core/StubExt.java
stack/native/trunk/src/main/java/org/jboss/ws/core/client/EndpointInfo.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
stack/native/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java
Log:
[JBWS-1817] WS-Security with JAX-WS Dispatch
Remove dependency on jbossws-jboss42
Modified: stack/native/trunk/ant-import/build-bin-dist.xml
===================================================================
--- stack/native/trunk/ant-import/build-bin-dist.xml 2007-10-09 10:03:27 UTC (rev 4700)
+++ stack/native/trunk/ant-import/build-bin-dist.xml 2007-10-09 10:58:37 UTC (rev 4701)
@@ -92,7 +92,6 @@
<include name="jbossws-framework.jar"/>
<include name="jbossws-framework-scripts.zip"/>
<include name="jbossws-spi.jar"/>
- <include name="jbossws-jboss42.jar"/>
<include name="jbossws-jboss40.jar"/>
</fileset>
<fileset dir="${core.dir}/output/lib">
Modified: stack/native/trunk/ant-import/build-thirdparty.xml
===================================================================
--- stack/native/trunk/ant-import/build-thirdparty.xml 2007-10-09 10:03:27 UTC (rev 4700)
+++ stack/native/trunk/ant-import/build-thirdparty.xml 2007-10-09 10:58:37 UTC (rev 4701)
@@ -56,9 +56,7 @@
<get
src="${jboss.repository}/jboss/jbossws-jboss40/${jbossws-jboss40}/lib/jbossws-jboss40.jar"
dest="${thirdparty.dir}/jbossws-jboss40.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/jbossws-jboss40/${jbossws-jboss40}/lib/jbossws-jboss40-resources.zip"
dest="${thirdparty.dir}/jbossws-jboss40-resources.zip"
usetimestamp="true" verbose="true"/>
<get
src="${jboss.repository}/jboss/jbossws-jboss40/${jbossws-jboss40}/lib/jbossws-jboss40-src.zip"
dest="${thirdparty.dir}/jbossws-jboss40-src.zip" usetimestamp="true"
verbose="true"/>
- <get
src="${jboss.repository}/jboss/jbossws-jboss42/${jbossws-jboss42}/lib/jbossws-jboss42.jar"
dest="${thirdparty.dir}/jbossws-jboss42.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/jboss/jbossws-jboss42/${jbossws-jboss42}/lib/jbossws-jboss42-resources.zip"
dest="${thirdparty.dir}/jbossws-jboss42-resources.zip"
usetimestamp="true" verbose="true"/>
- <get
src="${jboss.repository}/jboss/jbossws-jboss42/${jbossws-jboss42}/lib/jbossws-jboss42-src.zip"
dest="${thirdparty.dir}/jbossws-jboss42-src.zip" usetimestamp="true"
verbose="true"/>
<get src="${jboss.repository}/apache-ant/${apache-ant}/lib/ant.jar"
dest="${thirdparty.dir}/ant.jar" usetimestamp="true"
verbose="true"/>
<get
src="${jboss.repository}/apache-collections/${apache-collections}/lib/commons-collections.jar"
dest="${thirdparty.dir}/commons-collections.jar" usetimestamp="true"
verbose="true"/>
Modified: stack/native/trunk/ant-import/macros-deploy-native.xml
===================================================================
--- stack/native/trunk/ant-import/macros-deploy-native.xml 2007-10-09 10:03:27 UTC (rev
4700)
+++ stack/native/trunk/ant-import/macros-deploy-native.xml 2007-10-09 10:58:37 UTC (rev
4701)
@@ -141,7 +141,6 @@
<include name="jbossws-client.jar"/>
</fileset>
<fileset dir="@{thirdpartylibs}">
- <include name="jbossws-jboss42.jar"/>
<include name="jaxb-api.jar"/>
<include name="jaxb-impl.jar"/>
<include name="jaxb-xjc.jar"/>
@@ -161,12 +160,6 @@
<include name="jboss-xml-binding.jar"/>
</fileset>
</copy>
- <copy todir="${jboss42.home}/server/${jboss.server.instance}/lib"
overwrite="true">
- <fileset dir="@{thirdpartylibs}">
- <include name="jbossws-jboss42.jar"/>
- </fileset>
- </copy>
-
<mkdir
dir="${jboss42.home}/server/${jboss.server.instance}/deploy/jbossws.sar"/>
<unjar
dest="${jboss42.home}/server/${jboss.server.instance}/deploy/jbossws.sar"
src="(a){stacklibs}/jbossws-native42.sar"/>
<mkdir
dir="${jboss42.home}/server/${jboss.server.instance}/deploy/juddi-service.sar"/>
@@ -199,7 +192,6 @@
<include name="jboss-jaxws-ext.jar"/>
<include name="jboss-saaj.jar"/>
<include name="jbossws-client.jar"/>
- <include name="jbossws-jboss42.jar"/>
<include name="policy.jar"/>
<include name="stax-ex.jar"/>
<include name="streambuffer.jar"/>
@@ -217,7 +209,6 @@
<include name="jbossws-integration.jar"/>
</fileset>
<fileset
dir="${jboss42.home}/server/${jboss.server.instance}/lib">
- <include name="jbossws-jboss42.jar"/>
<include name="jboss-jaxrpc.jar"/>
<include name="jboss-jaxws.jar"/>
<include name="jboss-jaxws-ext.jar"/>
Modified: stack/native/trunk/build.xml
===================================================================
--- stack/native/trunk/build.xml 2007-10-09 10:03:27 UTC (rev 4700)
+++ stack/native/trunk/build.xml 2007-10-09 10:58:37 UTC (rev 4701)
@@ -331,7 +331,6 @@
<include name="jbossws-core.jar"/>
</fileset>
<fileset dir="${core.dir}/thirdparty">
- <include name="jbossws-jboss42.jar"/>
<include name="jaxb-api.jar"/>
<include name="jaxb-impl.jar"/>
<include name="policy.jar"/>
Modified: stack/native/trunk/src/main/java/javax/xml/ws/Binding21.java
===================================================================
--- stack/native/trunk/src/main/java/javax/xml/ws/Binding21.java 2007-10-09 10:03:27 UTC
(rev 4700)
+++ stack/native/trunk/src/main/java/javax/xml/ws/Binding21.java 2007-10-09 10:58:37 UTC
(rev 4701)
@@ -21,6 +21,8 @@
*/
package javax.xml.ws;
+// $Id$
+
/**
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/ConfigProvider.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/core/ConfigProvider.java 2007-10-09
10:03:27 UTC (rev 4700)
+++ stack/native/trunk/src/main/java/org/jboss/ws/core/ConfigProvider.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -50,4 +50,14 @@
* Set the port configuration name and file
*/
void setConfigName(String configName, String configFile);
+
+ /**
+ * Get the WS-Security configuration
+ */
+ String getSecurityConfig();
+
+ /**
+ * Set the WS-Security configuration
+ */
+ void setSecurityConfig(String securityConfig);
}
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/StubExt.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/core/StubExt.java 2007-10-09 10:03:27
UTC (rev 4700)
+++ stack/native/trunk/src/main/java/org/jboss/ws/core/StubExt.java 2007-10-09 10:58:37
UTC (rev 4701)
@@ -126,14 +126,4 @@
* Creates a new empty AttachmentPart object.
*/
AttachmentPart createAttachmentPart();
-
- /**
- * Get the WS-Security configuration
- */
- String getSecurityConfig();
-
- /**
- * Set the WS-Security configuration
- */
- void setSecurityConfig(String securityConfig);
}
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/client/EndpointInfo.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/core/client/EndpointInfo.java 2007-10-09
10:03:27 UTC (rev 4700)
+++ stack/native/trunk/src/main/java/org/jboss/ws/core/client/EndpointInfo.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -38,6 +38,7 @@
{
private String targetAddress;
private Map<String, Object> properties;
+
public EndpointInfo(EndpointMetaData epMetaData, String targetAddress, Map<String,
Object> callProps)
{
this.targetAddress = targetAddress;
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java 2007-10-09
10:03:27 UTC (rev 4700)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -21,15 +21,15 @@
*/
package org.jboss.ws.core.jaxws.binding;
+//$Id$
+
import java.util.List;
-import javax.xml.ws.Binding;
import javax.xml.ws.Binding21;
import javax.xml.ws.handler.Handler;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
-// $Id$
/**
* Extension to JAXWS protocol bindings.
@@ -39,7 +39,9 @@
*/
public interface BindingExt extends Binding21
{
+ /** Get the handler chain for a given type */
List<Handler> getHandlerChain(HandlerType handlerType);
-
+
+ /** Set the handler chain for a given type */
void setHandlerChain(List<Handler> handlerChain, HandlerType handlerType);
}
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java 2007-10-09
10:03:27 UTC (rev 4700)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -37,7 +37,6 @@
import javax.xml.ws.BindingProvider;
import javax.xml.ws.EndpointReference;
import javax.xml.ws.WebServiceException;
-import javax.xml.ws.wsaddressing.BindingProvider21;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.MessageContext;
@@ -47,6 +46,7 @@
import javax.xml.ws.http.HTTPException;
import javax.xml.ws.soap.SOAPBinding;
import javax.xml.ws.soap.SOAPFaultException;
+import javax.xml.ws.wsaddressing.BindingProvider21;
import org.jboss.logging.Logger;
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
@@ -59,11 +59,11 @@
import org.jboss.ws.core.jaxws.handler.HandlerChainExecutor;
import org.jboss.ws.core.jaxws.handler.HandlerResolverImpl;
import org.jboss.ws.core.jaxws.handler.MessageContextJAXWS;
-import org.jboss.ws.core.jaxws.handler.PortInfoImpl;
import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS;
import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.metadata.config.Configurable;
import org.jboss.ws.metadata.config.ConfigurationProvider;
+import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
@@ -79,22 +79,21 @@
// provide logging
private static Logger log = Logger.getLogger(ClientImpl.class);
- // the associated endpoint meta data
- private final EndpointMetaData epMetaData;
+ // the associated endpoint meta data
+ private final ClientEndpointMetaData epMetaData;
- // Keep a handle on the resolver so that updateConfig calls may revisit the associated
chains
- private final HandlerResolver handlerResolver;
-
- private Map<HandlerType, HandlerChainExecutor> executorMap = new
HashMap<HandlerType, HandlerChainExecutor>();
+ // Keep a handle on the resolver so that updateConfig calls may revisit the associated
chains
+ private final HandlerResolver handlerResolver;
- private static HandlerType[] HANDLER_TYPES = new HandlerType[] {HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST};
-
- public ClientImpl(EndpointMetaData epMetaData, HandlerResolver handlerResolver)
+ private Map<HandlerType, HandlerChainExecutor> executorMap = new
HashMap<HandlerType, HandlerChainExecutor>();
+ private static HandlerType[] HANDLER_TYPES = new HandlerType[] { HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST };
+
+ public ClientImpl(EndpointMetaData epMetaData, HandlerResolver handlerResolver)
{
super(epMetaData);
setTargetEndpointAddress(epMetaData.getEndpointAddress());
- this.epMetaData = epMetaData;
+ this.epMetaData = (ClientEndpointMetaData)epMetaData;
this.handlerResolver = handlerResolver;
initBindingHandlerChain(false);
@@ -112,31 +111,31 @@
{
BindingExt binding = (BindingExt)getBindingProvider().getBinding();
- PortInfo portInfo = getPortInfo(epMetaData);
+ PortInfo portInfo = epMetaData.getPortInfo();
- if (handlerResolver != null)
- {
+ if (handlerResolver != null)
+ {
- boolean jbossHandlerResolver = handlerResolver instanceof HandlerResolverImpl;
-
- if (jbossHandlerResolver) // knows about PRE and POST handlers
- {
- HandlerResolverImpl impl = (HandlerResolverImpl)handlerResolver;
- impl.initHandlerChain(epMetaData, HandlerType.PRE, clearExistingHandlers);
- impl.initHandlerChain(epMetaData, HandlerType.ENDPOINT, clearExistingHandlers);
- impl.initHandlerChain(epMetaData, HandlerType.POST, clearExistingHandlers);
+ boolean jbossHandlerResolver = handlerResolver instanceof HandlerResolverImpl;
- List<Handler> preChain = impl.getHandlerChain(portInfo, HandlerType.PRE);
- List<Handler> postChain = impl.getHandlerChain(portInfo, HandlerType.POST);
-
- binding.setHandlerChain(postChain, HandlerType.POST);
- binding.setHandlerChain(preChain, HandlerType.PRE);
- }
+ if (jbossHandlerResolver) // knows about PRE and POST handlers
+ {
+ HandlerResolverImpl impl = (HandlerResolverImpl)handlerResolver;
+ impl.initHandlerChain(epMetaData, HandlerType.PRE, clearExistingHandlers);
+ impl.initHandlerChain(epMetaData, HandlerType.ENDPOINT,
clearExistingHandlers);
+ impl.initHandlerChain(epMetaData, HandlerType.POST, clearExistingHandlers);
- // The regular handler chain
- List<Handler> endpointChain = handlerResolver.getHandlerChain(portInfo);
- binding.setHandlerChain(endpointChain);
- }
+ List<Handler> preChain = impl.getHandlerChain(portInfo,
HandlerType.PRE);
+ List<Handler> postChain = impl.getHandlerChain(portInfo,
HandlerType.POST);
+
+ binding.setHandlerChain(postChain, HandlerType.POST);
+ binding.setHandlerChain(preChain, HandlerType.PRE);
+ }
+
+ // The regular handler chain
+ List<Handler> endpointChain = handlerResolver.getHandlerChain(portInfo);
+ binding.setHandlerChain(endpointChain);
+ }
}
/**
@@ -389,26 +388,26 @@
configProvider.setConfigName(configName, configFile);
}
- /**
- * Retrieve header names that can be processed by this binding
- * @return
- */
- public Set<QName> getHeaders()
+ /**
+ * Retrieve header names that can be processed by this binding
+ * @return
+ */
+ public Set<QName> getHeaders()
{
- Set<QName> headers = new HashSet<QName>();
+ Set<QName> headers = new HashSet<QName>();
- BindingExt binding = (BindingExt)getBinding();
+ BindingExt binding = (BindingExt)getBinding();
- for(HandlerType type : HANDLER_TYPES)
- {
- for(Handler bindingHandler : binding.getHandlerChain(type))
- {
- if(bindingHandler instanceof SOAPHandler)
- headers.addAll( ((SOAPHandler)bindingHandler).getHeaders());
- }
- }
-
- return headers;
+ for (HandlerType type : HANDLER_TYPES)
+ {
+ for (Handler bindingHandler : binding.getHandlerChain(type))
+ {
+ if (bindingHandler instanceof SOAPHandler)
+ headers.addAll(((SOAPHandler)bindingHandler).getHeaders());
+ }
+ }
+
+ return headers;
}
@Override
@@ -417,13 +416,4 @@
Object bool = getRequestContext().get(BindingProvider.SESSION_MAINTAIN_PROPERTY);
return Boolean.TRUE.equals(bool);
}
-
- private PortInfo getPortInfo(EndpointMetaData epMetaData)
- {
- QName serviceName = epMetaData.getServiceMetaData().getServiceName();
- QName portName = epMetaData.getPortName();
- String bindingID = epMetaData.getBindingId();
- PortInfo portInfo = new PortInfoImpl(serviceName, portName, bindingID);
- return portInfo;
- }
}
\ No newline at end of file
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java 2007-10-09
10:03:27 UTC (rev 4700)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -24,41 +24,61 @@
// $Id$
import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.xml.bind.JAXBContext;
+import javax.xml.namespace.QName;
import javax.xml.soap.MimeHeaders;
-import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPFault;
-import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Binding;
+import javax.xml.ws.Binding21;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
import javax.xml.ws.EndpointReference;
import javax.xml.ws.Response;
import javax.xml.ws.WebServiceException;
-import javax.xml.ws.Binding21;
import javax.xml.ws.Service.Mode;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.PortInfo;
import javax.xml.ws.http.HTTPBinding;
import javax.xml.ws.soap.SOAPFaultException;
-import javax.xml.namespace.QName;
import org.jboss.logging.Logger;
import org.jboss.util.NotImplementedException;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.ConfigProvider;
import org.jboss.ws.core.MessageAbstraction;
-import org.jboss.ws.core.ConfigProvider;
-import org.jboss.ws.core.soap.SOAPFaultImpl;
+import org.jboss.ws.core.client.EndpointInfo;
import org.jboss.ws.core.client.HTTPRemotingConnection;
import org.jboss.ws.core.client.RemotingConnection;
import org.jboss.ws.core.client.SOAPRemotingConnection;
+import org.jboss.ws.core.jaxws.binding.BindingExt;
import org.jboss.ws.core.jaxws.binding.BindingProviderImpl;
+import org.jboss.ws.core.jaxws.handler.HandlerChainExecutor;
+import org.jboss.ws.core.jaxws.handler.HandlerResolverImpl;
+import org.jboss.ws.core.jaxws.handler.MessageContextJAXWS;
+import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS;
+import org.jboss.ws.core.soap.MessageContextAssociation;
+import org.jboss.ws.core.soap.SOAPMessageImpl;
+import org.jboss.ws.metadata.config.ConfigurationProvider;
+import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.config.ConfigurationProvider;
+import org.jboss.ws.metadata.umdm.ServiceMetaData;
+import org.jboss.ws.metadata.wsse.WSSecurityConfigFactory;
+import org.jboss.ws.metadata.wsse.WSSecurityConfiguration;
+import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
+import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
/**
* The Dispatch interface provides support for the dynamic invocation of a service
endpoint operations.
@@ -67,22 +87,26 @@
* @author Thomas.Diesler(a)jboss.com
* @since 04-Jul-2006
*/
-public class DispatchImpl<T> implements Dispatch<T>
+public class DispatchImpl<T> implements Dispatch<T>, ConfigProvider
{
// provide logging
private final Logger log = Logger.getLogger(DispatchImpl.class);
private BindingProvider bindingProvider;
- private EndpointMetaData epMetaData;
+ private HandlerResolverImpl handlerResolver;
+ private ClientEndpointMetaData epMetaData;
private JAXBContext jaxbContext;
private ExecutorService executor;
+ private String securityConfig;
private Class type;
private Mode mode;
+ private Map<HandlerType, HandlerChainExecutor> executorMap = new
HashMap<HandlerType, HandlerChainExecutor>();
+
public DispatchImpl(ExecutorService executor, EndpointMetaData epMetaData,
Class<T> type, Mode mode)
{
this.bindingProvider = new BindingProviderImpl(epMetaData);
- this.epMetaData = epMetaData;
+ this.epMetaData = (ClientEndpointMetaData)epMetaData;
this.executor = executor;
this.type = type;
this.mode = mode;
@@ -92,7 +116,7 @@
public DispatchImpl(ExecutorService executor, EndpointMetaData epMetaData, JAXBContext
jbc, Mode mode)
{
this.bindingProvider = new BindingProviderImpl(epMetaData);
- this.epMetaData = epMetaData;
+ this.epMetaData = (ClientEndpointMetaData)epMetaData;
this.executor = executor;
this.type = Object.class;
this.jaxbContext = jbc;
@@ -114,11 +138,49 @@
return retObj;
}
- private Object invokeInternal(Object obj, Map<String, Object> resContext) throws
IOException
+ private Object invokeInternal(Object obj, Map<String, Object> resContext) throws
Exception
{
- MessageAbstraction reqMsg = getRequestMessage(obj);
+ Object retObj = null;
+
+ BindingExt binding = (BindingExt)bindingProvider.getBinding();
+
+ String bindingID = binding.getBindingID();
+ if (bindingID.indexOf("soap") > 0)
+ {
+ // Init the handler chain
+ if (handlerResolver == null)
+ {
+ handlerResolver = new HandlerResolverImpl();
+ handlerResolver.initHandlerChain(epMetaData, HandlerType.PRE, true);
+ handlerResolver.initHandlerChain(epMetaData, HandlerType.ENDPOINT, true);
+ handlerResolver.initHandlerChain(epMetaData, HandlerType.POST, true);
+
+ PortInfo portInfo = epMetaData.getPortInfo();
+ List<Handler> preChain = handlerResolver.getHandlerChain(portInfo,
HandlerType.PRE);
+ List<Handler> epChain = handlerResolver.getHandlerChain(portInfo,
HandlerType.ENDPOINT);
+ List<Handler> postChain = handlerResolver.getHandlerChain(portInfo,
HandlerType.POST);
+
+ binding.setHandlerChain(preChain, HandlerType.PRE);
+ binding.setHandlerChain(epChain, HandlerType.ENDPOINT);
+ binding.setHandlerChain(postChain, HandlerType.POST);
+ }
+
+ retObj = invokeInternalSOAP(obj);
+ }
+ else
+ {
+ retObj = invokeInternalNonSOAP(obj);
+ }
+ return retObj;
+ }
+
+ private Object invokeInternalSOAP(Object obj) throws Exception
+ {
+ Object retObj = null;
+
+ SOAPMessageImpl reqMsg = (SOAPMessageImpl)getRequestMessage(obj);
String targetAddress = epMetaData.getEndpointAddress();
-
+
// R2744 A HTTP request MESSAGE MUST contain a SOAPAction HTTP header field
// with a quoted value equal to the value of the soapAction attribute of
// soapbind:operation, if present in the corresponding WSDL description.
@@ -127,22 +189,92 @@
// with a quoted empty string value, if in the corresponding WSDL description,
// the soapAction attribute of soapbind:operation is either not present, or
// present with an empty string as its value.
- String bindingID = ((Binding21)bindingProvider.getBinding()).getBindingID();
- if (bindingID.indexOf("soap") > 0)
+ String soapAction = null;
+ Map<String, Object> reqContext = getRequestContext();
+ Boolean useSOAPAction =
(Boolean)reqContext.get(BindingProvider.SOAPACTION_USE_PROPERTY);
+ if (Boolean.TRUE.equals(useSOAPAction))
{
- String soapAction = null;
- Map<String, Object> reqContext = getRequestContext();
- Boolean useSOAPAction =
(Boolean)reqContext.get(BindingProvider.SOAPACTION_USE_PROPERTY);
- if (Boolean.TRUE.equals(useSOAPAction))
+ soapAction = (String)reqContext.get(BindingProvider.SOAPACTION_URI_PROPERTY);
+ if (soapAction == null)
+ throw new IllegalStateException("Cannot obtain: " +
BindingProvider.SOAPACTION_URI_PROPERTY);
+ }
+ MimeHeaders mimeHeaders = reqMsg.getMimeHeaders();
+ mimeHeaders.addHeader("SOAPAction", soapAction != null ? soapAction :
"");
+
+ // Get the order of pre/post handlerchains
+ HandlerType[] handlerType = new HandlerType[] { HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST };
+ HandlerType[] faultType = new HandlerType[] { HandlerType.PRE,
HandlerType.ENDPOINT, HandlerType.POST };
+
+ // Associate a message context with the current thread
+ CommonMessageContext msgContext = new SOAPMessageContextJAXWS();
+ MessageContextAssociation.pushMessageContext(msgContext);
+ msgContext.setEndpointMetaData(epMetaData);
+ msgContext.setSOAPMessage(reqMsg);
+ msgContext.putAll(reqContext);
+
+ // The contents of the request context are used to initialize the message context
(see section 9.4.1)
+ // prior to invoking any handlers (see chapter 9) for the outbound message. Each
property within the
+ // request context is copied to the message context with a scope of HANDLER.
+ msgContext.put(MessageContextJAXWS.MESSAGE_OUTBOUND_PROPERTY, Boolean.TRUE);
+
+ QName portName = epMetaData.getPortName();
+ try
+ {
+ // Call the request handlers
+ boolean handlerPass = callRequestHandlerChain(portName, handlerType[0]);
+ handlerPass = handlerPass && callRequestHandlerChain(portName,
handlerType[1]);
+ handlerPass = handlerPass && callRequestHandlerChain(portName,
handlerType[2]);
+
+ // Handlers might have replaced the message
+ reqMsg = (SOAPMessageImpl)msgContext.getSOAPMessage();
+
+ MessageAbstraction resMsg = null;
+ if (handlerPass)
{
- soapAction =
(String)reqContext.get(BindingProvider.SOAPACTION_URI_PROPERTY);
- if (soapAction == null)
- throw new IllegalStateException("Cannot obtain: " +
BindingProvider.SOAPACTION_URI_PROPERTY);
+ Map<String, Object> callProps = new HashMap<String,
Object>(getRequestContext());
+ EndpointInfo epInfo = new EndpointInfo(epMetaData, targetAddress,
callProps);
+ resMsg = getRemotingConnection().invoke(reqMsg, epInfo, false);
+
+ // Call the response handler chain, removing the fault type entry will not
call handleFault for that chain
+ handlerPass = callResponseHandlerChain(portName, handlerType[2]);
+ faultType[2] = null;
+ handlerPass = handlerPass && callResponseHandlerChain(portName,
handlerType[1]);
+ faultType[1] = null;
+ handlerPass = handlerPass && callResponseHandlerChain(portName,
handlerType[0]);
+ faultType[0] = null;
}
- MimeHeaders mimeHeaders = reqMsg.getMimeHeaders();
- mimeHeaders.addHeader("SOAPAction", soapAction != null ? soapAction :
"");
+
+ if (handlerPass)
+ {
+ retObj = getReturnObject(resMsg);
+ }
}
-
+ catch (Exception ex)
+ {
+ if (faultType[2] != null)
+ callFaultHandlerChain(portName, faultType[2], ex);
+ if (faultType[1] != null)
+ callFaultHandlerChain(portName, faultType[1], ex);
+ if (faultType[0] != null)
+ callFaultHandlerChain(portName, faultType[0], ex);
+
+ throw ex;
+ }
+ finally
+ {
+ closeHandlerChain(portName, handlerType[2]);
+ closeHandlerChain(portName, handlerType[1]);
+ closeHandlerChain(portName, handlerType[0]);
+
+ MessageContextAssociation.popMessageContext();
+ }
+ return retObj;
+ }
+
+ private Object invokeInternalNonSOAP(Object obj) throws IOException
+ {
+ MessageAbstraction reqMsg = getRequestMessage(obj);
+ String targetAddress = epMetaData.getEndpointAddress();
MessageAbstraction resMsg = getRemotingConnection().invoke(reqMsg, targetAddress,
false);
Object retObj = getReturnObject(resMsg);
return retObj;
@@ -261,7 +393,7 @@
{
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault fault = factory.createFault("Request object cannot be
null", new QName("http://org.jboss.ws", "Dispatch"));
- fault.setFaultActor("client");
+ fault.setFaultActor("client");
throw new SOAPFaultException(fault);
}
catch (SOAPException e)
@@ -322,7 +454,7 @@
throw new IllegalArgumentException("Async response cannot be
null");
if (payload == null)
throw new IllegalArgumentException("Async payload cannot be
null");
-
+
this.response = response;
this.handler = handler;
this.payload = payload;
@@ -379,4 +511,85 @@
{
throw new NotImplementedException();
}
+
+ public String getConfigFile()
+ {
+ return epMetaData.getConfigFile();
+ }
+
+ public String getConfigName()
+ {
+ return epMetaData.getConfigName();
+ }
+
+ public void setConfigName(String configName)
+ {
+ epMetaData.setConfigName(configName);
+ }
+
+ public void setConfigName(String configName, String configFile)
+ {
+ epMetaData.setConfigName(configName, configFile);
+ }
+
+ public String getSecurityConfig()
+ {
+ return securityConfig;
+ }
+
+ public void setSecurityConfig(String securityConfig)
+ {
+ this.securityConfig = securityConfig;
+
+ if (securityConfig != null)
+ {
+ ServiceMetaData serviceMetaData = epMetaData.getServiceMetaData();
+ if (serviceMetaData.getSecurityConfiguration() == null)
+ {
+ try
+ {
+ WSSecurityConfigFactory wsseConfFactory =
WSSecurityConfigFactory.newInstance();
+ UnifiedVirtualFile vfsRoot =
serviceMetaData.getUnifiedMetaData().getRootFile();
+ WSSecurityConfiguration config =
wsseConfFactory.createConfiguration(vfsRoot, securityConfig);
+ serviceMetaData.setSecurityConfiguration(config);
+ }
+ catch (IOException ex)
+ {
+ WSException.rethrow("Cannot set security config", ex);
+ }
+ }
+ }
+ }
+
+ private boolean callRequestHandlerChain(QName portName, HandlerType type)
+ {
+ BindingExt binding = (BindingExt)bindingProvider.getBinding();
+ HandlerChainExecutor executor = new HandlerChainExecutor(epMetaData,
binding.getHandlerChain(type));
+ executorMap.put(type, executor);
+
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ return executor.handleMessage(msgContext);
+ }
+
+ private boolean callResponseHandlerChain(QName portName, HandlerType type)
+ {
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ HandlerChainExecutor executor = executorMap.get(type);
+ return (executor != null ? executor.handleMessage(msgContext) : true);
+ }
+
+ private boolean callFaultHandlerChain(QName portName, HandlerType type, Exception ex)
+ {
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ HandlerChainExecutor executor = executorMap.get(type);
+ return (executor != null ? executor.handleFault(msgContext, ex) : true);
+ }
+
+ private void closeHandlerChain(QName portName, HandlerType type)
+ {
+ MessageContext msgContext =
(MessageContext)MessageContextAssociation.peekMessageContext();
+ HandlerChainExecutor executor = executorMap.get(type);
+ if (executor != null)
+ executor.close(msgContext);
+ }
}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java 2007-10-09
10:03:27 UTC (rev 4700)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -83,13 +83,13 @@
return newList;
}
- private static Config getConfig(WSSecurityConfiguration config, String portName,
String operationName)
+ private static Config getConfig(WSSecurityConfiguration config, String portName,
String opName)
{
Port port = config.getPorts().get(portName);
if (port == null)
return config.getDefaultConfig();
- Operation operation = port.getOperations().get(operationName);
+ Operation operation = port.getOperations().get(opName);
if (operation == null)
{
Config portConfig = port.getDefaultConfig();
@@ -230,26 +230,29 @@
WSSecurityConfiguration config = getSecurityConfig(ctx);
SOAPMessageImpl soapMessage = (SOAPMessageImpl)ctx.getSOAPMessage();
+ EndpointMetaData epMetaData = ctx.getEndpointMetaData();
+ String port = epMetaData.getPortName().getLocalPart();
+
+ String opName = null;
OperationMetaData opMetaData = ctx.getOperationMetaData();
- String operation = opMetaData.getQName().toString();
- String port = opMetaData.getEndpointMetaData().getPortName().getLocalPart();
+ if (opMetaData != null)
+ opName = opMetaData.getQName().toString();
- Config operationConfig = getConfig(config, port, operation);
-
- log.debug("WS-Security config: " + operationConfig);
+ Config opConfig = getConfig(config, port, opName);
+ log.debug("WS-Security config: " + opConfig);
// Nothing to process
- if (operationConfig == null)
+ if (opConfig == null)
return;
ArrayList<OperationDescription<EncodingOperation>> operations = new
ArrayList<OperationDescription<EncodingOperation>>();
- Timestamp timestamp = operationConfig.getTimestamp();
+ Timestamp timestamp = opConfig.getTimestamp();
if (timestamp != null)
{
operations.add(new
OperationDescription<EncodingOperation>(TimestampOperation.class, null, null,
timestamp.getTtl(), null));
}
- if (operationConfig.getUsername() != null)
+ if (opConfig.getUsername() != null)
{
Object user = ctx.get(Stub.USERNAME_PROPERTY);
Object pass = ctx.get(Stub.PASSWORD_PROPERTY);
@@ -267,7 +270,7 @@
}
}
- Sign sign = operationConfig.getSign();
+ Sign sign = opConfig.getSign();
if (sign != null)
{
List<Target> targets = convertTargets(sign.getTargets());
@@ -283,7 +286,7 @@
operations.add(new
OperationDescription<EncodingOperation>(SignatureOperation.class, targets,
sign.getAlias(), null, null));
}
- Encrypt encrypt = operationConfig.getEncrypt();
+ Encrypt encrypt = opConfig.getEncrypt();
if (encrypt != null)
{
List<Target> targets = convertTargets(encrypt.getTargets());
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java 2007-10-09
10:03:27 UTC (rev 4700)
+++
stack/native/trunk/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -23,10 +23,12 @@
// $Id$
+import org.jboss.ws.core.jaxws.handler.PortInfoImpl;
import org.jboss.ws.metadata.config.ConfigurationProvider;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
import javax.xml.namespace.QName;
+import javax.xml.ws.handler.PortInfo;
/**
* Client side endpoint meta data.
@@ -60,6 +62,15 @@
this.endpointAddress = endpointAddress;
}
+ public PortInfo getPortInfo()
+ {
+ QName serviceName = getServiceMetaData().getServiceName();
+ QName portName = getPortName();
+ String bindingID = getBindingId();
+ PortInfo portInfo = new PortInfoImpl(serviceName, portName, bindingID);
+ return portInfo;
+ }
+
public String toString()
{
StringBuilder buffer = new StringBuilder("\nClientEndpointMetaData:");
Copied:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
(from rev 4700,
stack/native/branches/tdiesler/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java)
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java 2007-10-09
10:58:37 UTC (rev 4701)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.ws.jaxws.samples.wssecurity;
+
+import java.io.File;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+
+import junit.framework.Test;
+
+import org.jboss.ws.core.ConfigProvider;
+import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.common.DOMWriter;
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+import org.w3c.dom.Element;
+
+/**
+ * WS-Security with JAX-WS Dispatch
+ *
+ *
http://jira.jboss.org/jira/browse/JBWS-1817
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 02-Oct-2007
+ */
+public class SimpleDispatchTestCase extends JBossWSTest
+{
+ private static Dispatch dispatch;
+
+ public static Test suite() throws Exception
+ {
+ return new JBossWSTestSetup(SimpleDispatchTestCase.class,
"jaxws-samples-wssecurity-username.war");
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ if (dispatch == null)
+ {
+ URL wsdlURL = new
File("resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl").toURL();
+ URL securityURL = new
File("resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml").toURL();
+ QName serviceName = new
QName("http://org.jboss.ws/samples/wssecurity", "UsernameService");
+ QName portName = new QName("http://org.jboss.ws/samples/wssecurity",
"UsernameEndpointPort");
+
+ Service service = Service.create(wsdlURL, serviceName);
+ dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD);
+
+ ((ConfigProvider)dispatch).setSecurityConfig(securityURL.toExternalForm());
+ ((ConfigProvider)dispatch).setConfigName("Standard WSSecurity
Client");
+ }
+ }
+
+ public void testUsernameTokenNegative() throws Exception
+ {
+ try
+ {
+ String payload = "<ns1:getUsernameToken
xmlns:ns1='http://org.jboss.ws/samples/wssecurity'/>";
+ dispatch.invoke(new StreamSource(new StringReader(payload)));
+ fail("Server should respond with [401] - Unauthorized");
+ }
+ catch (Exception ex)
+ {
+ // this should be ok
+ }
+ }
+
+ public void testUsernameToken() throws Exception
+ {
+ Map<String, Object> reqContext = dispatch.getRequestContext();
+ reqContext.put(BindingProvider.USERNAME_PROPERTY, "kermit");
+ reqContext.put(BindingProvider.PASSWORD_PROPERTY, "thefrog");
+
+ String payload = "<ns1:getUsernameToken
xmlns:ns1='http://org.jboss.ws/samples/wssecurity'/>";
+ Source retObj = (Source)dispatch.invoke(new StreamSource(new
StringReader(payload)));
+
+ Element docElement = DOMUtils.sourceToElement(retObj);
+ Element retElement = DOMUtils.getFirstChildElement(docElement);
+ String retPayload = DOMWriter.printNode(retElement, false);
+ assertEquals("<return>kermit</return>", retPayload);
+ }
+}
\ No newline at end of file