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 di...@apache.org on 2005/08/12 22:59:19 UTC
svn commit: r232392 [1/2] - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis2/transport/http/
core/src/org/apache/axis2/transport/http/server/ integration/
integration/src/org/apache/axis2/soap12testing/server/
integration/test/org/apa...
Author: dims
Date: Fri Aug 12 13:59:07 2005
New Revision: 232392
URL: http://svn.apache.org/viewcvs?rev=232392&view=rev
Log:
Checking in a HTTP1.1 capable simple http server based on code in Commons
HTTP Client's test suite (everything under server was borrowed - UNMODIFIED except
for the package name). Am checking in this because i don't want to lose a
working copy :) will clean up during the weekend.
TODO:
- Fix 2 broken tests that i commented out.
- Remove unnecessary files left over from the previous implementation of our http server.
- Need to check ListenerManager stuff. there are comments in there that make me queasy as well.
Added:
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnManager.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnSet.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnectionThread.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHost.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServer.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimplePlainSocketFactory.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleProxy.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleRequest.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleResponse.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleSocketFactory.java (with props)
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/TransparentProxyRequestHandler.java (with props)
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPOutTransportInfo.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
webservices/axis/trunk/java/modules/integration/project.xml
webservices/axis/trunk/java/modules/integration/src/org/apache/axis2/soap12testing/server/SimpleServer.java
webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/integration/UtilServer.java
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=232392&r1=232391&r2=232392&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java Fri Aug 12 13:59:07 2005
@@ -19,6 +19,10 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.transport.http.server.HttpRequestHandler;
+import org.apache.axis2.transport.http.server.SimpleHttpServerConnection;
+import org.apache.axis2.transport.http.server.SimpleRequest;
+import org.apache.axis2.transport.http.server.SimpleResponse;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.TransportOutDescription;
@@ -27,138 +31,138 @@
import org.apache.axis2.util.threadpool.AxisWorker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.Header;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
import java.net.Socket;
import java.util.Map;
+import java.util.HashMap;
+import java.util.Enumeration;
-public class HTTPWorker implements AxisWorker {
+public class HTTPWorker implements HttpRequestHandler {
protected Log log = LogFactory.getLog(getClass().getName());
private ConfigurationContext configurationContext;
- private Socket socket;
- public HTTPWorker(ConfigurationContext configurationContext, Socket socket) {
+ public HTTPWorker(ConfigurationContext configurationContext) {
this.configurationContext = configurationContext;
- this.socket = socket;
}
- public void doWork() {
+ public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
MessageContext msgContext = null;
- SimpleHTTPOutputStream out = null;
+ SimpleResponse response = new SimpleResponse();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
try {
- if (socket != null) {
- if (configurationContext == null) {
- throw new AxisFault(Messages.getMessage("cannotBeNullConfigurationContext"));
- }
+ if (configurationContext == null) {
+ throw new AxisFault(Messages.getMessage("cannotBeNullConfigurationContext"));
+ }
- InputStream inStream = socket.getInputStream();
+ InputStream inStream = request.getBody();
- TransportOutDescription transportOut =
+ TransportOutDescription transportOut =
configurationContext.getAxisConfiguration().getTransportOut(
- new QName(Constants.TRANSPORT_HTTP));
- msgContext =
+ new QName(Constants.TRANSPORT_HTTP));
+ msgContext =
new MessageContext(
- configurationContext,
- configurationContext.getAxisConfiguration().getTransportIn(
- new QName(Constants.TRANSPORT_HTTP)),
- transportOut);
- msgContext.setServerSide(true);
-
-
- //parse the Transport Headers
- HTTPTransportReceiver receiver = new HTTPTransportReceiver();
- Map map = receiver.parseTheHeaders(inStream, true);
-
- //build a way to write the respone if the Axis choose to do so
- String httpVersion = (String)map.get(HTTPConstants.PROTOCOL_VERSION);
- if(httpVersion == null){
- throw new AxisFault("HTTP version can not be Null");
- }
- if(HTTPConstants.HEADER_PROTOCOL_10.equals(httpVersion)){
- httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
- }else if(HTTPConstants.HEADER_PROTOCOL_11.equals(httpVersion)){
- httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
- }else{
- throw new AxisFault("Unknown protocol version "+ httpVersion);
- }
-
- String transferEncoding = (String) map.get(HTTPConstants.HEADER_TRANSFER_ENCODING);
- if (transferEncoding != null
- && HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding)) {
- inStream = new ChunkedInputStream(inStream);
- out = new SimpleHTTPOutputStream(socket.getOutputStream(), true,httpVersion);
- } else {
- out = new SimpleHTTPOutputStream(socket.getOutputStream(), false,httpVersion);
- }
- msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
- //set the transport Headers
- msgContext.setProperty(MessageContext.TRANSPORT_HEADERS,map);
-
- //This is way to provide Accsess to the transport information to the transport Sender
- msgContext.setProperty(
+ configurationContext,
+ configurationContext.getAxisConfiguration().getTransportIn(
+ new QName(Constants.TRANSPORT_HTTP)),
+ transportOut);
+ msgContext.setServerSide(true);
+
+ HttpVersion ver = request.getRequestLine().getHttpVersion();
+ if (ver == null) {
+ throw new AxisFault("HTTP version can not be Null");
+ }
+ String httpVersion = null;
+ if (HttpVersion.HTTP_1_0.equals(ver)) {
+ httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
+ } else if (HttpVersion.HTTP_1_1.equals(ver)) {
+ httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+ } else {
+ throw new AxisFault("Unknown supported protocol version " + ver);
+ }
+
+
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
+
+ //set the transport Headers
+ msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, getHeaders(request));
+
+ //This is way to provide Accsess to the transport information to the transport Sender
+ msgContext.setProperty(
HTTPConstants.HTTPOutTransportInfo,
- new SimpleHTTPOutTransportInfo(out));
+ new SimpleHTTPOutTransportInfo(response));
- if (HTTPConstants.HEADER_GET.equals(map.get(HTTPConstants.HTTP_REQ_TYPE))) {
- //It is GET handle the Get request
- boolean processed =
+ String soapAction = null;
+ if (request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION) != null) {
+ soapAction = request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION).getValue();
+ }
+ if (HTTPConstants.HEADER_GET.equals(request.getRequestLine().getMethod())) {
+ //It is GET handle the Get request
+ boolean processed =
HTTPTransportUtils.processHTTPGetRequest(
- msgContext,
- inStream,
- out,
- (String) map.get(HTTPConstants.HEADER_CONTENT_TYPE),
- (String) map.get(HTTPConstants.HEADER_SOAP_ACTION),
- (String) map.get(HTTPConstants.REQUEST_URI),
- configurationContext,
- HTTPTransportReceiver.getGetRequestParameters(
- (String) map.get(HTTPConstants.REQUEST_URI)));
-
- if (!processed) {
- out.write(
- HTTPTransportReceiver.getServicesHTML(configurationContext).getBytes());
- out.flush();
- }
- } else {
- //It is POST, handle it
- HTTPTransportUtils.processHTTPPostRequest(
+ msgContext,
+ inStream,
+ baos,
+ request.getContentType(),
+ soapAction,
+ request.getRequestLine().getUri(),
+ configurationContext,
+ HTTPTransportReceiver.getGetRequestParameters(
+ request.getRequestLine().getUri()));
+ if (!processed) {
+ response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
+ response.setBodyString(HTTPTransportReceiver.getServicesHTML(configurationContext));
+ conn.writeResponse(response);
+ return true;
+ }
+ } else {
+ //It is POST, handle it
+ HTTPTransportUtils.processHTTPPostRequest(
msgContext,
inStream,
- out,
- (String) map.get(HTTPConstants.HEADER_CONTENT_TYPE),
- (String) map.get(HTTPConstants.HEADER_SOAP_ACTION),
- (String) map.get(HTTPConstants.REQUEST_URI),
+ baos,
+ request.getContentType(),
+ soapAction,
+ request.getRequestLine().getUri(),
configurationContext);
- }
-
- out.finalize();
}
+ response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
+ response.setBody(new ByteArrayInputStream(baos.toByteArray()));
+ conn.writeResponse(response);
} catch (Throwable e) {
try {
AxisEngine engine = new AxisEngine(configurationContext);
if (msgContext != null) {
- msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
- out.setFault(true);
+ response.setStatusLine(request.getRequestLine().getHttpVersion(), 500, "Internal server error");
engine.sendFault(faultContext);
+ response.setBody(new ByteArrayInputStream(baos.toByteArray()));
+ conn.writeResponse(response);
} else {
- log.error(e,e);
+ log.error(e, e);
}
} catch (Exception e1) {
log.error(e1.getMessage(), e1);
}
log.error(e.getMessage(), e);
- } finally {
- if (socket != null) {
- try {
- this.socket.close();
- } catch (IOException e1) {
- log.error(e1);
- }
- }
}
-
+ return true;
}
+ private Map getHeaders(SimpleRequest request) {
+ HashMap headerMap = new HashMap();
+ Header[] headers = request.getHeaders();
+ for (int i = 0; i < headers.length; i++) {
+ headerMap.put(headers[i].getName(), headers[i].getValue());
+ }
+ return headerMap;
+ }
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPOutTransportInfo.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPOutTransportInfo.java?rev=232392&r1=232391&r2=232392&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPOutTransportInfo.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPOutTransportInfo.java Fri Aug 12 13:59:07 2005
@@ -17,14 +17,17 @@
*/
package org.apache.axis2.transport.http;
+import org.apache.axis2.transport.http.server.SimpleResponse;
+import org.apache.commons.httpclient.Header;
+
public class SimpleHTTPOutTransportInfo implements HTTPOutTransportInfo {
- private SimpleHTTPOutputStream outInfo;
+ private SimpleResponse outInfo;
- public SimpleHTTPOutTransportInfo(SimpleHTTPOutputStream outInfo) {
+ public SimpleHTTPOutTransportInfo(SimpleResponse outInfo) {
this.outInfo = outInfo;
}
public void setContentType(String contentType) {
- outInfo.setContentType(contentType);
+ outInfo.setHeader(new Header(HTTPConstants.HEADER_CONTENT_TYPE,contentType));
}
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?rev=232392&r1=232391&r2=232392&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java Fri Aug 12 13:59:07 2005
@@ -17,19 +17,17 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.clientapi.ListenerManager;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.transport.TransportListener;
+import org.apache.axis2.transport.http.server.SimpleHttpServer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;
import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
/**
* This is a simple implementation of an HTTP server for processing
@@ -52,18 +50,15 @@
protected ConfigurationContext configurationContext;
/**
- * Field serverSocket
+ * Embedded commons http client based server
*/
- protected ServerSocket serverSocket;
+ SimpleHttpServer embedded = null;
+
+ int port = -1;
/**
- * are we stopped?
- * latch to true if stop() is called
+ * Constructor SimpleHTTPServer
*/
- private boolean stopped = false;
-
- private int port;
-
public SimpleHTTPServer() {
}
@@ -73,9 +68,9 @@
* @param systemContext
*/
public SimpleHTTPServer(ConfigurationContext systemContext,
- ServerSocket serverSoc) {
+ int port) throws IOException {
this.configurationContext = systemContext;
- this.serverSocket = serverSoc;
+ this.port = port;
}
/**
@@ -84,10 +79,9 @@
* @param dir
* @throws AxisFault
*/
- public SimpleHTTPServer(String dir, ServerSocket serverSoc) throws AxisFault {
+ public SimpleHTTPServer(String dir, int port) throws AxisFault {
try {
- this.serverSocket = serverSoc;
- // Class erClass = Class.forName("org.apache.axis2.deployment.EngineContextFactoryImpl");
+ this.port = port;
ConfigurationContextFactory erfac = new ConfigurationContextFactory();
this.configurationContext = erfac.buildConfigurationContext(dir);
Thread.sleep(2000);
@@ -112,58 +106,29 @@
*/
public void run() {
try {
- while (!stopped) {
- // Accept and process requests from the socket
- Socket socket = null;
- try {
- socket = serverSocket.accept();
- } catch (java.io.InterruptedIOException iie) {
- } catch (Exception e) {
- log.debug(e);
- break;
- }
- if (socket != null) {
- configurationContext.getThreadPool().addWorker(
- new HTTPWorker(configurationContext, socket));
- }
- }
- } catch (AxisFault e) {
+ embedded = new SimpleHttpServer(port);
+ embedded.setRequestHandler(new HTTPWorker(configurationContext));
+ embedded.run();
+ } catch (IOException e) {
log.error(e);
+ throw new RuntimeException(e);
}
- stop();
log.info("Simple Axis Server Quit");
}
/**
- * Obtain the serverSocket that that SimpleAxisServer is listening on.
- *
- * @return
- */
- public ServerSocket getServerSocket() {
- return serverSocket;
- }
-
- /**
- * Set the serverSocket this server should listen on.
- * (note : changing this will not affect a running server, but if you
- * stop() and then start() the server, the new socket will be used).
- *
- * @param serverSocket
- */
- public void setServerSocket(ServerSocket serverSocket) {
- this.serverSocket = serverSocket;
- }
-
- /**
* Start this server as a NON-daemon.
*/
public void start() throws AxisFault {
- if (serverSocket == null) {
- serverSocket = ListenerManager.openSocket(port);
+ try {
+ embedded = new SimpleHttpServer(port);
+ embedded.setRequestHandler(new HTTPWorker(configurationContext));
+ Thread newThread = new Thread(embedded);
+ newThread.start();
+ } catch (IOException e) {
+ log.error(e);
+ throw new AxisFault(e);
}
-
- Thread newThread = new Thread(this);
- newThread.start();
}
/**
@@ -173,35 +138,8 @@
*/
public void stop() {
log.info("stop called");
-
- // recognise use before we are live
- if (stopped) {
- return;
- }
-
- /*
- * Close the server socket cleanly, but avoid fresh accepts while
- * the socket is closing.
- */
- stopped = true;
- try {
- if (serverSocket != null) {
- serverSocket.close();
-
- // while(socket != null){
- // try {
- // //make sure all sockets closed by the time
- // //else we got in to lot of trouble testing
- // Thread.sleep(1000);
- // } catch (InterruptedException e1) {
- // log.error(e1);
- // }
- // }
- }
- } catch (IOException e) {
- log.info(e);
- } finally {
- serverSocket = null;
+ if(embedded != null) {
+ embedded.destroy();
}
log.info("Simple Axis Server Quits");
}
@@ -209,7 +147,7 @@
/**
* Method getSystemContext
*
- * @return
+ * @return the system context
*/
public ConfigurationContext getSystemContext() {
return configurationContext;
@@ -226,14 +164,11 @@
System.out.println("SimpleHTTPServer repositoryLocation port");
System.exit(1);
}
- ServerSocket serverSoc = null;
- serverSoc = new ServerSocket(Integer.parseInt(args[1]));
- SimpleHTTPServer receiver = new SimpleHTTPServer(args[0], serverSoc);
+ SimpleHTTPServer receiver = new SimpleHTTPServer(args[0], Integer.parseInt(args[1]));
System.out.println("starting SimpleHTTPServer in port "
+ args[1]
+ " using the repository "
+ new File(args[0]).getAbsolutePath());
- receiver.setServerSocket(serverSoc);
Thread thread = new Thread(receiver);
thread.setDaemon(true);
try {
@@ -250,23 +185,38 @@
}
}
- /* (non-Javadoc)
+ /**
+ * replyToEPR
+ *
+ * @param serviceName
+ * @return an EndpointReference
+ *
* @see org.apache.axis2.transport.TransportListener#replyToEPR(java.lang.String)
*/
public EndpointReference replyToEPR(String serviceName) {
- return new EndpointReference("http://127.0.0.1:" + (serverSocket.getLocalPort()) +
+ return new EndpointReference("http://127.0.0.1:" + (embedded.getLocalPort()) +
"/axis/services/" +
serviceName);
}
+ /**
+ * init method in TransportListener
+ *
+ * @param axisConf
+ * @param transprtIn
+ * @throws AxisFault
+ */
public void init(ConfigurationContext axisConf,
TransportInDescription transprtIn)
throws AxisFault {
- this.configurationContext = axisConf;
- Parameter param = transprtIn.getParameter(PARAM_PORT);
- if (param != null) {
- this.port = Integer.parseInt((String) param.getValue());
+ try {
+ this.configurationContext = axisConf;
+ Parameter param = transprtIn.getParameter(PARAM_PORT);
+ if (param != null) {
+ this.port = Integer.parseInt((String) param.getValue());
+ }
+ } catch (Exception e1) {
+ throw new AxisFault(e1);
}
}
-
}
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,138 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/AuthRequestHandler.java,v 1.1 2004/11/20 17:56:40 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.BasicScheme;
+
+/**
+ * This request handler guards access to the http server when used in a request handler
+ * chain. It checks the headers for valid credentials and performs the
+ * authentication handshake if necessary.
+ *
+ * @author Ortwin Glueck
+ * @author Oleg Kalnichevski
+ */
+public class AuthRequestHandler implements HttpRequestHandler {
+
+ private Credentials credentials = null;
+ private String realm = null;
+ private boolean keepalive = true;
+
+ /**
+ * The authenticate response header.
+ */
+ public static final String AUTH_RESP = "Authorization";
+
+ /**
+ * TODO replace creds parameter with a class specific to an auth scheme
+ * encapsulating all required information for a specific scheme
+ *
+ * @param creds
+ */
+ public AuthRequestHandler(final Credentials creds, final String realm, boolean keepalive) {
+ if (creds == null)
+ throw new IllegalArgumentException("Credentials may not be null");
+ this.credentials = creds;
+ this.keepalive = keepalive;
+ if (realm != null) {
+ this.realm = realm;
+ } else {
+ this.realm = "test";
+ }
+ }
+
+ public AuthRequestHandler(final Credentials creds, final String realm) {
+ this(creds, realm, true);
+ }
+
+ public AuthRequestHandler(final Credentials creds) {
+ this(creds, null, true);
+ }
+
+ public boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException
+ {
+ Header clientAuth = request.getFirstHeader(AUTH_RESP);
+ if (clientAuth != null && checkAuthorization(clientAuth)) {
+ return false;
+ } else {
+ SimpleResponse response = performBasicHandshake(conn, request);
+ // Make sure the request body is fully consumed
+ request.getBodyBytes();
+ conn.writeResponse(response);
+ return true;
+ }
+ }
+
+ //TODO add more auth schemes
+ private SimpleResponse performBasicHandshake(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException
+ {
+ SimpleResponse response = new SimpleResponse();
+ response.setStatusLine(
+ request.getRequestLine().getHttpVersion(),
+ HttpStatus.SC_UNAUTHORIZED);
+ if (!request.getRequestLine().getMethod().equalsIgnoreCase("HEAD")) {
+ response.setBodyString("unauthorized");
+ }
+ response.addHeader(new Header("WWW-Authenticate", "basic realm=\"" + this.realm + "\""));
+ if (this.keepalive) {
+ response.addHeader(new Header("Connection", "keep-alive"));
+ conn.setKeepAlive(true);
+ } else {
+ response.addHeader(new Header("Connection", "close"));
+ conn.setKeepAlive(false);
+ }
+ return response;
+ }
+
+ /**
+ * Checks if the credentials provided by the client match the required
+ * credentials
+ *
+ * @return true if the client is authorized, false if not.
+ * @param clientAuth
+ */
+ private boolean checkAuthorization(final Header clientAuth) {
+ String expectedAuthString = BasicScheme.authenticate(
+ (UsernamePasswordCredentials)credentials,
+ "ISO-8859-1");
+ return expectedAuthString.equals(clientAuth.getValue());
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,72 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/ErrorResponse.java,v 1.6 2004/11/13 12:21:28 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.util.HashMap;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpVersion;
+
+/**
+ * Default error responses.
+ *
+ * @author Christian Kohlschuetter
+ */
+public class ErrorResponse {
+
+ private static final HashMap responses = new HashMap();
+
+ private ErrorResponse() {
+ super();
+ }
+
+ public static SimpleResponse getResponse(int statusCode) {
+ Integer code = new Integer(statusCode);
+ SimpleResponse response = (SimpleResponse)responses.get(code);
+ if (response == null) {
+ response = new SimpleResponse();
+ response.setStatusLine(HttpVersion.HTTP_1_0, statusCode);
+ response.setHeader(new Header("Content-Type", "text/plain; charset=US-ASCII"));
+
+ String s = HttpStatus.getStatusText(statusCode);
+ if (s == null) {
+ s = "Error " + statusCode;
+ }
+ response.setBodyString(s);
+ response.addHeader(new Header("Connection", "close"));
+ response.addHeader(new Header("Content-Length", Integer.toString(s.length())));
+ responses.put(code, response);
+ }
+ return response;
+ }
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,65 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/HttpRequestHandler.java,v 1.4 2004/02/27 19:01:33 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+
+/**
+ * Defines an HTTP request handler for the SimpleHttpServer
+ *
+ * @author Christian Kohlschuetter
+ * @author Oleg Kalnichevski
+ */
+public interface HttpRequestHandler {
+ /**
+ * The request handler is asked to process this request.
+ *
+ * If it is not capable/interested in processing it, this call should
+ * be simply ignored.
+ *
+ * Any modification of the output stream (via <code>conn.getWriter()</code>)
+ * by this request handler will stop the execution chain and return the output
+ * to the client.
+ *
+ * The handler may also rewrite the request parameters (this is useful in
+ * {@link HttpRequestHandlerChain} structures).
+ *
+ * @param conn The Connection object to which this request belongs to.
+ * @param request The request object.
+ * @return true if this handler handled the request and no other handlers in the
+ * chain should be called, false otherwise.
+ * @throws IOException
+ */
+ public boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException;
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,90 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/HttpRequestHandlerChain.java,v 1.6 2004/11/28 15:44:39 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Maintains a chain of {@link HttpRequestHandler}s where new request-handlers
+ * can be prepended/appended.
+ *
+ * For each call to {@link #processRequest(ResponseWriter,SimpleHttpServerConnection,RequestLine,Header[])}
+ * we iterate over the chain from the start to the end, stopping as soon as a handler
+ * has claimed the output.
+ *
+ * @author Christian Kohlschuetter
+ */
+public class HttpRequestHandlerChain implements HttpRequestHandler {
+
+ private List subhandlers = new ArrayList();
+
+ public HttpRequestHandlerChain(final HttpRequestHandlerChain chain) {
+ super();
+ if (chain != null) {
+ this.subhandlers.clear();
+ this.subhandlers.addAll(chain.subhandlers);
+ }
+ }
+
+ public HttpRequestHandlerChain() {
+ super();
+ }
+
+ public synchronized void clear() {
+ subhandlers.clear();
+ }
+
+ public synchronized void prependHandler(HttpRequestHandler handler) {
+ subhandlers.add(0,handler);
+ }
+
+ public synchronized void appendHandler(HttpRequestHandler handler) {
+ subhandlers.add(handler);
+ }
+
+ public synchronized boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException
+ {
+ for(Iterator it=subhandlers.iterator();it.hasNext();) {
+ HttpRequestHandler h = (HttpRequestHandler)it.next();
+ boolean stop = h.processRequest(conn, request);
+ if (stop) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,54 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/HttpService.java,v 1.1 2004/02/27 19:04:32 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.io.IOException;
+
+/**
+ * Defines an HTTP request/response service for the SimpleHttpServer
+ *
+ * @author Oleg Kalnichevski
+ */
+public interface HttpService {
+ /**
+ * This interface represents a serice to process HTTP requests.
+ *
+ * @param request The HTTP request object.
+ * @param response The HTTP response object.
+ * @return true if this service was able to handle the request, false otherwise.
+ *
+ * @throws IOException
+ */
+ public boolean process(
+ final SimpleRequest request, final SimpleResponse response)
+ throws IOException;
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,129 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/HttpServiceHandler.java,v 1.9 2004/11/13 22:38:27 mbecke Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpVersion;
+
+/**
+ * This request handler provides service interface similar to that of Servlet API.
+ *
+ * @author Oleg Kalnichevski
+ */
+public class HttpServiceHandler implements HttpRequestHandler {
+
+ private HttpService service = null;
+
+ public HttpServiceHandler(final HttpService service) {
+ super();
+ if (service == null) {
+ throw new IllegalArgumentException("Service may not be null");
+ }
+ this.service = service;
+ }
+
+ public boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException {
+ if (conn == null) {
+ throw new IllegalArgumentException("Connection may not be null");
+ }
+ if (request == null) {
+ throw new IllegalArgumentException("Request may not be null");
+ }
+ boolean complete = false;
+ SimpleResponse response = new SimpleResponse();
+ this.service.process(request, response);
+
+ // Nake sure the request if fully consumed
+ request.getBodyBytes();
+
+ // Ensure there's a content type header
+ if (!response.containsHeader("Content-Type")) {
+ response.addHeader(new Header("Content-Type", "text/plain"));
+ }
+
+ // Ensure there's a content length or transfer encoding header
+ if (!response.containsHeader("Content-Length") && !response.containsHeader("Transfer-Encoding")) {
+ InputStream content = response.getBody();
+ if (content != null) {
+ long len = response.getContentLength();
+ if (len < 0) {
+ if (response.getHttpVersion().lessEquals(HttpVersion.HTTP_1_0)) {
+ throw new IOException("Chunked encoding not supported for HTTP version "
+ + response.getHttpVersion());
+ }
+ Header header = new Header("Transfer-Encoding", "chunked");
+ response.addHeader(header);
+ } else {
+ Header header = new Header("Content-Length", Long.toString(len));
+ response.setHeader(header);
+ }
+ } else {
+ Header header = new Header("Content-Length", "0");
+ response.addHeader(header);
+ }
+ }
+
+ if (!response.containsHeader("Connection")) {
+ // See if the the client explicitly handles connection persistence
+ Header connheader = request.getFirstHeader("Connection");
+ if (connheader != null) {
+ if (connheader.getValue().equalsIgnoreCase("keep-alive")) {
+ Header header = new Header("Connection", "keep-alive");
+ response.addHeader(header);
+ conn.setKeepAlive(true);
+ }
+ if (connheader.getValue().equalsIgnoreCase("close")) {
+ Header header = new Header("Connection", "close");
+ response.addHeader(header);
+ conn.setKeepAlive(false);
+ }
+ } else {
+ // Use protocol default connection policy
+ if (response.getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
+ conn.setKeepAlive(true);
+ } else {
+ conn.setKeepAlive(false);
+ }
+ }
+ }
+ if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
+ // this is a head request, we don't want to send the actualy content
+ response.setBody(null);
+ }
+ conn.writeResponse(response);
+ return true;
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,138 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/ProxyAuthRequestHandler.java,v 1.12 2004/11/28 15:44:39 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.BasicScheme;
+
+/**
+ * This request handler guards access to a proxy when used in a request handler
+ * chain. It checks the headers for valid credentials and performs the
+ * authentication handshake if necessary.
+ *
+ * @author Ortwin Glueck
+ * @author Oleg Kalnichevski
+ */
+public class ProxyAuthRequestHandler implements HttpRequestHandler {
+
+ private Credentials credentials = null;
+ private String realm = null;
+ private boolean keepalive = true;
+
+ /**
+ * The proxy authenticate response header.
+ */
+ public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
+
+ /**
+ * TODO replace creds parameter with a class specific to an auth scheme
+ * encapsulating all required information for a specific scheme
+ *
+ * @param creds
+ */
+ public ProxyAuthRequestHandler(final Credentials creds, final String realm, boolean keepalive) {
+ if (creds == null)
+ throw new IllegalArgumentException("Credentials may not be null");
+ this.credentials = creds;
+ this.keepalive = keepalive;
+ if (realm != null) {
+ this.realm = realm;
+ } else {
+ this.realm = "test";
+ }
+ }
+
+ public ProxyAuthRequestHandler(final Credentials creds, final String realm) {
+ this(creds, realm, true);
+ }
+
+ public ProxyAuthRequestHandler(final Credentials creds) {
+ this(creds, null, true);
+ }
+
+ public boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException
+ {
+ Header clientAuth = request.getFirstHeader(PROXY_AUTH_RESP);
+ if (clientAuth != null && checkAuthorization(clientAuth)) {
+ return false;
+ } else {
+ SimpleResponse response = performBasicHandshake(conn, request);
+ // Make sure the request body is fully consumed
+ request.getBodyBytes();
+ conn.writeResponse(response);
+ return true;
+ }
+ }
+
+ //TODO add more auth schemes
+ private SimpleResponse performBasicHandshake(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) {
+
+ SimpleResponse response = new SimpleResponse();
+ response.setStatusLine(
+ request.getRequestLine().getHttpVersion(),
+ HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED);
+ if (!request.getRequestLine().getMethod().equalsIgnoreCase("HEAD")) {
+ response.setBodyString("unauthorized");
+ }
+ response.addHeader(new Header("Proxy-Authenticate", "basic realm=\"" + this.realm + "\""));
+ if (this.keepalive) {
+ response.addHeader(new Header("Proxy-Connection", "keep-alive"));
+ conn.setKeepAlive(true);
+ } else {
+ response.addHeader(new Header("Proxy-Connection", "close"));
+ conn.setKeepAlive(false);
+ }
+ return response;
+ }
+
+ /**
+ * Checks if the credentials provided by the client match the required
+ * credentials
+ *
+ * @return true if the client is authorized, false if not.
+ * @param clientAuth
+ */
+ private boolean checkAuthorization(Header clientAuth) {
+ String expectedAuthString = BasicScheme.authenticate(
+ (UsernamePasswordCredentials)credentials,
+ "ISO-8859-1");
+ return expectedAuthString.equals(clientAuth.getValue());
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,165 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/ProxyRequestHandler.java,v 1.11 2004/12/11 22:35:26 olegk Exp $
+ * $Revision: 169849 $
+ * $Date: 2005-05-12 13:05:07 -0400 (Thu, 12 May 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Ortwin Glueck
+ * @author Oleg Kalnichevski
+ */
+public class ProxyRequestHandler implements HttpRequestHandler {
+
+ private static final Log LOG = LogFactory.getLog(ProxyRequestHandler.class);
+
+ private SimpleConnManager connmanager = null;
+
+ public ProxyRequestHandler(final SimpleConnManager connmanager) {
+ super();
+ if (connmanager == null) {
+ throw new IllegalArgumentException("Connection manager may not be null");
+ }
+ this.connmanager = connmanager;
+ }
+
+ /**
+ * @see org.apache.commons.httpclient.server.HttpRequestHandler#processRequest(org.apache.commons.httpclient.server.SimpleHttpServerConnection)
+ */
+ public boolean processRequest(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException
+ {
+ httpProxy(conn, request);
+ return true;
+ }
+
+ private void httpProxy(
+ final SimpleHttpServerConnection conn,
+ final SimpleRequest request) throws IOException {
+
+ RequestLine oldreqline = request.getRequestLine();
+ URI uri = null;
+ SimpleHost host = null;
+ try {
+ uri = new URI(oldreqline.getUri(), true);
+ host = new SimpleHost(uri.getHost(), uri.getPort());
+ } catch (URIException ex) {
+ SimpleResponse response = ErrorResponse.getResponse(HttpStatus.SC_BAD_REQUEST);
+ conn.writeResponse(response);
+ return;
+ }
+ SimpleHttpServerConnection proxyconn = null;
+ try {
+ proxyconn = this.connmanager.openConnection(host);
+ } catch (UnknownHostException e) {
+ SimpleResponse response = ErrorResponse.getResponse(HttpStatus.SC_NOT_FOUND);
+ conn.writeResponse(response);
+ return;
+ }
+ try {
+ proxyconn.setSocketTimeout(0);
+ // Rewrite target url
+ RequestLine newreqline = new RequestLine(
+ oldreqline.getMethod(),
+ uri.getEscapedPath(),
+ oldreqline.getHttpVersion());
+ request.setRequestLine(newreqline);
+ // Remove proxy-auth headers if present
+ request.removeHeaders("Proxy-Authorization");
+ // Manage connection persistence
+ Header connheader = request.getFirstHeader("Proxy-Connection");
+ if (connheader != null) {
+ if (connheader.getValue().equalsIgnoreCase("close")) {
+ request.setHeader(new Header("Connection", "close"));
+ }
+ }
+ request.removeHeaders("Proxy-Connection");
+
+ proxyconn.writeRequest(request);
+
+ SimpleResponse response = proxyconn.readResponse();
+ if (response == null) {
+ return;
+ }
+ response.setHeader(new Header("Via", "1.1 test (Test-Proxy)"));
+ connheader = response.getFirstHeader("Connection");
+ if (connheader != null) {
+ String s = connheader.getValue();
+ if (s.equalsIgnoreCase("close")) {
+ response.setHeader(new Header("Proxy-Connection", "close"));
+ conn.setKeepAlive(false);
+ proxyconn.setKeepAlive(false);
+ response.removeHeaders("Connection");
+ }
+ if (s.equalsIgnoreCase("keep-alive")) {
+ response.setHeader(new Header("Proxy-Connection", "keep-alive"));
+ conn.setKeepAlive(true);
+ proxyconn.setKeepAlive(true);
+ response.removeHeaders("Connection");
+ }
+ } else {
+ // Use protocol default connection policy
+ if (response.getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
+ conn.setKeepAlive(true);
+ proxyconn.setKeepAlive(true);
+ } else {
+ conn.setKeepAlive(false);
+ proxyconn.setKeepAlive(false);
+ }
+ }
+ if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
+ // this is a head request, we don't want to send the actualy content
+ response.setBody(null);
+ }
+ conn.writeResponse(response);
+
+ } catch (HttpException e) {
+ SimpleResponse response = ErrorResponse.getResponse(HttpStatus.SC_BAD_REQUEST);
+ conn.writeResponse(response);
+ proxyconn.setKeepAlive(false);
+ } catch (IOException e) {
+ LOG.warn(e.getMessage());
+ proxyconn.setKeepAlive(false);
+ } finally {
+ this.connmanager.releaseConnection(host, proxyconn);
+ }
+ }
+
+}
\ No newline at end of file
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,112 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/RequestLine.java,v 1.4 2004/09/14 15:50:41 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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/>.
+ *
+ * [Additional notices, if required by prior licensing conditions]
+ *
+ */
+
+package org.apache.axis2.transport.http.server;
+
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.ProtocolException;
+
+/**
+ * Defines a HTTP request-line, consisting of method name, URI and protocol.
+ * Instances of this class are immutable.
+ *
+ * @author Christian Kohlschuetter
+ * @author Oleg Kalnichevski
+ */
+public class RequestLine {
+
+ private HttpVersion httpversion = null;
+ private String method = null;
+ private String uri= null;
+
+ public static RequestLine parseLine(final String l)
+ throws HttpException {
+ String method = null;
+ String uri = null;
+ String protocol = null;
+ try {
+ StringTokenizer st = new StringTokenizer(l, " ");
+ method = st.nextToken();
+ uri = st.nextToken();
+ protocol = st.nextToken();
+ } catch (NoSuchElementException e) {
+ throw new ProtocolException("Invalid request line: " + l);
+ }
+ return new RequestLine(method, uri, protocol);
+ }
+
+ public RequestLine(final String method, final String uri, final HttpVersion httpversion) {
+ super();
+ if (method == null) {
+ throw new IllegalArgumentException("Method may not be null");
+ }
+ if (uri == null) {
+ throw new IllegalArgumentException("URI may not be null");
+ }
+ if (httpversion == null) {
+ throw new IllegalArgumentException("HTTP version may not be null");
+ }
+ this.method = method;
+ this.uri = uri;
+ this.httpversion = httpversion;
+ }
+
+ public RequestLine(final String method, final String uri, final String httpversion)
+ throws ProtocolException {
+ this(method, uri, HttpVersion.parse(httpversion));
+ }
+
+ public String getMethod() {
+ return this.method;
+ }
+
+ public HttpVersion getHttpVersion() {
+ return this.httpversion;
+ }
+
+ public String getUri() {
+ return this.uri;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(this.method);
+ sb.append(" ");
+ sb.append(this.uri);
+ sb.append(" ");
+ sb.append(this.httpversion);
+ return sb.toString();
+ }
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,130 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/ResponseWriter.java,v 1.5 2004/11/07 12:31:42 olegk Exp $
+ * $Revision: 155418 $
+ * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.io.BufferedWriter;
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Provides a hybrid Writer/OutputStream for sending HTTP response data
+ *
+ * @author Christian Kohlschuetter
+ */
+public class ResponseWriter extends FilterWriter {
+ public static final String CRLF = "\r\n";
+ public static final String ISO_8859_1 = "ISO-8859-1";
+ private OutputStream outStream = null;
+ private String encoding = null;
+
+ public ResponseWriter(final OutputStream outStream)
+ throws UnsupportedEncodingException {
+ this(outStream, CRLF, ISO_8859_1);
+ }
+
+ public ResponseWriter(final OutputStream outStream, final String encoding)
+ throws UnsupportedEncodingException {
+ this(outStream, CRLF, encoding);
+ }
+
+ public ResponseWriter(
+ final OutputStream outStream,
+ final String lineSeparator,
+ final String encoding) throws UnsupportedEncodingException {
+ super(new BufferedWriter(new OutputStreamWriter(outStream, encoding)));
+ this.outStream = outStream;
+ this.encoding = encoding;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public void close() throws IOException {
+ if(outStream != null) {
+ super.close();
+ outStream = null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#flush()
+ */
+ public void flush() throws IOException {
+ if(outStream != null) {
+ super.flush();
+ outStream.flush();
+ }
+ }
+
+ public void write(byte b) throws IOException {
+ super.flush();
+ outStream.write((int)b);
+ }
+
+ public void write(byte[] b) throws IOException {
+ super.flush();
+ outStream.write(b);
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ super.flush();
+ outStream.write(b,off,len);
+ }
+
+ public void print(String s) throws IOException {
+ if (s == null) {
+ s = "null";
+ }
+ write(s);
+ }
+
+ public void print(int i) throws IOException {
+ write(Integer.toString(i));
+ }
+
+ public void println(int i) throws IOException {
+ write(Integer.toString(i));
+ write(CRLF);
+ }
+
+ public void println(String s) throws IOException {
+ print(s);
+ write(CRLF);
+ }
+
+ public void println() throws IOException {
+ write(CRLF);
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,83 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleConnList.java,v 1.1 2004/11/13 12:21:28 olegk Exp $
+ * $Revision: 224451 $
+ * $Date: 2005-07-23 06:23:59 -0400 (Sat, 23 Jul 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A simple list of connections.
+ *
+ * @author Oleg Kalnichevski
+ */
+public class SimpleConnList {
+
+ private List connections = new ArrayList();
+
+ public SimpleConnList() {
+ super();
+ }
+
+ public synchronized void addConnection(final SimpleHttpServerConnection conn) {
+ this.connections.add(conn);
+ }
+
+ public synchronized void removeConnection(final SimpleHttpServerConnection conn) {
+ this.connections.remove(conn);
+ }
+
+ public synchronized SimpleHttpServerConnection removeLast() {
+ int s = this.connections.size();
+ if (s > 0) {
+ return (SimpleHttpServerConnection)this.connections.remove(s - 1);
+ } else {
+ return null;
+ }
+ }
+
+ public synchronized SimpleHttpServerConnection removeFirst() {
+ int s = this.connections.size();
+ if (s > 0) {
+ return (SimpleHttpServerConnection)this.connections.remove(0);
+ } else {
+ return null;
+ }
+ }
+
+ public synchronized void shutdown() {
+ for (Iterator i = this.connections.iterator(); i.hasNext();) {
+ SimpleHttpServerConnection conn = (SimpleHttpServerConnection) i.next();
+ conn.close();
+ }
+ this.connections.clear();
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnManager.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnManager.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnManager.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnManager.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,100 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleConnManager.java,v 1.2 2004/11/20 17:56:40 olegk Exp $
+ * $Revision: 224451 $
+ * $Date: 2005-07-23 06:23:59 -0400 (Sat, 23 Jul 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * A REALLY simple connection manager.
+ *
+ * @author Oleg Kalnichevski
+ */
+public class SimpleConnManager {
+
+ private Map connsets = new HashMap();
+
+ public SimpleConnManager() {
+ super();
+ }
+
+ public synchronized SimpleHttpServerConnection openConnection(final SimpleHost host)
+ throws IOException {
+ if (host == null) {
+ throw new IllegalArgumentException("Host may not be null");
+ }
+ SimpleHttpServerConnection conn = null;
+ SimpleConnList connlist = (SimpleConnList)this.connsets.get(host);
+ if (connlist != null) {
+ conn = connlist.removeFirst();
+ if (conn != null && !conn.isOpen()) {
+ conn = null;
+ }
+ }
+ if (conn == null) {
+ Socket socket = new Socket(host.getHostName(), host.getPort());
+ conn = new SimpleHttpServerConnection(socket);
+ }
+ return conn;
+ }
+
+ public synchronized void releaseConnection(final SimpleHost host,
+ final SimpleHttpServerConnection conn) throws IOException {
+ if (host == null) {
+ throw new IllegalArgumentException("Host may not be null");
+ }
+ if (conn == null) {
+ return;
+ }
+ if (!conn.isKeepAlive()) {
+ conn.close();
+ }
+ if (conn.isOpen()) {
+ SimpleConnList connlist = (SimpleConnList)this.connsets.get(host);
+ if (connlist == null) {
+ connlist = new SimpleConnList();
+ this.connsets.put(host, connlist);
+ }
+ connlist.addConnection(conn);
+ }
+ }
+
+ public synchronized void shutdown() {
+ for (Iterator i = this.connsets.values().iterator(); i.hasNext();) {
+ SimpleConnList connlist = (SimpleConnList) i.next();
+ connlist.shutdown();
+ }
+ this.connsets.clear();
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnSet.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnSet.java?rev=232392&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnSet.java (added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnSet.java Fri Aug 12 13:59:07 2005
@@ -0,0 +1,64 @@
+/*
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleConnSet.java,v 1.1 2004/11/13 12:21:28 olegk Exp $
+ * $Revision: 224451 $
+ * $Date: 2005-07-23 06:23:59 -0400 (Sat, 23 Jul 2005) $
+ *
+ * ====================================================================
+ *
+ * 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;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A simple set of connections.
+ *
+ * @author Oleg Kalnichevski
+ */
+public class SimpleConnSet {
+
+ private Set connections = new HashSet();
+
+ public SimpleConnSet() {
+ super();
+ }
+
+ public synchronized void addConnection(final SimpleHttpServerConnection conn) {
+ this.connections.add(conn);
+ }
+
+ public synchronized void removeConnection(final SimpleHttpServerConnection conn) {
+ this.connections.remove(conn);
+ }
+
+ public synchronized void shutdown() {
+ for (Iterator i = connections.iterator(); i.hasNext();) {
+ SimpleHttpServerConnection conn = (SimpleHttpServerConnection) i.next();
+ conn.close();
+ }
+ }
+
+}
Propchange: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnSet.java
------------------------------------------------------------------------------
svn:eol-style = native