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 ch...@apache.org on 2006/06/16 04:30:47 UTC
svn commit: r414724 - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http:
./ server/
Author: chuckw
Date: Thu Jun 15 19:30:47 2006
New Revision: 414724
URL: http://svn.apache.org/viewvc?rev=414724&view=rev
Log:
Fixes to SimpleHTTPServer cookie handling and session management per AXIS2-819 courtesy of Oleg.
Added:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AxisParams.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestSessionCookie.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseSessionCookie.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SessionManager.java
Modified:
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/SimpleHTTPServer.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpFactory.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpUtils.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?rev=414724&r1=414723&r2=414724&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 Jun 15 19:30:47 2006
@@ -38,7 +38,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.GZIPOutputStream;
@@ -92,7 +91,6 @@
cookie = cookie.substring(0,index);
}
postMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE,cookie);
- postMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE2, cookie);
}
postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?rev=414724&r1=414723&r2=414724&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java Thu Jun 15 19:30:47 2006
@@ -75,7 +75,7 @@
public SimpleHTTPServer(HttpFactory httpFactory) throws AxisFault {
this.httpFactory = httpFactory;
this.configurationContext = httpFactory.getConfigurationContext();
- this. port = httpFactory.getPort();
+ this.port = httpFactory.getPort();
TransportInDescription httpDescription = new TransportInDescription(new QName(Constants.TRANSPORT_HTTP));
httpDescription.setReceiver(this);
httpFactory.getListenerManager().addListener(httpDescription, true);
Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AxisParams.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AxisParams.java?rev=414724&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AxisParams.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AxisParams.java Thu Jun 15 19:30:47 2006
@@ -0,0 +1,39 @@
+/*
+* $HeadURL$
+* $Revision$
+* $Date$
+*
+* ====================================================================
+*
+* Copyright 1999-2004 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of the Apache Software Foundation. For more
+* information on the Apache Software Foundation, please see
+* <http://www.apache.org/>.
+*/
+package org.apache.axis2.transport.http.server;
+
+public class AxisParams {
+
+ private AxisParams() {
+ }
+
+ public static final String LISTENER_PORT = "axis.listener.port";
+
+ public static final String MESSAGE_CONTEXT = "axis.message.context";
+
+}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java?rev=414724&r1=414723&r2=414724&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java Thu Jun 15 19:30:47 2006
@@ -38,10 +38,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpServerConnection;
import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.ResponseConnControl;
-import org.apache.http.protocol.ResponseContent;
-import org.apache.http.protocol.ResponseDate;
-import org.apache.http.protocol.ResponseServer;
import edu.emory.mathcs.backport.java.util.concurrent.Executor;
@@ -54,6 +50,7 @@
private final WorkerFactory workerfactory;
private final HttpParams params;
private final List processors;
+ private final SessionManager sessionManager;
private HttpFactory httpFactory = null;
@@ -76,6 +73,7 @@
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.configurationContext = configurationContext;
+ this.sessionManager = new SessionManager();
this.executor = executor;
this.workerfactory = workerfactory;
this.params = params;
@@ -134,18 +132,15 @@
};
HttpServiceProcessor processor;
- if (httpFactory!=null)
- processor = httpFactory.newRequestServiceProcessor(conn, workerfactory.newWorker(), callback);
- else
- processor = new DefaultHttpServiceProcessor(conn, configurationContext, workerfactory.newWorker(), callback);
+ if (httpFactory != null) {
+ processor = httpFactory.newRequestServiceProcessor(
+ conn, sessionManager, workerfactory.newWorker(), callback);
+ } else {
+ processor = new DefaultHttpServiceProcessor(
+ conn, configurationContext, sessionManager, workerfactory.newWorker(), callback);
+ }
processor.setParams(this.params);
- // Add required protocol interceptors
- processor.addInterceptor(new ResponseDate());
- processor.addInterceptor(new ResponseServer());
- processor.addInterceptor(new ResponseContent());
- processor.addInterceptor(new ResponseConnControl());
-
addProcessor(processor);
this.executor.execute(processor);
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java?rev=414724&r1=414723&r2=414724&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/DefaultHttpServiceProcessor.java Thu Jun 15 19:30:47 2006
@@ -31,23 +31,17 @@
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Iterator;
import javax.xml.namespace.QName;
-import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.context.ServiceGroupContext;
import org.apache.axis2.context.SessionContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.engine.DependencyManager;
-import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.util.UUIDGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -62,22 +56,27 @@
import org.apache.http.UnsupportedHttpVersionException;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.ResponseConnControl;
+import org.apache.http.protocol.ResponseContent;
+import org.apache.http.protocol.ResponseDate;
+import org.apache.http.protocol.ResponseServer;
public class DefaultHttpServiceProcessor extends HttpServiceProcessor {
private static final Log LOG = LogFactory.getLog(DefaultHttpServiceProcessor.class);
private static final Log HEADERLOG = LogFactory.getLog("org.apache.axis2.transport.http.server.wire");
- // to store session object
- private static Hashtable sessionContextTable = new Hashtable();
-
private final ConfigurationContext configurationContext;
+ private final SessionManager sessionManager;
private final Worker worker;
private final IOProcessorCallback callback;
+ private HttpContext httpcontext = null;
+
public DefaultHttpServiceProcessor(
final HttpServerConnection conn,
final ConfigurationContext configurationContext,
+ final SessionManager sessionManager,
final Worker worker,
final IOProcessorCallback callback) {
super(conn);
@@ -87,9 +86,21 @@
if (configurationContext == null) {
throw new IllegalArgumentException("Configuration context may not be null");
}
+ if (sessionManager == null) {
+ throw new IllegalArgumentException("Session manager may not be null");
+ }
this.configurationContext = configurationContext;
+ this.sessionManager = sessionManager;
this.worker = worker;
this.callback = callback;
+
+ // Add required protocol interceptors
+ addInterceptor(new RequestSessionCookie());
+ addInterceptor(new ResponseDate());
+ addInterceptor(new ResponseServer());
+ addInterceptor(new ResponseContent());
+ addInterceptor(new ResponseConnControl());
+ addInterceptor(new ResponseSessionCookie());
}
protected void postprocessResponse(final HttpResponse response, final HttpContext context)
@@ -106,6 +117,9 @@
protected void preprocessRequest(final HttpRequest request, final HttpContext context)
throws IOException, HttpException {
+ // As of next version of HttpCore the HTTP execution context can be retrieved
+ // by calling #getContext()
+ this.httpcontext = context;
super.preprocessRequest(request, context);
if (HEADERLOG.isDebugEnabled()) {
HEADERLOG.debug(">> " + request.getRequestLine().toString());
@@ -137,29 +151,30 @@
TransportInDescription transportIn = this.configurationContext.getAxisConfiguration()
.getTransportIn(new QName(Constants.TRANSPORT_HTTP));
- String cookieID = HttpUtils.getCookieID(request);
msgContext.setConfigurationContext(this.configurationContext);
+
+ String sessionKey = (String) this.httpcontext.getAttribute(Constants.COOKIE_STRING);
if (this.configurationContext.getAxisConfiguration().isManageTransportSession()) {
- SessionContext sessionContext = getSessionContext(cookieID);
+ SessionContext sessionContext = this.sessionManager.getSessionContext(sessionKey);
msgContext.setSessionContext(sessionContext);
}
msgContext.setTransportIn(transportIn);
msgContext.setTransportOut(transportOut);
msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
msgContext.setServerSide(true);
- msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL,
- request.getRequestLine().getUri());
+ msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, reqline.getUri());
// set the transport Headers
HashMap headerMap = new HashMap();
- Header[] headers = request.getAllHeaders();
- for (int i = 0; i < headers.length; i++) {
- headerMap.put(headers[i].getName(), headers[i].getValue());
+ for (Iterator it = request.headerIterator(); it.hasNext(); ) {
+ Header header = (Header) it.next();
+ headerMap.put(header.getName(), header.getValue());
}
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
+ this.httpcontext.setAttribute(AxisParams.MESSAGE_CONTEXT, msgContext);
+
this.worker.service(request, response, msgContext);
- setCookie(response, msgContext);
} catch (SocketException ex) {
// Socket is unreliable.
throw ex;
@@ -179,7 +194,6 @@
response.setStatusLine(new StatusLine(ver, 500, "Internal server error"));
engine.sendFault(faultContext);
response.setEntity(outbuffer);
- setCookie(response, msgContext);
} catch (Exception ex) {
response.setStatusLine(new StatusLine(ver, 500, "Internal server error"));
StringEntity entity = new StringEntity(ex.getMessage());
@@ -190,73 +204,6 @@
}
- private static void setCookie(final HttpResponse response, MessageContext msgContext) {
- //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));
- }
- }
-
- /**
- * 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 = System.currentTimeMillis();
- 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();
- Iterator serviceGroupContext = sessionContext.getServiceGroupContext();
- if (serviceGroupContext != null) {
- while (serviceGroupContext.hasNext()) {
- ServiceGroupContext groupContext = (ServiceGroupContext) serviceGroupContext.next();
- cleanupServiceContextes(groupContext);
- }
- }
- }
- }
- }
- }
-
- private void cleanupServiceContextes(ServiceGroupContext serviceGroupContext) {
- Iterator serviceContecxtes = serviceGroupContext.getServiceContexts();
- while (serviceContecxtes.hasNext()) {
- ServiceContext serviceContext = (ServiceContext) serviceContecxtes.next();
- try {
- DependencyManager.destroyServiceClass(serviceContext);
- } catch (AxisFault axisFault) {
- LOG.info(axisFault.getMessage());
- }
- }
- }
-
protected void logIOException(final IOException ex) {
if (ex instanceof SocketTimeoutException) {
LOG.debug(ex.getMessage());
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpFactory.java?rev=414724&r1=414723&r2=414724&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpFactory.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpFactory.java Thu Jun 15 19:30:47 2006
@@ -244,8 +244,12 @@
}
/** Create a request service processor to populate the response */
- public HttpServiceProcessor newRequestServiceProcessor(HttpServerConnection connection, Worker worker, IOProcessorCallback callback) {
- return new DefaultHttpServiceProcessor(connection, configurationContext, worker, callback);
+ public HttpServiceProcessor newRequestServiceProcessor(
+ final HttpServerConnection connection,
+ final SessionManager sessionManager,
+ final Worker worker,
+ final IOProcessorCallback callback) {
+ return new DefaultHttpServiceProcessor(connection, configurationContext, sessionManager, worker, callback);
}
// *****
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpUtils.java?rev=414724&r1=414723&r2=414724&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpUtils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpUtils.java Thu Jun 15 19:30:47 2006
@@ -41,21 +41,6 @@
private HttpUtils() {
}
- public static String getCookieID(final HttpRequest request) {
- if (request == null) {
- return null;
- }
- Header header = request.getFirstHeader(HTTPConstants.HEADER_COOKIE);
- if (header == null) {
- header = request.getFirstHeader(HTTPConstants.HEADER_COOKIE2);
- }
- if (header == null) {
- return null;
- } else {
- return header.getValue();
- }
- }
-
public static String getSoapAction(final HttpRequest request) {
if (request == null) {
return null;
Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestSessionCookie.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestSessionCookie.java?rev=414724&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestSessionCookie.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestSessionCookie.java Thu Jun 15 19:30:47 2006
@@ -0,0 +1,65 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.http.Header;
+import org.apache.http.HeaderElement;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.protocol.HttpContext;
+
+public class RequestSessionCookie implements HttpRequestInterceptor {
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+
+ String sessionCookie = null;
+ Header header = request.getFirstHeader(HTTPConstants.HEADER_COOKIE);
+ if (header != null) {
+ HeaderElement[] elements = header.getElements();
+ if (elements.length > 0) {
+ sessionCookie = elements[0].getName();
+ }
+ }
+ context.setAttribute(Constants.COOKIE_STRING, sessionCookie);
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseSessionCookie.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseSessionCookie.java?rev=414724&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseSessionCookie.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseSessionCookie.java Thu Jun 15 19:30:47 2006
@@ -0,0 +1,79 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.io.CharArrayBuffer;
+import org.apache.http.protocol.HttpContext;
+
+public class ResponseSessionCookie implements HttpResponseInterceptor {
+
+ public void process(final HttpResponse response, final HttpContext context)
+ throws HttpException, IOException {
+ if (response == null) {
+ throw new IllegalArgumentException("HTTP response may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+
+ String sessionCookie = null;
+ MessageContext msgctx = (MessageContext) context.getAttribute(AxisParams.MESSAGE_CONTEXT);
+ if (msgctx != null) {
+ sessionCookie = (String) msgctx.getProperty(Constants.COOKIE_STRING);
+ }
+ if (sessionCookie == null) {
+ sessionCookie = (String) context.getAttribute(Constants.COOKIE_STRING);
+ }
+ if (sessionCookie != null) {
+ response.addHeader(new Header(HTTPConstants.HEADER_SET_COOKIE, sessionCookie));
+ CharArrayBuffer buffer = new CharArrayBuffer(sessionCookie.length() + 40);
+ buffer.append(sessionCookie);
+ buffer.append("; ");
+ int port = response.getParams().getIntParameter(AxisParams.LISTENER_PORT, 0);
+ if (port > 0) {
+ buffer.append("Port=\"");
+ buffer.append(Integer.toString(port));
+ buffer.append("\"; ");
+ }
+ buffer.append("Version=1");
+ response.addHeader(new Header(HTTPConstants.HEADER_SET_COOKIE2, buffer.toString()));
+ }
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SessionManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SessionManager.java?rev=414724&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SessionManager.java (added)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SessionManager.java Thu Jun 15 19:30:47 2006
@@ -0,0 +1,102 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.context.SessionContext;
+import org.apache.axis2.engine.DependencyManager;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SessionManager {
+
+ private static final Log LOG = LogFactory.getLog(SessionManager.class);
+
+ private final Map sessionmap;
+
+ public SessionManager() {
+ super();
+ this.sessionmap = new HashMap();
+ }
+
+ public synchronized SessionContext getSessionContext(String sessionKey) {
+ SessionContext sessionContext = null;
+ if (sessionKey != null && !sessionKey.equals("")) {
+ sessionContext = (SessionContext) this.sessionmap.get(sessionKey);
+ }
+ if (sessionContext == null) {
+ sessionKey = UUIDGenerator.getUUID();
+ sessionContext = new SessionContext(null);
+ sessionContext.setCookieID(sessionKey);
+ this.sessionmap.put(sessionKey, sessionContext);
+ }
+ sessionContext.touch();
+ cleanupServiceGroupContexts();
+ return sessionContext;
+ }
+
+ private void cleanupServiceGroupContexts() {
+ long currentTime = System.currentTimeMillis();
+ for (Iterator it = this.sessionmap.keySet().iterator(); it.hasNext(); ) {
+ String cookieID = (String) it.next();
+ SessionContext sessionContext = (SessionContext) this.sessionmap.get(cookieID);
+ if ((currentTime - sessionContext.getLastTouchedTime()) >
+ sessionContext.sessionContextTimeoutInterval) {
+ it.remove();
+ Iterator serviceGroupContext = sessionContext.getServiceGroupContext();
+ if (serviceGroupContext != null) {
+ while (serviceGroupContext.hasNext()) {
+ ServiceGroupContext groupContext = (ServiceGroupContext) serviceGroupContext.next();
+ cleanupServiceContextes(groupContext);
+ }
+ }
+ }
+ }
+ }
+
+ private void cleanupServiceContextes(final ServiceGroupContext serviceGroupContext) {
+ for (Iterator it = serviceGroupContext.getServiceContexts(); it.hasNext(); ) {
+ ServiceContext serviceContext = (ServiceContext) it.next();
+ try {
+ DependencyManager.destroyServiceClass(serviceContext);
+ } catch (AxisFault axisFault) {
+ LOG.info(axisFault.getMessage());
+ }
+ }
+ }
+
+}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java?rev=414724&r1=414723&r2=414724&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java Thu Jun 15 19:30:47 2006
@@ -69,6 +69,7 @@
this.port = port;
this.workerFactory = httpFactory.newRequestWorkerFactory();
this.params = httpFactory.newRequestConnectionParams();
+ this.params.setIntParameter(AxisParams.LISTENER_PORT, port);
}
public void init() throws IOException {
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org