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/12/16 18:18:08 UTC
svn commit: r357187 [17/25] - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: ./
addressing/ client/ client/async/ context/ deployment/ deployment/listener/
deployment/repository/util/ deployment/scheduler/ deployment/util/
descript...
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?rev=357187&r1=357186&r2=357187&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 Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.
+*/
+
package org.apache.axis2.transport.http;
@@ -45,26 +46,25 @@
* you want bad things to happen at shutdown.
*/
public class SimpleHTTPServer extends TransportListener {
+
/**
* Field log
*/
protected Log log = LogFactory.getLog(SimpleHTTPServer.class.getName());
/**
- * Field systemContext
- */
- protected ConfigurationContext configurationContext;
-
- /**
* Embedded commons http client based server
*/
SimpleHttpServer embedded = null;
-
int port = -1;
-
private ThreadFactory threadPool = null;
/**
+ * Field systemContext
+ */
+ protected ConfigurationContext configurationContext;
+
+ /**
* Constructor SimpleHTTPServer
*/
public SimpleHTTPServer() {
@@ -75,62 +75,66 @@
*
* @param systemContext
*/
- public SimpleHTTPServer(ConfigurationContext systemContext,
- int port) throws IOException {
- this(systemContext, port, null);
- }
-
- /**
- * Constructor SimpleHTTPServer
- *
- * @param systemContext
- * @param pool
- */
- public SimpleHTTPServer(ConfigurationContext systemContext, int port,
- ThreadFactory pool) throws IOException {
- // If a threadPool is not passed-in the threadpool
- // from the ConfigurationContext
- // is used. This is a bit tricky, and might cause a
- // thread lock. So use with
- // caution
- if (pool == null) {
- pool = systemContext.getThreadPool();
- }
- this.configurationContext = systemContext;
- this.port = port;
- this.threadPool = pool;
- }
-
+ public SimpleHTTPServer(ConfigurationContext systemContext, int port) throws IOException {
+ this(systemContext, port, null);
+ }
/**
- * Constructor SimpleHTTPServer
- *
- * @param dir
- * @throws AxisFault
- */
+ * Constructor SimpleHTTPServer
+ *
+ * @param dir
+ * @throws AxisFault
+ */
public SimpleHTTPServer(String dir, int port) throws AxisFault {
- this(dir, port, null);
+ this(dir, port, null);
}
+
/**
- * Constructor SimpleHTTPServer
- *
- * @param dir
- * @param pool
- * @throws AxisFault
- */
- public SimpleHTTPServer(String dir, int port,
- ThreadFactory pool) throws AxisFault {
+ * Constructor SimpleHTTPServer
+ *
+ * @param systemContext
+ * @param pool
+ */
+ public SimpleHTTPServer(ConfigurationContext systemContext, int port, ThreadFactory pool)
+ throws IOException {
+
+ // If a threadPool is not passed-in the threadpool
+ // from the ConfigurationContext
+ // is used. This is a bit tricky, and might cause a
+ // thread lock. So use with
+ // caution
+ if (pool == null) {
+ pool = systemContext.getThreadPool();
+ }
+
+ this.configurationContext = systemContext;
+ this.port = port;
+ this.threadPool = pool;
+ }
+
+ /**
+ * Constructor SimpleHTTPServer
+ *
+ * @param dir
+ * @param pool
+ * @throws AxisFault
+ */
+ public SimpleHTTPServer(String dir, int port, ThreadFactory pool) throws AxisFault {
try {
this.port = port;
+
ConfigurationContextFactory erfac = new ConfigurationContextFactory();
+
this.configurationContext = erfac.buildConfigurationContext(dir);
+
// If a thread pool is not passed the thread pool from the config context
// is used. If one is passed it is set on the config context.
- if (pool==null){
- pool = this.configurationContext.getThreadPool();
- } else {
- this.configurationContext.setThreadPool(pool);
- }
+ if (pool == null) {
+ pool = this.configurationContext.getThreadPool();
+ } else {
+ this.configurationContext.setThreadPool(pool);
+ }
+
this.threadPool = pool;
Thread.sleep(2000);
} catch (Exception e1) {
@@ -139,15 +143,54 @@
}
/**
- * Checks if this HTTP server instance is running.
+ * init method in TransportListener
*
- * @return true/false
+ * @param axisConf
+ * @param transprtIn
+ * @throws AxisFault
*/
- public boolean isRunning() {
- if(embedded == null) {
- return false;
+ public void init(ConfigurationContext axisConf, TransportInDescription transprtIn)
+ throws AxisFault {
+ 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);
+ }
+ }
+
+ /**
+ * Method main
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ if (args.length != 2) {
+ System.out.println("SimpleHTTPServer repositoryLocation port");
+ System.exit(1);
+ }
+
+ 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());
+
+ try {
+ System.out.println("[Axis2] Using the Repository "
+ + new File(args[0]).getAbsolutePath());
+ System.out.println("[Axis2] Starting the SimpleHTTPServer on port " + args[1]);
+ receiver.start();
+ System.out.println("[Axis2] SimpleHTTPServer started");
+ System.in.read();
+ } finally {
+ receiver.stop();
}
- return embedded.isRunning();
}
/**
@@ -155,11 +198,12 @@
*
* @throws Throwable
*/
- //todo : Deepal , this is not the properway to handle , pls fix
-// protected void finalize() throws Throwable {
-// stop();
-// super.finalize();
-// }
+
+ // todo : Deepal , this is not the properway to handle , pls fix
+ // protected void finalize() throws Throwable {
+ // stop();
+ // super.finalize();
+ // }
/**
* Start this server as a NON-daemon.
@@ -170,6 +214,7 @@
embedded.setRequestHandler(new HTTPWorker(configurationContext));
} catch (IOException e) {
log.error(e);
+
throw new AxisFault(e);
}
}
@@ -181,9 +226,11 @@
*/
public void stop() {
log.info("stop called");
- if(embedded != null) {
+
+ if (embedded != null) {
embedded.destroy();
}
+
log.info("Simple Axis Server Quits");
}
@@ -197,32 +244,42 @@
}
/**
- * Method main
+ * Returns the ip address to be used for the replyto epr
+ * CAUTION:
+ * This will simply go though the list of available network
+ * interfaces and will return the final address of the final interface
+ * available in the list. This workes fine for the simple cases where
+ * 1.) there's only the loopback interface, where the ip is 127.0.0.1
+ * 2.) there's an additional interface availbale which is used to
+ * access an external network and has only one ip assigned to it.
+ * <p/>
+ * TODO:
+ * - Improve this logic to genaralize it a bit more
+ * - Obtain the ip to be used here from the Call API
*
- * @param args
- * @throws Exception
+ * @return
+ * @throws AxisFault
*/
- public static void main(String[] args) throws Exception {
- if (args.length != 2) {
- System.out.println("SimpleHTTPServer repositoryLocation port");
- System.exit(1);
- }
- 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());
+ private String getIpAddress() throws AxisFault {
try {
- System.out.println(
- "[Axis2] Using the Repository " +
- new File(args[0]).getAbsolutePath());
- System.out.println(
- "[Axis2] Starting the SimpleHTTPServer on port " + args[1]);
- receiver.start();
- System.out.println("[Axis2] SimpleHTTPServer started");
- System.in.read();
- } finally {
- receiver.stop();
+ Enumeration e = NetworkInterface.getNetworkInterfaces();
+ String address = null;
+
+ while (e.hasMoreElements()) {
+ NetworkInterface netface = (NetworkInterface) e.nextElement();
+ Enumeration addresses = netface.getInetAddresses();
+
+ while (addresses.hasMoreElements()) {
+ InetAddress ip = (InetAddress) addresses.nextElement();
+
+ // the last available ip address will be returned
+ address = ip.getHostAddress();
+ }
+ }
+
+ return address;
+ } catch (SocketException e) {
+ throw new AxisFault(e);
}
}
@@ -231,71 +288,25 @@
*
* @param serviceName
* @return an EndpointReference
- *
- * @see org.apache.axis2.transport.TransportListener#getReplyToEPR(java.lang.String)
+ * @see org.apache.axis2.transport.TransportListener#getReplyToEPR(String)
*/
public EndpointReference getReplyToEPR(String serviceName) throws AxisFault {
String hostAddress = getIpAddress();
-
- return new EndpointReference("http://"+ hostAddress + ":" + (embedded.getLocalPort()) +
- "/axis2/services/" +
- serviceName);
- }
- /**
- * Returns the ip address to be used for the replyto epr
- * CAUTION:
- * This will simply go though the list of available network
- * interfaces and will return the final address of the final interface
- * available in the list. This workes fine for the simple cases where
- * 1.) there's only the loopback interface, where the ip is 127.0.0.1
- * 2.) there's an additional interface availbale which is used to
- * access an external network and has only one ip assigned to it.
- *
- * TODO:
- * - Improve this logic to genaralize it a bit more
- * - Obtain the ip to be used here from the Call API
- * @return
- * @throws AxisFault
- */
- private String getIpAddress() throws AxisFault {
- try {
- Enumeration e = NetworkInterface.getNetworkInterfaces();
+ return new EndpointReference("http://" + hostAddress + ":" + (embedded.getLocalPort())
+ + "/axis2/services/" + serviceName);
+ }
- String address = null;
- while (e.hasMoreElements()) {
- NetworkInterface netface = (NetworkInterface) e.nextElement();
- Enumeration addresses = netface.getInetAddresses();
- while (addresses.hasMoreElements()) {
- InetAddress ip = (InetAddress) addresses.nextElement();
- //the last available ip address will be returned
- address = ip.getHostAddress();
- }
- }
- return address;
- } catch (SocketException e) {
- throw new AxisFault(e);
- }
- }
-
/**
- * init method in TransportListener
+ * Checks if this HTTP server instance is running.
*
- * @param axisConf
- * @param transprtIn
- * @throws AxisFault
+ * @return true/false
*/
- public void init(ConfigurationContext axisConf,
- TransportInDescription transprtIn)
- throws AxisFault {
- 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);
+ public boolean isRunning() {
+ if (embedded == null) {
+ return false;
}
+
+ return embedded.isRunning();
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AdminAppException.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AdminAppException.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AdminAppException.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AdminAppException.java Fri Dec 16 09:13:57 2005
@@ -1,23 +1,23 @@
/*
- * Copyright 2004,2005 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.
- */
+* Copyright 2004,2005 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.
+*/
-package org.apache.axis2.transport.http.server;
-public class AdminAppException extends Exception{
+package org.apache.axis2.transport.http.server;
+public class AdminAppException extends Exception {
public AdminAppException() {
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/AuthRequestHandler.java Fri Dec 16 09:13:57 2005
@@ -1,31 +1,32 @@
/*
- * $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/>.
- *
- */
+* $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;
@@ -43,27 +44,37 @@
* authentication handshake if necessary.
*/
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";
+ private Credentials credentials = null;
+ private String realm = null;
+ private boolean keepalive = true;
+
+ public AuthRequestHandler(final Credentials creds) {
+ this(creds, null, true);
+ }
+
+ public AuthRequestHandler(final Credentials creds, final String realm) {
+ this(creds, realm, true);
+ }
/**
* 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)
+ if (creds == null) {
throw new IllegalArgumentException("Credentials may not be null");
+ }
+
this.credentials = creds;
this.keepalive = keepalive;
+
if (realm != null) {
this.realm = realm;
} else {
@@ -71,43 +82,35 @@
}
}
- 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;
- }
+ /**
+ * Checks if the credentials provided by the client match the required
+ * credentials
+ *
+ * @param clientAuth
+ * @return true if the client is authorized, false if not.
+ */
+ private boolean checkAuthorization(final Header clientAuth) {
+ String expectedAuthString =
+ BasicScheme.authenticate((UsernamePasswordCredentials) credentials, "ISO-8859-1");
+
+ return expectedAuthString.equals(clientAuth.getValue());
}
- //TODO add more auth schemes
- private SimpleResponse performBasicHandshake(
- final SimpleHttpServerConnection conn,
- final SimpleRequest request) throws IOException
- {
+ // 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(),
+
+ 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);
@@ -115,21 +118,25 @@
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());
- }
+ 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;
+ }
+ }
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ErrorResponse.java Fri Dec 16 09:13:57 2005
@@ -1,33 +1,34 @@
/*
- * $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]
- *
- */
+* $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;
@@ -41,30 +42,33 @@
* Default error responses.
*/
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);
+ 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;
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandler.java Fri Dec 16 09:13:57 2005
@@ -1,33 +1,34 @@
/*
- * $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]
- *
- */
+* $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;
@@ -37,26 +38,27 @@
* Defines an HTTP request handler for the SimpleHttpServer
*/
public interface HttpRequestHandler {
+
/**
* The request handler is asked to process this request.
- *
+ * <p/>
* If it is not capable/interested in processing it, this call should
* be simply ignored.
- *
+ * <p/>
* 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.
- *
+ * <p/>
* 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.
+ *
+ * @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;
+ public boolean processRequest(final SimpleHttpServerConnection conn,
+ final SimpleRequest request)
+ throws IOException;
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpRequestHandlerChain.java Fri Dec 16 09:13:57 2005
@@ -1,33 +1,34 @@
/*
- * $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]
- *
- */
+* $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;
@@ -39,50 +40,51 @@
/**
* Maintains a chain of {@link HttpRequestHandler}s where new request-handlers
* can be prepended/appended.
- *
+ * <p/>
* 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.
*/
public class HttpRequestHandlerChain implements HttpRequestHandler {
-
private List subhandlers = new ArrayList();
-
+
+ public HttpRequestHandlerChain() {
+ super();
+ }
+
public HttpRequestHandlerChain(final HttpRequestHandlerChain chain) {
super();
+
if (chain != null) {
this.subhandlers.clear();
this.subhandlers.addAll(chain.subhandlers);
}
}
-
- public HttpRequestHandlerChain() {
- super();
+
+ public synchronized void appendHandler(HttpRequestHandler handler) {
+ subhandlers.add(handler);
}
-
+
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);
+ subhandlers.add(0, 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();
+ 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;
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpService.java Fri Dec 16 09:13:57 2005
@@ -1,33 +1,34 @@
/*
- * $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]
- *
- */
+* $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;
@@ -37,16 +38,15 @@
* Defines an HTTP request/response service for the SimpleHttpServer
*/
public interface HttpService {
+
/**
* This interface represents a serice to process HTTP requests.
- *
- * @param request The HTTP request object.
- * @param response The HTTP response object.
+ *
+ * @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)
+ public boolean process(final SimpleRequest request, final SimpleResponse response)
throws IOException;
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/HttpServiceHandler.java Fri Dec 16 09:13:57 2005
@@ -1,31 +1,32 @@
/*
- * $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/>.
- *
- */
+* $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;
@@ -39,75 +40,92 @@
* This request handler provides service interface similar to that of Servlet API.
*/
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 {
+
+ 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")) {
+ 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 "
+ throw new IOException("Chunked encoding not supported for HTTP version "
+ response.getHttpVersion());
}
- Header header = new Header("Transfer-Encoding", "chunked");
- response.addHeader(header);
+
+ Header header = new Header("Transfer-Encoding", "chunked");
+
+ response.addHeader(header);
} else {
- Header header = new Header("Content-Length", Long.toString(len));
+ Header header = new Header("Content-Length", Long.toString(len));
+
response.setHeader(header);
}
} else {
- Header header = new Header("Content-Length", "0");
+ 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");
+ Header header = new Header("Connection", "keep-alive");
+
response.addHeader(header);
conn.setKeepAlive(true);
}
+
if (connheader.getValue().equalsIgnoreCase("close")) {
- Header header = new Header("Connection", "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);
@@ -116,12 +134,15 @@
}
}
}
+
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;
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyAuthRequestHandler.java Fri Dec 16 09:13:57 2005
@@ -1,31 +1,32 @@
/*
- * $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/>.
- *
- */
+* $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;
@@ -44,26 +45,36 @@
*/
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";
+ private Credentials credentials = null;
+ private String realm = null;
+ private boolean keepalive = true;
+
+ public ProxyAuthRequestHandler(final Credentials creds) {
+ this(creds, null, true);
+ }
+
+ public ProxyAuthRequestHandler(final Credentials creds, final String realm) {
+ this(creds, realm, true);
+ }
/**
* 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)
+ if (creds == null) {
throw new IllegalArgumentException("Credentials may not be null");
+ }
+
this.credentials = creds;
this.keepalive = keepalive;
+
if (realm != null) {
this.realm = realm;
} else {
@@ -71,43 +82,34 @@
}
}
- public ProxyAuthRequestHandler(final Credentials creds, final String realm) {
- this(creds, realm, true);
- }
-
- public ProxyAuthRequestHandler(final Credentials creds) {
- this(creds, null, true);
- }
+ /**
+ * Checks if the credentials provided by the client match the required
+ * credentials
+ *
+ * @param clientAuth
+ * @return true if the client is authorized, false if not.
+ */
+ private boolean checkAuthorization(Header clientAuth) {
+ String expectedAuthString =
+ BasicScheme.authenticate((UsernamePasswordCredentials) credentials, "ISO-8859-1");
- 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;
- }
+ return expectedAuthString.equals(clientAuth.getValue());
}
- //TODO add more auth schemes
- private SimpleResponse performBasicHandshake(
- final SimpleHttpServerConnection conn,
- final SimpleRequest request) {
-
+ // TODO add more auth schemes
+ private SimpleResponse performBasicHandshake(final SimpleHttpServerConnection conn,
+ final SimpleRequest request) {
SimpleResponse response = new SimpleResponse();
- response.setStatusLine(
- request.getRequestLine().getHttpVersion(),
+
+ 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);
@@ -115,21 +117,25 @@
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());
- }
+ 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;
+ }
+ }
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ProxyRequestHandler.java Fri Dec 16 09:13:57 2005
@@ -1,31 +1,32 @@
/*
- * $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/>.
- *
- */
+* $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;
@@ -42,88 +43,91 @@
import java.net.UnknownHostException;
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 {
+ 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());
+ 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();
+ 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);
@@ -131,6 +135,7 @@
response.removeHeaders("Connection");
}
} else {
+
// Use protocol default connection policy
if (response.getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
conn.setKeepAlive(true);
@@ -140,14 +145,17 @@
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);
+ conn.writeResponse(response);
} catch (HttpException e) {
SimpleResponse response = ErrorResponse.getResponse(HttpStatus.SC_BAD_REQUEST);
+
conn.writeResponse(response);
proxyconn.setKeepAlive(false);
} catch (IOException e) {
@@ -156,6 +164,16 @@
} finally {
this.connmanager.releaseConnection(host, proxyconn);
}
- }
-
-}
\ No newline at end of file
+ }
+
+ /**
+ * @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;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/RequestLine.java Fri Dec 16 09:13:57 2005
@@ -1,33 +1,34 @@
/*
- * $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]
- *
- */
+* $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;
@@ -43,67 +44,74 @@
* Instances of this class are immutable.
*/
public class RequestLine {
-
private HttpVersion httpversion = null;
private String method = null;
- private String uri= null;
+ private String uri = null;
+
+ 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 static RequestLine parseLine(final String l)
- throws HttpException {
+ public RequestLine(final String method, final String uri, final String httpversion)
+ throws ProtocolException {
+ this(method, uri, HttpVersion.parse(httpversion));
+ }
+
+ 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);
+ 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 toString() {
+ StringBuffer sb = new StringBuffer();
- public String getMethod() {
- return this.method;
+ sb.append(this.method);
+ sb.append(" ");
+ sb.append(this.uri);
+ sb.append(" ");
+ sb.append(this.httpversion);
+
+ return sb.toString();
}
public HttpVersion getHttpVersion() {
return this.httpversion;
}
- public String getUri() {
- return this.uri;
+ public String getMethod() {
+ return this.method;
}
- 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();
+ public String getUri() {
+ return this.uri;
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/ResponseWriter.java Fri Dec 16 09:13:57 2005
@@ -1,31 +1,32 @@
/*
- * $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/>.
- *
- */
+* $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;
@@ -45,72 +46,57 @@
private OutputStream outStream = null;
private String encoding = null;
- public ResponseWriter(final OutputStream outStream)
- throws UnsupportedEncodingException {
+ public ResponseWriter(final OutputStream outStream) throws UnsupportedEncodingException {
this(outStream, CRLF, ISO_8859_1);
}
-
- public ResponseWriter(final OutputStream outStream, final String encoding)
- throws UnsupportedEncodingException {
+
+ 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 {
+
+ 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) {
+ if (outStream != null) {
super.close();
outStream = null;
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see java.io.Writer#flush()
*/
public void flush() throws IOException {
- if(outStream != null) {
+ 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(int i) throws IOException {
+ write(Integer.toString(i));
}
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() throws IOException {
+ write(CRLF);
}
-
+
public void println(int i) throws IOException {
write(Integer.toString(i));
write(CRLF);
@@ -120,9 +106,23 @@
print(s);
write(CRLF);
}
-
- public void println() throws IOException {
- write(CRLF);
+
+ 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 String getEncoding() {
+ return encoding;
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleConnList.java Fri Dec 16 09:13:57 2005
@@ -1,31 +1,32 @@
/*
- * $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/>.
- *
- */
+* $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;
@@ -37,9 +38,8 @@
* A simple list of connections.
*/
public class SimpleConnList {
-
private List connections = new ArrayList();
-
+
public SimpleConnList() {
super();
}
@@ -47,24 +47,26 @@
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();
+ public synchronized SimpleHttpServerConnection removeFirst() {
+ int s = this.connections.size();
+
if (s > 0) {
- return (SimpleHttpServerConnection)this.connections.remove(s - 1);
+ return (SimpleHttpServerConnection) this.connections.remove(0);
} else {
return null;
}
}
- public synchronized SimpleHttpServerConnection removeFirst() {
- int s = this.connections.size();
+ public synchronized SimpleHttpServerConnection removeLast() {
+ int s = this.connections.size();
+
if (s > 0) {
- return (SimpleHttpServerConnection)this.connections.remove(0);
+ return (SimpleHttpServerConnection) this.connections.remove(s - 1);
} else {
return null;
}
@@ -73,9 +75,10 @@
public synchronized void shutdown() {
for (Iterator i = this.connections.iterator(); i.hasNext();) {
SimpleHttpServerConnection conn = (SimpleHttpServerConnection) i.next();
+
conn.close();
}
+
this.connections.clear();
}
-
}