[jbossws-commits] JBossWS SVN: r2699 - in trunk/jbossws-core/src/java/org/jboss/ws/core: jaxrpc/client and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Mar 27 23:56:45 EDT 2007


Author: jason.greene at jboss.com
Date: 2007-03-27 23:56:44 -0400 (Tue, 27 Mar 2007)
New Revision: 2699

Modified:
   trunk/jbossws-core/src/java/org/jboss/ws/core/CommonClient.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/CallImpl.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EndpointInfo.java
   trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java
Log:
Initial implementation of http session affinity


Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/CommonClient.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/CommonClient.java	2007-03-27 22:26:52 UTC (rev 2698)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/CommonClient.java	2007-03-28 03:56:44 UTC (rev 2699)
@@ -75,7 +75,9 @@
 {
    // provide logging
    private static Logger log = Logger.getLogger(CommonClient.class);
-
+   
+   public static String SESSION_COOKIES = "org.jboss.ws.maintain.session.cookies";
+   
    // The endpoint together with the operationName uniquely identify the call operation
    protected EndpointMetaData epMetaData;
    // The current operation name
@@ -221,6 +223,8 @@
    protected abstract void setInboundContextProperties();
 
    protected abstract void setOutboundContextProperties();
+   
+   protected abstract boolean shouldMaintainSession();
 
    /** Call invokation goes as follows:
     *
@@ -312,6 +316,8 @@
 
             Map<String, Object> callProps = new HashMap<String, Object>(getRequestContext()); 
             EndpointInfo epInfo = new EndpointInfo(epMetaData, targetAddress, callProps);
+            if (shouldMaintainSession())
+               addSessionInfo(reqMessage, callProps);
 
             SOAPMessage resMessage;
             if (oneway)
@@ -322,12 +328,15 @@
             {
                resMessage = new SOAPConnectionImpl().call(reqMessage, epInfo);
             }
+            
+            if (shouldMaintainSession())
+               saveSessionInfo(callProps, getRequestContext());
 
             // At pivot the message context might be replaced
             msgContext = processPivotInternal(msgContext, direction);
             
             // Copy the remoting meta data 
-            msgContext.putAll(callProps);
+            msgContext.put(CommonMessageContext.REMOTING_METADATA, callProps);
 
             // Associate response message with message context
             msgContext.setSOAPMessage(resMessage);
@@ -393,7 +402,57 @@
          closeHandlerChain(portName, handlerType[0]);
       }
    }
+   
+   private void saveSessionInfo(Map<String, Object> remotingMetadata, Map<String, Object> requestContext)
+   {
+      Map<String, String> cookies = (Map) remotingMetadata.get(SESSION_COOKIES);
+      if (cookies == null)
+      {
+         cookies = new HashMap<String, String>();
+         requestContext.put(SESSION_COOKIES, cookies);
+      }
+      
+      List<String> setCookies = new ArrayList<String>();
+      
+      List<String> setCookies1 = (List)remotingMetadata.get("Set-Cookie");
+      if (setCookies1 != null)
+         setCookies.addAll(setCookies1);
+      
+      List<String> setCookies2 = (List)remotingMetadata.get("Set-Cookie2");
+      if (setCookies2 != null)
+         setCookies.addAll(setCookies2);
+      
+      // TODO: The parsing here should be improved to be fully compliant with the RFC
+      for (String setCookie : setCookies)
+      {
+         int index = setCookie.indexOf(';');
+         if (index == -1)
+            continue;
+         
+         String pair = setCookie.substring(0, index);
+         index = pair.indexOf('=');
+         if (index == -1)
+            continue;
+         
+         String name = pair.substring(0, index);
+         String value = pair.substring(index + 1);
+         
+         cookies.put(name, value);
+      }
+   }
 
+   protected void addSessionInfo(SOAPMessage reqMessage, Map<String, Object> callProperties)
+   {
+      Map<String, String> cookies = (Map) callProperties.get(SESSION_COOKIES);
+      if (cookies != null)
+      {
+         for (Map.Entry<String, String> cookie : cookies.entrySet())
+         {
+            reqMessage.getMimeHeaders().addHeader("Cookie" , cookie.getKey() +  "=" + cookie.getValue()); 
+         }
+      }
+   }
+
    private CommonMessageContext processPivotInternal(CommonMessageContext msgContext, DirectionHolder direction)
    {
       if (direction.getDirection() == Direction.OutBound)

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java	2007-03-27 22:26:52 UTC (rev 2698)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/CommonMessageContext.java	2007-03-28 03:56:44 UTC (rev 2699)
@@ -52,6 +52,8 @@
    // expandToDOM in the SOAPContentElement should not happen during normal operation 
    // This property should be set the message context when it is ok to do so.
    public static String ALLOW_EXPAND_TO_DOM = "org.jboss.ws.allow.expand.dom";
+   
+   public static String REMOTING_METADATA = "org.jboss.ws.remoting.metadata";
 
    // The serialization context for this message ctx
    private SerializationContext serContext;

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/CallImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/CallImpl.java	2007-03-27 22:26:52 UTC (rev 2698)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/client/CallImpl.java	2007-03-28 03:56:44 UTC (rev 2699)
@@ -671,4 +671,11 @@
       
       return set;
    }
+
+   @Override
+   protected boolean shouldMaintainSession()
+   {
+      Object bool = getRequestContext().get(Stub.SESSION_MAINTAIN_PROPERTY);
+      return Boolean.TRUE.equals(bool);
+   }
 }
\ No newline at end of file

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ClientImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ClientImpl.java	2007-03-27 22:26:52 UTC (rev 2698)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/ClientImpl.java	2007-03-28 03:56:44 UTC (rev 2699)
@@ -77,7 +77,7 @@
 {
    // provide logging
    private static Logger log = Logger.getLogger(ClientImpl.class);
-
+   
    private final EndpointMetaData epMetaData;
    private final HandlerResolver handlerResolver;
    private Map<HandlerType, HandlerChainExecutor> executorMap = new HashMap<HandlerType, HandlerChainExecutor>();
@@ -178,17 +178,17 @@
    {
       // Get the HTTP_RESPONSE_CODE
       MessageContext msgContext = (MessageContext)MessageContextAssociation.peekMessageContext();
-      Integer resposeCode = (Integer)msgContext.get(HTTPMetadataConstants.RESPONSE_CODE);
+      Map<?, ?> remotingMetadata = (Map)msgContext.get(CommonMessageContext.REMOTING_METADATA);
+      Integer resposeCode = (Integer)remotingMetadata.get(HTTPMetadataConstants.RESPONSE_CODE);
       if (resposeCode != null)
          msgContext.put(MessageContextJAXWS.HTTP_RESPONSE_CODE, resposeCode);
       
       // Map of attachments to a message for the inbound message, key is  the MIME Content-ID, value is a DataHandler
       msgContext.put(MessageContext.INBOUND_MESSAGE_ATTACHMENTS, new HashMap<String, DataHandler>());
       
-      // Get the HTTP response headers
       // [JBREM-728] Improve access to HTTP response headers
       Map<String, List> headers = new HashMap<String, List>();
-      for (Map.Entry en : msgContext.entrySet())
+      for (Map.Entry en : remotingMetadata.entrySet())
       {
          if (en.getKey() instanceof String && en.getValue() instanceof List)
             headers.put((String)en.getKey(), (List)en.getValue());
@@ -380,4 +380,11 @@
 
       return headers;
    }
+
+   @Override
+   protected boolean shouldMaintainSession()
+   {
+      Object bool = getRequestContext().get(BindingProvider.SESSION_MAINTAIN_PROPERTY);
+      return Boolean.TRUE.equals(bool);
+   }
 }
\ No newline at end of file

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EndpointInfo.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EndpointInfo.java	2007-03-27 22:26:52 UTC (rev 2698)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EndpointInfo.java	2007-03-28 03:56:44 UTC (rev 2699)
@@ -23,6 +23,7 @@
 
 // $Id$
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
@@ -38,7 +39,6 @@
 {
    private String targetAddress;
    private Map<String, Object> properties;
-
    public EndpointInfo(EndpointMetaData epMetaData, String targetAddress, Map<String, Object> callProps)
    {
       this.targetAddress = targetAddress;
@@ -80,7 +80,7 @@
    {
       return targetAddress;
    }
-
+   
    public boolean equals(Object obj)
    {
       if (!(obj instanceof EndpointInfo))

Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java	2007-03-27 22:26:52 UTC (rev 2698)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPConnectionImpl.java	2007-03-28 03:56:44 UTC (rev 2699)
@@ -159,6 +159,8 @@
             timeout = callProps.get(StubExt.PROPERTY_CLIENT_TIMEOUT);
             targetAddress = addURLParameter(targetAddress, "timeout", timeout.toString());
          }
+         
+         
       }
       else if (endpoint instanceof EndpointReference)
       {




More information about the jbossws-commits mailing list