[jbossws-commits] JBossWS SVN: r9479 - in stack/native/branches/jbossws-native-2.0.1.SP2_CP: src/main/java/org/jboss/ws/core and 6 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Mar 4 06:48:58 EST 2009


Author: darran.lofthouse at jboss.com
Date: 2009-03-04 06:48:54 -0500 (Wed, 04 Mar 2009)
New Revision: 9479

Added:
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java
Modified:
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/.classpath
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/ConfigProvider.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/StubExt.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/client/EndpointInfo.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java
Log:
[JBPAPP-1746] Handler Chains missed for Dispatch clients.

Modified: stack/native/branches/jbossws-native-2.0.1.SP2_CP/.classpath
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/.classpath	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/.classpath	2009-03-04 11:48:54 UTC (rev 9479)
@@ -12,6 +12,7 @@
 	<classpathentry kind="lib" path="thirdparty/jaxb-impl.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jaxb-xjc.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jboss-dependency.jar"/>
+	<classpathentry kind="lib" path="thirdparty/jboss-common-core.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jboss-j2ee.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jboss-logging-spi.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jboss-microcontainer.jar"/>

Modified: stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/ConfigProvider.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/ConfigProvider.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/ConfigProvider.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/StubExt.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/StubExt.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/StubExt.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -136,14 +136,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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/client/EndpointInfo.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/client/EndpointInfo.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/client/EndpointInfo.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/binding/BindingExt.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ws.core.jaxws.binding;
 
+//$Id$
+
 import java.util.List;
 
 import javax.xml.ws.Binding;
@@ -28,7 +30,6 @@
 
 import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
 
-// $Id$
 
 /**
  * Extension to JAXWS protocol bindings. 
@@ -38,7 +39,9 @@
  */
 public interface BindingExt extends Binding
 {
+   /** 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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/ClientImpl.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -56,7 +56,6 @@
 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.umdm.ClientEndpointMetaData;
@@ -76,7 +75,7 @@
 {
 
    // the associated endpoint meta data
-   private final EndpointMetaData epMetaData;
+   private final ClientEndpointMetaData epMetaData;
    private EndpointConfigMetaData epConfigMetaData;
 
    // Keep a handle on the resolver so that updateConfig calls may revisit the associated chains
@@ -91,7 +90,7 @@
       super(epMetaData);
       setTargetEndpointAddress(epMetaData.getEndpointAddress());
 
-      this.epMetaData = epMetaData;
+      this.epMetaData = (ClientEndpointMetaData)epMetaData;
       this.epConfigMetaData = epMetaData.getEndpointConfigMetaData();
 
       if (handlerResolver instanceof HandlerResolverImpl)
@@ -113,7 +112,7 @@
    {
       BindingExt binding = (BindingExt)getBindingProvider().getBinding();
 
-      PortInfo portInfo = getPortInfo(epMetaData);
+      PortInfo portInfo = epMetaData.getPortInfo();
 
       if (handlerResolver != null)
       {
@@ -427,12 +426,4 @@
       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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -24,12 +24,18 @@
 // $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.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.transform.Source;
 import javax.xml.ws.AsyncHandler;
@@ -40,22 +46,39 @@
 import javax.xml.ws.Response;
 import javax.xml.ws.WebServiceException;
 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 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.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.EndpointConfigMetaData;
 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. 
@@ -64,22 +87,26 @@
  * @author Thomas.Diesler at 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;
@@ -89,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;
@@ -111,11 +138,50 @@
       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();
+            EndpointConfigMetaData ecmd = epMetaData.getEndpointConfigMetaData();
+            handlerResolver.initHandlerChain(ecmd, HandlerType.PRE, true);
+            handlerResolver.initHandlerChain(ecmd, HandlerType.ENDPOINT, true);
+            handlerResolver.initHandlerChain(ecmd, 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.
@@ -124,22 +190,104 @@
       // 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 = 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());
+            if (callProps.containsKey(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)) {
+               targetAddress = (String) callProps.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+            }
+            EndpointInfo epInfo = new EndpointInfo(epMetaData, targetAddress, callProps);
+            resMsg = getRemotingConnection().invoke(reqMsg, epInfo, false);
+
+            //Pivot, switch to response ctx and save the response message there
+            msgContext = MessageContextJAXWS.processPivot(msgContext);
+            msgContext.setMessageAbstraction(resMsg);
+            
+            // 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)
+      {
+         msgContext = MessageContextJAXWS.processPivot(msgContext);
+         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();
+      Map<String, Object> callProps = new HashMap<String, Object>(getRequestContext());
+      if (callProps.containsKey(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)) {
+         targetAddress = (String) callProps.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
+      }
       MessageAbstraction resMsg = getRemotingConnection().invoke(reqMsg, targetAddress, false);
       Object retObj = getReturnObject(resMsg);
       return retObj;
@@ -260,7 +408,19 @@
    {
       // jaxws/api/javax_xml_ws/Dispatch/Client.java#invokeTestJAXBNull
       if (obj == null)
-         throw new SOAPFaultException("Request object cannot be null");
+      {
+         try
+         {
+            SOAPFactory factory = SOAPFactory.newInstance();
+            SOAPFault fault = factory.createFault("Request object cannot be null", new QName("http://org.jboss.ws", "Dispatch"));
+            fault.setFaultActor("client");
+            throw new SOAPFaultException(fault);
+         }
+         catch (SOAPException e)
+         {
+            //
+         }
+      }
 
       String bindingID = bindingProvider.getBinding().getBindingID();
       if (EndpointMetaData.SUPPORTED_BINDINGS.contains(bindingID) == false)
@@ -314,7 +474,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;
@@ -371,4 +531,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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -85,13 +85,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();
@@ -132,8 +132,14 @@
             opMetaData = soapMessage.getOperationMetaData(epMetaData);
          }
 
-         String operation = opMetaData.getQName().toString();
-         String port = opMetaData.getEndpointMetaData().getPortName().getLocalPart();
+         String operation = null;
+         String port = null;
+         if (opMetaData != null)
+         {
+            operation = opMetaData.getQName().toString();
+            port = opMetaData.getEndpointMetaData().getPortName().getLocalPart();
+         }
+          
 
          if (hasRequirements(config, operation, port))
             throw convertToFault(new InvalidSecurityHeaderException("This service requires <wsse:Security>, which is missing."));
@@ -161,8 +167,13 @@
             opMetaData = soapMessage.getOperationMetaData(epMetaData);
          }
 
-         String operation = opMetaData.getQName().toString();
-         String port = opMetaData.getEndpointMetaData().getPortName().getLocalPart();
+         String operation = null;
+         String port = null;
+         if (opMetaData != null)
+         {
+            operation = opMetaData.getQName().toString();
+            port = opMetaData.getEndpointMetaData().getPortName().getLocalPart();
+         }
 
          List<OperationDescription<RequireOperation>> operations = buildRequireOperations(config, operation, port);
 
@@ -288,26 +299,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);
+      Config opConfig = getConfig(config, port, opName);
+      log.debug("WS-Security config: " + opConfig);
 
-      log.debug("WS-Security config: " + operationConfig);
-
       // 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);
@@ -325,7 +339,7 @@
          }
       }
 
-      Sign sign = operationConfig.getSign();
+      Sign sign = opConfig.getSign();
       if (sign != null)
       {
          List<Target> targets = convertTargets(sign.getTargets());
@@ -341,7 +355,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/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java	2009-03-03 18:52:16 UTC (rev 9478)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/main/java/org/jboss/ws/metadata/umdm/ClientEndpointMetaData.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -24,7 +24,9 @@
 // $Id$
 
 import javax.xml.namespace.QName;
+import javax.xml.ws.handler.PortInfo;
 
+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;
 
@@ -64,11 +66,20 @@
       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 EndpointConfigMetaData createEndpointConfigMetaData(String configName, String configFile)
    {
       return super.createEndpointConfigMetaData(configName, configFile);
    }
-
+   
    public String toString()
    {
       StringBuilder buffer = new StringBuilder("\nClientEndpointMetaData:");

Copied: stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java (from rev 9477, stack/native/branches/dlofthouse/JBPAPP-1746/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java)
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java	                        (rev 0)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleDispatchTestCase.java	2009-03-04 11:48:54 UTC (rev 9479)
@@ -0,0 +1,138 @@
+/*
+ * 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 at jboss.com
+ * @author alessio.soldano at jboss.com
+ * @since 02-Oct-2007
+ */
+public class SimpleDispatchTestCase extends JBossWSTest
+{
+   private static Dispatch usernameDispatch;
+   private static Dispatch encryptDispatch;
+
+   public static Test suite() throws Exception
+   {
+      return new JBossWSTestSetup(SimpleDispatchTestCase.class, "jaxws-samples-wssecurity-username.war jaxws-samples-wssecurity-encrypt.war");
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      if (usernameDispatch == 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);
+         usernameDispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD);
+
+         ((ConfigProvider)usernameDispatch).setSecurityConfig(securityURL.toExternalForm());
+         ((ConfigProvider)usernameDispatch).setConfigName("Standard WSSecurity Client");
+      }
+      if (encryptDispatch == null)
+      {
+         URL wsdlURL = new File("wsprovide/resources/jaxws/samples/wssecurity/HelloService.wsdl").toURL();
+         URL securityURL = new File("resources/jaxws/samples/wssecurity/simple-encrypt/META-INF/jboss-wsse-client.xml").toURL();
+         QName serviceName = new QName("http://org.jboss.ws/samples/wssecurity", "HelloService");
+         QName portName = new QName("http://org.jboss.ws/samples/wssecurity", "HelloPort");
+
+         Service service = Service.create(wsdlURL, serviceName);
+         encryptDispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD);
+
+         ((ConfigProvider)encryptDispatch).setSecurityConfig(securityURL.toExternalForm());
+         ((ConfigProvider)encryptDispatch).setConfigName("Standard WSSecurity Client");
+         
+         encryptDispatch.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+               "http://" + getServerHost() + ":8080/jaxws-samples-wssecurity-encrypt");
+      }
+   }
+
+   public void testUsernameTokenNegative() throws Exception
+   {
+      try
+      {
+         String payload = "<ns1:getUsernameToken xmlns:ns1='http://org.jboss.ws/samples/wssecurity'/>";
+         usernameDispatch.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 = usernameDispatch.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)usernameDispatch.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);
+   }
+   
+   public void testEncrypt() throws Exception
+   {
+      String payload = "<ns1:echoUserType xmlns:ns1='http://org.jboss.ws/samples/wssecurity'><user><msg>Kermit</msg></user></ns1:echoUserType>";
+      Source retObj = (Source)encryptDispatch.invoke(new StreamSource(new StringReader(payload)));
+      
+      Element docElement = DOMUtils.sourceToElement(retObj);
+      Element retElement = DOMUtils.getFirstChildElement(docElement);
+      String retPayload = DOMWriter.printNode(retElement, false);
+      assertEquals("<return><msg>Kermit</msg></return>", retPayload);
+   }
+}
\ No newline at end of file




More information about the jbossws-commits mailing list