You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by de...@apache.org on 2005/12/23 07:53:49 UTC

svn commit: r358753 - in /webservices/axis2/trunk/java/modules: addressing/src/org/apache/axis2/handlers/addressing/ core/src/org/apache/axis2/ core/src/org/apache/axis2/context/ core/src/org/apache/axis2/description/ core/src/org/apache/axis2/engine/ ...

Author: deepal
Date: Thu Dec 22 22:53:22 2005
New Revision: 358753

URL: http://svn.apache.org/viewcvs?rev=358753&view=rev
Log:
 - Completed session management both in AxisServelet and Simple Axis Server
 - Cookie ID is stored in the service context and when sending Http senders will write cookies into HTTP headers 
 - In the case of SimpleAxis Server , if the session context is not found new one will be created and stored in HTTPWorker 

Modified:
    webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/Constants.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ServiceGroupContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/SessionContext.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2WOM.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/InstanceDispatcher.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceGroupContextTest.java

Modified: webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java (original)
+++ webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java Thu Dec 22 22:53:22 2005
@@ -88,7 +88,8 @@
                 Constants.SERVICE_GROUP_ID, Constants.AXIS2_NAMESPACE_PREFIX));
         if (serviceGroupId != null) {
             String groupId = serviceGroupId.getText();
-            ServiceGroupContext serviceGroupContext = msgContext.getConfigurationContext().getServiceGroupContext(groupId);
+            ServiceGroupContext serviceGroupContext = msgContext.getConfigurationContext().
+                    getServiceGroupContext(groupId,msgContext);
             if (serviceGroupContext == null) {
                 throw new AxisFault("Invalid Service Group Id." + groupId);
             }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/Constants.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/Constants.java Thu Dec 22 22:53:22 2005
@@ -179,6 +179,9 @@
     public static final String ADDRESSING_FROM = "WS-Addressing:From";
     public static final String ADDRESSING_FAULT_TO = "WS-Addressing:FaultTo";
 
+    //to set and get the property from service context
+    public static final String COOKIE_STRING = "Cookie";
+
     //See
 
     /**

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContext.java Thu Dec 22 22:53:22 2005
@@ -70,7 +70,7 @@
      *
      * @param messageContext
      */
-    public ServiceGroupContext fillServiceContextAndServiceGroupContext(
+    public void fillServiceContextAndServiceGroupContext(
             MessageContext messageContext)
             throws AxisFault {
         String serviceGroupContextId = messageContext.getServiceGroupContextId();
@@ -78,60 +78,60 @@
 
         // by this time service group context id must have a value. Either from transport or from addressing
         ServiceGroupContext serviceGroupContext;
-        ServiceContext serviceContext;
-
-        if (!isNull(serviceGroupContextId)
-                && (getServiceGroupContext(serviceGroupContextId) != null)) {
-
-            // SGC is already there
-            serviceGroupContext =
-                    getServiceGroupContext(serviceGroupContextId);
-            serviceContext =
-                    serviceGroupContext.getServiceContext(messageContext.getAxisService());
-        } else {
+        ServiceContext serviceContext = messageContext.getServiceContext();
+        if (serviceContext == null) {
+            if (!isNull(serviceGroupContextId)
+                    && (getServiceGroupContext(serviceGroupContextId, messageContext) != null)) {
+
+                // SGC is already there
+                serviceGroupContext =
+                        getServiceGroupContext(serviceGroupContextId, messageContext);
+                serviceContext =
+                        serviceGroupContext.getServiceContext(messageContext.getAxisService());
+            } else {
 
-            // either the key is null or no SGC is found from the give key
-            if (isNull(serviceGroupContextId)) {
-                serviceGroupContextId = UUIDGenerator.getUUID();
-                messageContext.setServiceGroupContextId(serviceGroupContextId);
+                // either the key is null or no SGC is found from the give key
+                if (isNull(serviceGroupContextId)) {
+                    serviceGroupContextId = UUIDGenerator.getUUID();
+                    messageContext.setServiceGroupContextId(serviceGroupContextId);
+                }
+
+                if (messageContext.getAxisService() != null) {
+                    AxisServiceGroup axisServiceGroup = messageContext.getAxisService().getParent();
+
+                    serviceGroupContext = new ServiceGroupContext(this, axisServiceGroup);
+                    serviceContext = serviceGroupContext.getServiceContext(messageContext.getAxisService());
+
+                    // set the serviceGroupContextID
+                    serviceGroupContext.setId(serviceGroupContextId);
+                } else {
+                    throw new AxisFault("AxisService Not found yet");
+                }
             }
 
-            if (messageContext.getAxisService() != null) {
-                AxisServiceGroup axisServiceGroup = messageContext.getAxisService().getParent();
-
-                serviceGroupContext = new ServiceGroupContext(this, axisServiceGroup);
-                serviceContext = serviceGroupContext.getServiceContext(messageContext.getAxisService());
-
-                // set the serviceGroupContextID
-                serviceGroupContext.setId(serviceGroupContextId);
+            /**
+             * 1. Check the max scope of the service gruop , if it is grater than TarnsportSession
+             *    then need to store in configurationContext
+             * 2. Else need to store in SessionContext , and need to store both service context and
+             *    service group context
+             */
+            String maxScope = SessionUtils.calculateMaxScopeForServiceGroup(serviceGroupContext.getDescription());
+            if (Constants.APPLICATION_SCOPE.equals(maxScope)) {
+                //todo : needed to add to two tables
+                registerServiceGroupContext(serviceGroupContext);
+            } else if (Constants.SOAP_SESSION_SCOPE.equals(maxScope)) {
+                //todo : needed to add to two tables
+                registerServiceGroupContext(serviceGroupContext);
             } else {
-                throw new AxisFault("AxisService Not found yet");
+                sessionContext.addServiceGroupContext(serviceGroupContext, serviceGroupContextId);
+                sessionContext.addServiceContext(serviceContext);
             }
-        }
-
-        /**
-         * 1. Check the max scope of the service gruop , if it is grater than TarnsportSession
-         *    then need to store in configurationContext
-         * 2. Else need to store in SessionContext , and need to store both service context and
-         *    service group context
-         */
-        String maxScope = SessionUtils.calculateMaxScopeForServiceGroup(serviceGroupContext.getDescription());
-        if (Constants.APPLICATION_SCOPE.equals(maxScope)) {
-            //todo : needed to add to two tables
-            registerServiceGroupContext(serviceGroupContext);
-        } else if (Constants.TRANSPORT_SESSION_SCOPE.equals(maxScope)) {
-            //todo : needed to add to two tables
-            registerServiceGroupContext(serviceGroupContext);
-        } else {
-            sessionContext.addServiceGroupContext(serviceGroupContext, serviceGroupContextId);
-            sessionContext.addServiceContext(serviceContext);
+            messageContext.setServiceContext(serviceContext);
+            messageContext.setServiceGroupContext(serviceGroupContext);
         }
         // when you come here operation context MUST already been assigned to the message context
+        serviceContext.setProperty(Constants.COOKIE_STRING, sessionContext.getCookieID());
         messageContext.getOperationContext().setParent(serviceContext);
-        messageContext.setServiceContext(serviceContext);
-        messageContext.setServiceGroupContext(serviceGroupContext);
-
-        return serviceGroupContext;
     }
 
     /**
@@ -189,17 +189,21 @@
         }
     }
 
-    public synchronized ServiceGroupContext getServiceGroupContext(String serviceGroupContextId) {
+    public synchronized ServiceGroupContext getServiceGroupContext(String serviceGroupContextId,
+                                                                   MessageContext msgContext) {
+        ServiceGroupContext serviceGroupContext = null;
         if (serviceGroupContextMap != null) {
-            ServiceGroupContext serviceGroupContext = (ServiceGroupContext)
-                    serviceGroupContextMap.get(serviceGroupContextId);
+            serviceGroupContext = (ServiceGroupContext) serviceGroupContextMap.get(serviceGroupContextId);
             if (serviceGroupContext != null) {
                 serviceGroupContext.touch();
             }
-            return serviceGroupContext;
+        }
+        if (serviceGroupContext == null) {
+            serviceGroupContext = msgContext.getSessionContext().getServiceGroupContext(
+                    serviceGroupContextId);
         }
 
-        return null;
+        return serviceGroupContext;
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java Thu Dec 22 22:53:22 2005
@@ -871,6 +871,7 @@
 
     public void setServiceGroupContext(ServiceGroupContext serviceGroupContext) {
         this.serviceGroupContext = serviceGroupContext;
+        this.axisServiceGroup = serviceGroupContext.getDescription();
     }
 
     public void setServiceGroupContextId(String serviceGroupContextId) {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ServiceGroupContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ServiceGroupContext.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ServiceGroupContext.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ServiceGroupContext.java Thu Dec 22 22:53:22 2005
@@ -18,7 +18,6 @@
 package org.apache.axis2.context;
 
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
 
@@ -61,17 +60,10 @@
             throw new AxisFault("Invalid service " + service.getName() + " not belong to " +
                     "service group " + axisServiceGroup.getServiceGroupName());
         }
-        String scope = axisService.getScope();
-        ServiceContext serviceContext;
-        if (Constants.APPLICATION_SCOPE.equals(scope) || Constants.SOAP_SESSION_SCOPE.equals(scope)) {
-            //since the session scope is longer that trasport or request we need to store that some where
-            serviceContext = (ServiceContext) serviceContextMap.get(service.getName());
-            if (serviceContext == null) {
-                serviceContext = new ServiceContext(service, this);
-            }
-            serviceContextMap.put(service.getName(), serviceContext);
-        } else {
+        ServiceContext serviceContext = (ServiceContext) serviceContextMap.get(service.getName());
+        if (serviceContext == null) {
             serviceContext = new ServiceContext(service, this);
+            serviceContextMap.put(service.getName(), serviceContext);
         }
         return serviceContext;
     }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/SessionContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/SessionContext.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/SessionContext.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/SessionContext.java Thu Dec 22 22:53:22 2005
@@ -21,6 +21,7 @@
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.engine.AxisConfiguration;
 
+import java.util.Date;
 import java.util.HashMap;
 
 /**
@@ -31,6 +32,10 @@
 
     private HashMap serviceContextMap = new HashMap();
     private HashMap serviceGroupContextMap = new HashMap();
+    private String cookieID;
+
+    // current time out interval is 30 secs. Need to make this configurable
+    public long sessionContextTimeoutInterval = 30 * 1000;
 
     /**
      * @param parent
@@ -57,5 +62,34 @@
     public ServiceGroupContext getServiceGroupContext(String serviceGroupID) {
         return (ServiceGroupContext) serviceGroupContextMap.get(serviceGroupID);
     }
+
+    public String getCookieID() {
+        return cookieID;
+    }
+
+    public void setCookieID(String cookieID) {
+        this.cookieID = cookieID;
+    }
+
+    /**
+     * ServiceContext and ServiceGroupContext are not getting automatically garbage collected. And there
+     * is no specific way for some one to go and make it garbage collectable.
+     * So the current solution is to make them time out. So the logic is that, there is a timer task
+     * in each and every service group which will check for the last touched time. And if it has not
+     * been touched for some time, the timer task will remove it from the memory.
+     * The touching logic happens like this. Whenever there is a call to addMessageContext in the operationContext
+     * it will go and update operationCOntext -> serviceContext -> serviceGroupContext.
+     */
+    public void touch() {
+        lastTouchedTime = new Date().getTime();
+        if (parent != null) {
+            parent.touch();
+        }
+    }
+
+    public long getLastTouchedTime() {
+        return lastTouchedTime;
+    }
+
 
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2WOM.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2WOM.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2WOM.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/AxisService2WOM.java Thu Dec 22 22:53:22 2005
@@ -4,12 +4,8 @@
 import org.apache.axis2.wsdl.java2wsdl.SchemaGenerator;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.wsdl.*;
-import org.apache.wsdl.extensions.ExtensionConstants;
-import org.apache.wsdl.extensions.ExtensionFactory;
+import org.apache.wsdl.extensions.*;
 import org.apache.wsdl.extensions.impl.SOAPAddressImpl;
-import org.apache.wsdl.extensions.impl.SOAPBindingImpl;
-import org.apache.wsdl.extensions.impl.SOAPBodyImpl;
-import org.apache.wsdl.extensions.impl.SOAPOperationImpl;
 import org.apache.wsdl.impl.WSDLDescriptionImpl;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -134,7 +130,7 @@
             }
 
             AxisMessage outaxisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
-            if (outaxisMessage != null) {
+            if (outaxisMessage != null && outaxisMessage.getElementQName() != null) {
                 MessageReference messageRefout = wsdlComponentFactory.createMessageReference();
                 messageRefout.setElementQName(outaxisMessage.getElementQName());
                 messageRefout.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
@@ -168,10 +164,14 @@
                                         String trsportURI,
                                         String namespeceURI) {
         WSDLBinding binding = wsdlComponentFactory.createBinding();
+
+        ExtensionFactory extensionFactory = wsdlComponentFactory.createExtensionFactory();
+
         binding.setBoundInterface(portType);
         binding.setName(bindingName);
 
-        SOAPBindingImpl soapbindingImpl = new SOAPBindingImpl();
+        SOAPBinding soapbindingImpl = (SOAPBinding) extensionFactory.getExtensionElement(
+                ExtensionConstants.SOAP_11_BINDING);
         soapbindingImpl.setStyle(style);
         soapbindingImpl.setTransportURI(trsportURI);
         binding.addExtensibilityElement(soapbindingImpl);
@@ -187,7 +187,8 @@
             bindingoperation.setOperation(wsdlOperation);
             binding.addBindingOperation(bindingoperation);
 
-            SOAPOperationImpl soapOpimpl = new SOAPOperationImpl();
+            SOAPOperation soapOpimpl = (SOAPOperation) extensionFactory.getExtensionElement(
+                    ExtensionConstants.SOAP_11_OPERATION);
             soapOpimpl.setStyle(style);
             //to do heve to set a proper SOAPAction
             soapOpimpl.setSoapAction(opName);
@@ -196,7 +197,9 @@
                 WSDLBindingMessageReference bindingInMessage = wsdlComponentFactory.createWSDLBindingMessageReference();
                 bindingInMessage.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
                 bindingoperation.setInput(bindingInMessage);
-                SOAPBodyImpl requestSoapbody = new SOAPBodyImpl();
+
+                SOAPBody requestSoapbody = (SOAPBody) extensionFactory.getExtensionElement(
+                        ExtensionConstants.SOAP_11_BODY);
                 requestSoapbody.setUse(use);
                 //todo need to fix this
                 requestSoapbody.setNamespaceURI(namespeceURI);
@@ -209,7 +212,8 @@
 
                 bindingOutMessage.setDirection(org.apache.wsdl.WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
                 bindingoperation.setOutput(bindingOutMessage);
-                SOAPBodyImpl resSoapbody = new SOAPBodyImpl();
+                SOAPBody resSoapbody = (SOAPBody) extensionFactory.getExtensionElement(
+                        ExtensionConstants.SOAP_11_BODY);
                 resSoapbody.setUse(use);
                 resSoapbody.setNamespaceURI(namespeceURI);
                 bindingOutMessage.addExtensibilityElement(resSoapbody);

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/InstanceDispatcher.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/InstanceDispatcher.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/InstanceDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/InstanceDispatcher.java Thu Dec 22 22:53:22 2005
@@ -96,8 +96,15 @@
         String serviceGroupContextId = msgContext.getServiceGroupContextId();
         if (serviceGroupContextId != null) {
             //setting service group context which is teken from session context
-            msgContext.setServiceGroupContext(
-                    sessionContext.getServiceGroupContext(serviceGroupContextId));
+            ServiceGroupContext serviceGroupContext = sessionContext.getServiceGroupContext(
+                    serviceGroupContextId);
+            if (serviceGroupContext != null) {
+                //setting service group context
+                msgContext.setServiceGroupContext(serviceGroupContext);
+                // setting Service conetxt
+                msgContext.setServiceContext(serviceGroupContext.getServiceContext(service));
+                return;
+            }
         }
         String scope = service.getScope();
 

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Thu Dec 22 22:53:22 2005
@@ -10,15 +10,7 @@
 import org.apache.axis2.om.OMAttribute;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMOutputFormat;
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HeaderElement;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.commons.logging.Log;
@@ -67,9 +59,9 @@
                                              TransportOutDescription proxySetting, HostConfiguration config, MessageContext msgCtx)
             throws AxisFault {
         Parameter proxyParam = proxySetting.getParameter(HTTPConstants.PROXY);
-        String usrName = null;
-        String domain = null;
-        String passwd = null;
+        String usrName;
+        String domain;
+        String passwd;
         Credentials proxyCred = null;
         String proxyHostName = null;
         int proxyPort = -1;
@@ -150,8 +142,8 @@
                 NameValuePair charsetEnc =
                         headers[i].getParameterByName(HTTPConstants.CHAR_SET_ENCODING);
                 OperationContext opContext = msgContext.getOperationContext();
-
-                if (headers[i].getName().equalsIgnoreCase(
+                String name = headers[i].getName();
+                if (name.equalsIgnoreCase(
                         HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)) {
                     if (opContext != null) {
                         opContext.setProperty(HTTPConstants.MTOM_RECIVED_CONTENT_TYPE,
@@ -163,6 +155,14 @@
                 }
             }
         }
+        Header cookieHeader = method.getResponseHeader(HTTPConstants.HEADER_SET_COOKIE);
+        if (cookieHeader == null) {
+            cookieHeader = method.getResponseHeader(HTTPConstants.HEADER_SET_COOKIE2);
+        }
+        if (cookieHeader != null) {
+            msgContext.getServiceContext().setProperty(Constants.COOKIE_STRING,
+                    cookieHeader.getValue());
+        }
     }
 
     protected void processResponse(HttpMethodBase httpMethod, MessageContext msgContext)
@@ -336,7 +336,7 @@
 
         public void writeRequest(OutputStream out) throws IOException {
             try {
-                if (doingMTOM) {    
+                if (doingMTOM) {
                     if (chuncked) {
                         this.handleOMOutput(out, doingMTOM);
                     } else {
@@ -370,7 +370,7 @@
 
         public long getContentLength() {
             try {
-                if (doingMTOM) {    
+                if (doingMTOM) {
                     if (chuncked) {
                         return -1;
                     } else {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java Thu Dec 22 22:53:22 2005
@@ -227,7 +227,7 @@
 
     private Object getSessionContext(HttpServletRequest httpServletRequest) {
         Object sessionContext =
-                httpServletRequest.getSession().getAttribute(Constants.SESSION_CONTEXT_PROPERTY);
+                httpServletRequest.getSession(true).getAttribute(Constants.SESSION_CONTEXT_PROPERTY);
 
         if (sessionContext == null) {
             sessionContext = new SessionContext(null);

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java Thu Dec 22 22:53:22 2005
@@ -23,6 +23,7 @@
  * HTTP protocol and message context constants.
  */
 public class HTTPConstants {
+
     public static final String HTTP_CONTENT_TYPE = "HTTP_CONTENT_TYPE";
     public static final String PROTOCOL_VERSION = "PROTOCOL";
     public static final String MEDIA_TYPE_X_WWW_FORM =

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java Thu Dec 22 22:53:22 2005
@@ -22,6 +22,7 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.SessionContext;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.engine.AxisConfiguration;
@@ -43,13 +44,14 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.SocketException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
 
 public class HTTPWorker implements HttpRequestHandler {
+
     protected Log log = LogFactory.getLog(getClass().getName());
     private ConfigurationContext configurationContext;
+    // to store session object
+    private Hashtable sessionContextTable = new Hashtable();
 
     public HTTPWorker(ConfigurationContext configurationContext) {
         this.configurationContext = configurationContext;
@@ -70,9 +72,10 @@
             TransportOutDescription transportOut =
                     configurationContext.getAxisConfiguration().getTransportOut(
                             new QName(Constants.TRANSPORT_HTTP));
+            String cookieID = request.getCookieID();
+            SessionContext sessionContext = getSessionContext(cookieID);
 
-            msgContext = new MessageContext(
-                    configurationContext,
+            msgContext = new MessageContext(configurationContext, sessionContext,
                     configurationContext.getAxisConfiguration().getTransportIn(
                             new QName(Constants.TRANSPORT_HTTP)), transportOut);
             msgContext.setServerSide(true);
@@ -83,12 +86,12 @@
                 throw new AxisFault("HTTP version can not be Null");
             }
 
-            String httpVersion = null;
+//            String httpVersion = null;
 
             if (HttpVersion.HTTP_1_0.equals(ver)) {
-                httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
+//                httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
             } else if (HttpVersion.HTTP_1_1.equals(ver)) {
-                httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+//                httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
 
                 /**
                  * Transport Sender configuration via axis2.xml
@@ -129,7 +132,7 @@
                     response.addHeader(new Header("Content-Type", "text/html"));
                     response.setBodyString(
                             HTTPTransportReceiver.getServicesHTML(configurationContext));
-                    setResponseHeaders(conn, request, response, 0);
+                    setResponseHeaders(conn, request, response, 0, msgContext);
                     conn.writeResponse(response);
 
                     return true;
@@ -137,7 +140,7 @@
             } else {
                 ByteArrayOutputStream baosIn = new ByteArrayOutputStream();
                 byte[]                bytes = new byte[8192];
-                int size = 0;
+                int size;
 
                 while ((size = inStream.read(bytes)) > 0) {
                     baosIn.write(bytes, 0, size);
@@ -164,7 +167,8 @@
             }
 
             response.setBody(new ByteArrayInputStream(baos.toByteArray()));
-            setResponseHeaders(conn, request, response, baos.toByteArray().length);
+            setResponseHeaders(conn, request, response, baos.toByteArray().length, msgContext);
+
             conn.writeResponse(response);
         } catch (Throwable e) {
             if (!(e instanceof java.net.SocketException)) {
@@ -183,7 +187,7 @@
                             "Internal server error");
                     engine.sendFault(faultContext);
                     response.setBody(new ByteArrayInputStream(baos.toByteArray()));
-                    setResponseHeaders(conn, request, response, baos.toByteArray().length);
+                    setResponseHeaders(conn, request, response, baos.toByteArray().length, msgContext);
                     conn.writeResponse(response);
                 }
             } catch (SocketException e1) {
@@ -207,7 +211,6 @@
         AxisConfiguration axisConf = configContext.getAxisConfiguration();
         HashMap trasportOuts = axisConf.getTransportsOut();
         Iterator values = trasportOuts.values().iterator();
-        String httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
 
         while (values.hasNext()) {
             TransportOutDescription transportOut = (TransportOutDescription) values.next();
@@ -217,7 +220,6 @@
 
             if (version != null) {
                 if (HTTPConstants.HEADER_PROTOCOL_11.equals(version.getValue())) {
-                    httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
 
                     Parameter transferEncoding =
                             transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
@@ -230,12 +232,6 @@
                                             HTTPConstants.HEADER_TRANSFER_ENCODING,
                                             HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED));
                         }
-                    } else {
-                        continue;
-                    }
-                } else {
-                    if (HTTPConstants.HEADER_PROTOCOL_10.equals(version.getValue())) {
-                        httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
                     }
                 }
             }
@@ -254,7 +250,7 @@
     }
 
     private void setResponseHeaders(final SimpleHttpServerConnection conn, SimpleRequest request,
-                                    SimpleResponse response, long contentLength) {
+                                    SimpleResponse response, long contentLength, MessageContext msgContext) {
         if (!response.containsHeader("Connection")) {
 
             // See if the the client explicitly handles connection persistence
@@ -284,6 +280,13 @@
                 }
             }
         }
+        //TODO : provide a way to enable and diable cookies
+        //setting the coolie in the out path
+        Object cookieString = msgContext.getProperty(Constants.COOKIE_STRING);
+        if (cookieString != null) {
+            response.addHeader(new Header(HTTPConstants.HEADER_SET_COOKIE, (String) cookieString));
+            response.addHeader(new Header(HTTPConstants.HEADER_SET_COOKIE2, (String) cookieString));
+        }
 
         if (!response.containsHeader("Transfer-Encoding")) {
             if (contentLength != 0) {
@@ -293,4 +296,43 @@
             }
         }
     }
+
+    /**
+     * To get the sessioncontext , if its not there in the hashtable , new one will be created and
+     * added to the list.
+     *
+     * @param cookieID
+     * @return <code>SessionContext</code>
+     */
+    private synchronized SessionContext getSessionContext(String cookieID) {
+        SessionContext sessionContext = null;
+        if (!(cookieID == null || cookieID.trim().equals(""))) {
+            sessionContext = (SessionContext) sessionContextTable.get(cookieID);
+        }
+        if (sessionContext == null) {
+            String cookieString = UUIDGenerator.getUUID();
+            sessionContext = new SessionContext(null);
+            sessionContext.setCookieID(cookieString);
+            sessionContextTable.put(cookieString, sessionContext);
+        }
+        sessionContext.touch();
+        cleanupServiceGroupContexts();
+        return sessionContext;
+    }
+
+    private void cleanupServiceGroupContexts() {
+        synchronized (sessionContextTable) {
+            long currentTime = new Date().getTime();
+            Iterator sgCtxtMapKeyIter = sessionContextTable.keySet().iterator();
+            while (sgCtxtMapKeyIter.hasNext()) {
+                String cookieID = (String) sgCtxtMapKeyIter.next();
+                SessionContext sessionContext = (SessionContext) sessionContextTable.get(cookieID);
+                if ((currentTime - sessionContext.getLastTouchedTime()) >
+                        sessionContext.sessionContextTimeoutInterval) {
+                    sgCtxtMapKeyIter.remove();
+                }
+            }
+        }
+    }
+
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java Thu Dec 22 22:53:22 2005
@@ -1,17 +1,14 @@
 package org.apache.axis2.transport.http;
 
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMOutputFormat;
 import org.apache.axis2.soap.SOAP11Constants;
 import org.apache.axis2.soap.SOAP12Constants;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
 
@@ -66,6 +63,14 @@
         } else {
         }
 
+        //TODO : provide a way to enable and diable cookies
+        //setting the coolie in the out path
+        Object cookieString = msgContext.getProperty(Constants.COOKIE_STRING);
+        if (cookieString != null) {
+            postMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE, (String) cookieString);
+            postMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE2, (String) cookieString);
+        }
+
         postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
 
         if (httpVersion != null) {
@@ -170,7 +175,7 @@
 
         public void writeRequest(OutputStream out) throws IOException {
             try {
-                if (doingMTOM) {    
+                if (doingMTOM) {
                     if (chuncked) {
                         this.handleOMOutput(out, doingMTOM);
                     } else {
@@ -204,7 +209,7 @@
 
         public long getContentLength() {
             try {
-                if (doingMTOM) {    
+                if (doingMTOM) {
                     if (chuncked) {
                         return -1;
                     } else {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java Thu Dec 22 22:53:22 2005
@@ -49,9 +49,9 @@
     private String name = null;
     transient boolean stopped;
 
+
     public SimpleConnectionThread(final String name, final SimpleHttpServerConnection conn,
-                                  final SimpleConnSet connpool, final HttpRequestHandler handler)
-            {
+                                  final SimpleConnSet connpool, final HttpRequestHandler handler) {
 
         // super(tg, name);
         if (conn == null) {
@@ -80,8 +80,6 @@
             conn = null;
         }
         this.stopped = true;
-
-
 
         // interrupt();
     }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java Thu Dec 22 22:53:22 2005
@@ -30,12 +30,8 @@
 
 package org.apache.axis2.transport.http.server;
 
-import org.apache.commons.httpclient.ChunkedInputStream;
-import org.apache.commons.httpclient.ContentLengthInputStream;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HeaderElement;
-import org.apache.commons.httpclient.HeaderGroup;
-import org.apache.commons.httpclient.NameValuePair;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.httpclient.*;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -201,6 +197,23 @@
             return contenttype.getValue();
         } else {
             return "text/plain";
+        }
+    }
+
+    /**
+     * To get the cookieID from HTTPHeaders
+     *
+     * @return string : cookieID
+     */
+    public String getCookieID() {
+        Header cookieHeader = this.headers.getFirstHeader(HTTPConstants.HEADER_COOKIE);
+        if (cookieHeader == null) {
+            cookieHeader = this.headers.getFirstHeader(HTTPConstants.HEADER_COOKIE2);
+        }
+        if (cookieHeader == null) {
+            return null;
+        } else {
+            return cookieHeader.getValue();
         }
     }
 

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java Thu Dec 22 22:53:22 2005
@@ -40,6 +40,7 @@
 import java.io.File;
 
 public class Utils {
+
     public static void addHandler(Flow flow, Handler handler, String phaseName) {
         HandlerDescription handlerDesc = new HandlerDescription();
         PhaseRule rule = new PhaseRule(phaseName);

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceGroupContextTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceGroupContextTest.java?rev=358753&r1=358752&r2=358753&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceGroupContextTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/ServiceGroupContextTest.java Thu Dec 22 22:53:22 2005
@@ -53,7 +53,8 @@
      */
 
     protected EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:" +
-            (UtilServer.TESTING_PORT) +
+            (5000) +
+//            (UtilServer.TESTING_PORT) +
             "/axis/services/RequestCounter");
     protected Log log = LogFactory.getLog(getClass());
     protected QName serviceName = new QName("RequestCounter");