You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2008/06/24 13:07:10 UTC
svn commit: r671127 [6/8] - in /webservices/axis2/trunk/java: ./
modules/addressing/ modules/clustering/
modules/clustering/test/org/apache/axis2/clustering/ modules/integration/
modules/integration/test-resources/deployment/ modules/integration/test/o...
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class RESTRequestEntity implements RequestEntity {
+ private byte[] bytes;
+ private String charSetEnc;
+ private boolean chunked;
+ private OMElement element;
+ private MessageContext msgCtxt;
+ private String soapActionString;
+ private OMOutputFormat format;
+
+ public RESTRequestEntity(OMElement element, boolean chunked,
+ MessageContext msgCtxt,
+ String charSetEncoding,
+ String soapActionString,
+ OMOutputFormat format) {
+ this.element = element;
+ this.chunked = chunked;
+ this.msgCtxt = msgCtxt;
+ this.charSetEnc = charSetEncoding;
+ this.soapActionString = soapActionString;
+ this.format = format;
+ }
+
+ private void handleOMOutput(OutputStream out, boolean doingMTOM)
+ throws XMLStreamException {
+ format.setDoOptimize(doingMTOM);
+ element.serializeAndConsume(out, format);
+ }
+
+ public byte[] writeBytes() throws AxisFault {
+ try {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ if (!format.isOptimized()) {
+ OMOutputFormat format2 = new OMOutputFormat();
+ format2.setCharSetEncoding(charSetEnc);
+ element.serializeAndConsume(bytesOut, format2);
+ return bytesOut.toByteArray();
+ } else {
+ format.setCharSetEncoding(charSetEnc);
+ format.setDoOptimize(true);
+ element.serializeAndConsume(bytesOut, format);
+ return bytesOut.toByteArray();
+ }
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+
+ public void writeRequest(OutputStream out) throws IOException {
+ try {
+ if (chunked) {
+ this.handleOMOutput(out, format.isDoingSWA());
+ } else {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+ out.write(bytes);
+ }
+ out.flush();
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw AxisFault.makeFault(e);
+ } catch (IOException e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+
+ public long getContentLength() {
+ try {
+ if (chunked) {
+ return -1;
+ } else {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+ return bytes.length;
+ }
+ } catch (AxisFault e) {
+ return -1;
+ }
+ }
+
+ public String getContentType() {
+ String encoding = format.getCharSetEncoding();
+ String contentType = format.getContentType();
+ if (encoding != null) {
+ contentType += "; charset=" + encoding;
+ }
+
+ // action header is not mandated in SOAP 1.2. So putting it, if available
+ if (!msgCtxt.isSOAP11() && (soapActionString != null)
+ && !"".equals(soapActionString.trim()) && !"\"\"".equals(soapActionString.trim())) {
+ contentType = contentType + ";action=\"" + soapActionString + "\";";
+ }
+ return contentType;
+ }
+
+ public boolean isRepeatable() {
+ return true;
+ }
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity2.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity2.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/RESTRequestEntity2.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class RESTRequestEntity2 implements RequestEntity {
+ private String contentType;
+ private String postRequestBody;
+
+ public RESTRequestEntity2(String postRequestBody, String contentType) {
+ this.postRequestBody = postRequestBody;
+ this.contentType = contentType;
+ }
+
+ public void writeRequest(OutputStream output) throws IOException {
+ output.write(postRequestBody.getBytes());
+ }
+
+ public long getContentLength() {
+ return this.postRequestBody.getBytes().length;
+ }
+
+ public String getContentType() {
+ return this.contentType;
+ }
+
+ public boolean isRepeatable() {
+ return true;
+ }
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.axis2.transport.OutTransportInfo;
+
+import javax.servlet.http.HttpServletResponse;
+
+public class ServletBasedOutTransportInfo implements OutTransportInfo {
+ private HttpServletResponse response;
+
+ public ServletBasedOutTransportInfo(HttpServletResponse response) {
+ this.response = response;
+ }
+
+ public void setContentType(String contentType) {
+ response.setContentType(contentType);
+ }
+
+ public void addHeader(String headerName, String headerValue) {
+ response.addHeader(headerName, headerValue);
+ }
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/SimpleHTTPServer.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/SimpleHTTPServer.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,374 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.SessionContext;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.transport.TransportListener;
+import org.apache.axis2.transport.http.server.HttpFactory;
+import org.apache.axis2.transport.http.server.HttpUtils;
+import org.apache.axis2.transport.http.server.SessionManager;
+import org.apache.axis2.transport.http.server.SimpleHttpServer;
+import org.apache.axis2.util.OptionsParser;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.io.IOException;
+import java.net.SocketException;
+import java.util.Iterator;
+
+/**
+ * This is a simple implementation of an HTTP server for processing
+ * SOAP requests via Apache's xml-axis2.
+ * It can be used with no configuration other than the port to listen on, or it can
+ * be configured in detail with an HttpFactory.
+ */
+public class SimpleHTTPServer implements TransportListener {
+
+ private static final Log log = LogFactory.getLog(SimpleHTTPServer.class);
+
+ /**
+ * Embedded commons http core based server
+ */
+ SimpleHttpServer embedded = null;
+ private String localAddress;
+ int port = -1;
+
+ public static int DEFAULT_PORT = 8080;
+
+ private String hostAddress = null;
+
+ protected ConfigurationContext configurationContext;
+ protected HttpFactory httpFactory;
+ private SessionManager sessionManager;
+
+ public SimpleHTTPServer() {
+ }
+
+ /**
+ * Create a SimpleHTTPServer using default HttpFactory settings
+ */
+ public SimpleHTTPServer(ConfigurationContext configurationContext, int port) throws AxisFault {
+ this(new HttpFactory(configurationContext, port));
+ }
+
+ /**
+ * Create a configured SimpleHTTPServer
+ */
+ public SimpleHTTPServer(HttpFactory httpFactory) throws AxisFault {
+ this.httpFactory = httpFactory;
+ this.configurationContext = httpFactory.getConfigurationContext();
+ this.port = httpFactory.getPort();
+ TransportInDescription httpDescription =
+ new TransportInDescription(Constants.TRANSPORT_HTTP);
+ httpDescription.setReceiver(this);
+ httpFactory.getListenerManager().addListener(httpDescription, true);
+ sessionManager = new SessionManager();
+ }
+
+ /**
+ * init method in TransportListener
+ *
+ * @param axisConf
+ * @param transprtIn
+ * @throws AxisFault
+ */
+ 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());
+ }
+
+ if (httpFactory == null) {
+ httpFactory = new HttpFactory(configurationContext, port);
+ }
+
+ param = transprtIn.getParameter(HOST_ADDRESS);
+ if (param != null) {
+ hostAddress = ((String) param.getValue()).trim();
+ } else {
+ hostAddress = httpFactory.getHostAddress();
+ }
+ } catch (Exception e1) {
+ throw AxisFault.makeFault(e1);
+ }
+ }
+
+ /**
+ * Method main
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ int port = DEFAULT_PORT;
+ OptionsParser optionsParser = new OptionsParser(args);
+
+ args = optionsParser.getRemainingArgs();
+ // first check if we should print usage
+ if ((optionsParser.isFlagSet('?') > 0) || (optionsParser.isFlagSet('h') > 0) ||
+ args == null || args.length == 0 || args.length > 3) {
+ printUsage();
+ }
+ String paramPort = optionsParser.isValueSet('p');
+ if (paramPort != null) {
+ port = Integer.parseInt(paramPort);
+ }
+
+ boolean startAllTransports = "all".equals(optionsParser.isValueSet('t'));
+ String repository = optionsParser.isValueSet('r');
+ if (repository == null) {
+ args = optionsParser.getRemainingArgs();
+ if (args != null && args[0] != null && !args[0].equals("")) {
+ repository = args[0];
+ } else {
+ printUsage();
+ }
+ }
+
+ System.out.println("[SimpleHTTPServer] Starting");
+ System.out.println("[SimpleHTTPServer] Using the Axis2 Repository "
+ + new File(repository).getAbsolutePath());
+ System.out.println("[SimpleHTTPServer] Listening on port " + port);
+ try {
+ ConfigurationContext configctx = ConfigurationContextFactory
+ .createConfigurationContextFromFileSystem(repository, null);
+ SimpleHTTPServer receiver = new SimpleHTTPServer(configctx, port);
+ Runtime.getRuntime().addShutdownHook(new ShutdownThread(receiver));
+ receiver.start();
+ ListenerManager listenerManager = configctx .getListenerManager();
+ TransportInDescription trsIn = new TransportInDescription(Constants.TRANSPORT_HTTP);
+ trsIn.setReceiver(receiver);
+ if (listenerManager == null) {
+ listenerManager = new ListenerManager();
+ listenerManager.init(configctx);
+ }
+ listenerManager.addListener(trsIn, true);
+
+ // should all transports be started? specified as "-t all"
+ if (startAllTransports) {
+ Iterator iter = configctx.getAxisConfiguration().
+ getTransportsIn().keySet().iterator();
+ while (iter.hasNext()) {
+ QName trp = (QName) iter.next();
+ if (!new QName(Constants.TRANSPORT_HTTP).equals(trp)) {
+ trsIn = (TransportInDescription)
+ configctx.getAxisConfiguration().getTransportsIn().get(trp);
+ listenerManager.addListener(trsIn, false);
+ }
+ }
+ }
+
+ System.out.println("[SimpleHTTPServer] Started");
+ } catch (Throwable t) {
+ log.fatal("Error starting SimpleHTTPServer", t);
+ System.out.println("[SimpleHTTPServer] Shutting down");
+ }
+ }
+
+ public static void printUsage() {
+ System.out.println("Usage: SimpleHTTPServer [options] -r <repository>");
+ System.out.println(" Opts: -? this message");
+ System.out.println();
+ System.out.println(" -p port :to listen on (default is 8080)");
+ System.out.println(
+ " -t all :to start all transports defined in the axis2 configuration");
+ System.exit(1);
+ }
+
+
+ /**
+ * Start this server as a NON-daemon.
+ */
+ public void start() throws AxisFault {
+ try {
+ embedded = new SimpleHttpServer(httpFactory, port);
+ embedded.init();
+ embedded.start();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ throw AxisFault.makeFault(e);
+ }
+ }
+
+ /**
+ * Stop this server. Can be called safely if the system is already stopped,
+ * or if it was never started.
+ * This will interrupt any pending accept().
+ */
+ public void stop() {
+ System.out.println("[SimpleHTTPServer] Stop called");
+ if (embedded != null) {
+ try {
+ embedded.destroy();
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ /**
+ * replyToEPR
+ * If the user has given host address paramter then it gets the high priority and
+ * ERP will be creatd using that
+ * N:B - hostAddress should be a complete url (http://www.myApp.com/ws)
+ *
+ * @param serviceName
+ * @param ip
+ * @return an EndpointReference
+ * @see org.apache.axis2.transport.TransportListener#getEPRForService(String,String)
+ */
+ public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault {
+ //if host address is present
+ if (hostAddress != null) {
+ if (embedded != null) {
+ String endpointRefernce = hostAddress ;
+ if(configurationContext.getServiceContextPath().startsWith("/")){
+ endpointRefernce = endpointRefernce +
+ configurationContext.getServiceContextPath() + "/" + serviceName;
+ } else {
+ endpointRefernce = endpointRefernce + '/' +
+ configurationContext.getServiceContextPath() + "/" + serviceName;
+ }
+ return new EndpointReference[]{new EndpointReference(endpointRefernce)};
+ } else {
+ throw new AxisFault("Unable to generate EPR for the transport : http");
+ }
+ }
+ //if the host address is not present
+ String ipAddress;
+ if (ip != null) {
+ ipAddress = ip;
+ } else {
+ try {
+ if(localAddress==null){
+ localAddress = Utils.getIpAddress(configurationContext.getAxisConfiguration());
+ }
+ if (localAddress == null) {
+ ipAddress = "127.0.0.1";
+ } else {
+ ipAddress = localAddress;
+ }
+ } catch (SocketException e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+ if (embedded != null) {
+ String endpointRefernce = "http://" + ipAddress + ":" + embedded.getPort() ;
+ if(configurationContext.getServiceContextPath().startsWith("/")){
+ endpointRefernce = endpointRefernce +
+ configurationContext.getServiceContextPath() + "/" + serviceName;
+ } else {
+ endpointRefernce = endpointRefernce + '/' +
+ configurationContext.getServiceContextPath() + "/" + serviceName;
+ }
+
+
+ return new EndpointReference[]{new EndpointReference(endpointRefernce)};
+ } else {
+ throw new AxisFault("Unable to generate EPR for the transport : http");
+ }
+ }
+
+ /**
+ * Getter for httpFactory
+ */
+ public HttpFactory getHttpFactory() {
+ return httpFactory;
+ }
+
+ /**
+ * Method getConfigurationContext
+ *
+ * @return the system context
+ */
+ public ConfigurationContext getConfigurationContext() {
+ return configurationContext;
+ }
+
+ /**
+ * replyToEPR
+ * If the user has given host address paramter then it gets the high priority and
+ * ERP will be creatd using that
+ * N:B - hostAddress should be a complte url (http://www.myApp.com/ws)
+ *
+ * @param serviceName
+ * @param ip
+ * @return an EndpointReference
+ * @see org.apache.axis2.transport.TransportListener#getEPRForService(String,String)
+ */
+ public EndpointReference getEPRForService(String serviceName, String ip) throws AxisFault {
+ return getEPRsForService(serviceName, ip)[0];
+ }
+
+ /**
+ * Checks if this HTTP server instance is running.
+ *
+ * @return true/false
+ */
+ public boolean isRunning() {
+ if (embedded == null) {
+ return false;
+ }
+
+ return embedded.isRunning();
+ }
+
+ static class ShutdownThread extends Thread {
+ private SimpleHTTPServer server = null;
+
+ public ShutdownThread(SimpleHTTPServer server) {
+ super();
+ this.server = server;
+ }
+
+ public void run() {
+ System.out.println("[SimpleHTTPServer] Shutting down");
+ server.stop();
+ System.out.println("[SimpleHTTPServer] Shutdown complete");
+ }
+ }
+
+
+ public SessionContext getSessionContext(MessageContext messageContext) {
+ String sessionKey = (String) messageContext.getProperty(HTTPConstants.COOKIE_STRING);
+ return this.sessionManager.getSessionContext(sessionKey);
+ }
+
+ public void destroy() {
+ this.configurationContext = null;
+ }
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/TransportHeaders.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/TransportHeaders.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/TransportHeaders.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/TransportHeaders.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Pass-Thru / delayed get and put of the values from HttpServletRequest
+ */
+public class TransportHeaders implements Map {
+ HttpServletRequest req;
+ // This map contains the headers from the request; it will be filled in lazily if needed,
+ // for performance
+ HashMap headerMap = null;
+ // This map contains properties that have been put onto the map; it is not populated by values
+ // from the HttpServletRequest. A null value means the headerMap has been fully populated and
+ // any values that were in localHeaderMap have been migrated to headerMap.
+ HashMap localHeaderMap = new HashMap();
+
+ public TransportHeaders(HttpServletRequest req) {
+ this.req = req;
+ }
+
+ /**
+ * This will fully populate the HashMap with the value from the HttpSerlvetRequest and migrate
+ * any values previously put onto localHeaderMap into the new HashMap.
+ *
+ * Note this is a bit non-performant, so it is only done if needed.
+ * If/when it is done, there may be properties that have been set on the localHeaderMap.
+ * If headerMap must be created due to a call
+ * to size, or isEmpty, or some other method which requires a fully populated map, then any
+ * previously created entries in the localHeaderMap are migrated to the new hashmap.
+ * After that localHeaderMap is released and only headerMap is used after that.
+ */
+ private void init() {
+ headerMap = new HashMap();
+ Enumeration headerNames = req.getHeaderNames();
+
+ while (headerNames.hasMoreElements()) {
+ String key = (String) headerNames.nextElement();
+ String value = req.getHeader(key);
+
+ headerMap.put(key, value);
+ }
+
+ // Migrate any previously set local properties to the newly created hashmap then release
+ // the local hashmap
+ Set localHeaderSet = localHeaderMap.entrySet();
+ Iterator localHeaderIterator = localHeaderSet.iterator();
+ while (localHeaderIterator.hasNext()) {
+ Map.Entry localHeaderEntry = (Map.Entry) localHeaderIterator.next();
+ headerMap.put(localHeaderEntry.getKey(), localHeaderEntry.getValue());
+ }
+ localHeaderMap = null;
+ }
+
+ public int size() {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.size();
+ }
+
+ public void clear() {
+ if (headerMap != null) {
+ headerMap.clear();
+ }
+ if (localHeaderMap != null) {
+ localHeaderMap.clear();
+ }
+ }
+
+ public boolean isEmpty() {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.isEmpty();
+ }
+
+ public boolean containsKey(Object key) {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.containsValue(value);
+ }
+
+ public Collection values() {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.values();
+ }
+
+ public void putAll(Map t) {
+ if (headerMap == null) {
+ init();
+ }
+ headerMap.putAll(t);
+ }
+
+ public Set entrySet() {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.entrySet();
+ }
+
+ public Set keySet() {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.keySet();
+ }
+
+ public Object get(Object key) {
+ // If there is a local map, look there first.
+ if (localHeaderMap != null) {
+ Object returnValue = null;
+ returnValue = localHeaderMap.get(key);
+ if (returnValue != null) {
+ return returnValue;
+ }
+ }
+ if (headerMap == null) {
+ return req.getHeader((String) key);
+ }
+ return headerMap.get(key);
+ }
+
+ public Object remove(Object key) {
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.remove(key);
+ }
+
+ public Object put(Object key, Object value) {
+ if (localHeaderMap != null) {
+ return localHeaderMap.put(key, value);
+ }
+ if (headerMap == null) {
+ init();
+ }
+ return headerMap.put(key, value);
+ }
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.http.HttpConnection;
+import org.apache.http.HttpException;
+import org.apache.http.HttpInetConnection;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public interface AxisHttpConnection extends HttpConnection, HttpInetConnection {
+
+ HttpRequest receiveRequest()
+ throws HttpException, IOException;
+
+ InputStream getInputStream();
+
+ void sendResponse(HttpResponse response)
+ throws HttpException, IOException;
+
+ OutputStream getOutputStream();
+
+ void flush()
+ throws IOException;
+
+ void reset()
+ throws IOException;
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpConnectionMetrics;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.io.ChunkedInputStream;
+import org.apache.http.impl.io.ChunkedOutputStream;
+import org.apache.http.impl.io.ContentLengthInputStream;
+import org.apache.http.impl.io.ContentLengthOutputStream;
+import org.apache.http.impl.io.HttpRequestParser;
+import org.apache.http.impl.io.HttpResponseWriter;
+import org.apache.http.impl.io.IdentityInputStream;
+import org.apache.http.impl.io.IdentityOutputStream;
+import org.apache.http.impl.io.SocketInputBuffer;
+import org.apache.http.impl.io.SocketOutputBuffer;
+import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageWriter;
+import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.io.SessionOutputBuffer;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
+
+public class AxisHttpConnectionImpl implements AxisHttpConnection {
+
+ private static final Log HEADERLOG =
+ LogFactory.getLog("org.apache.axis2.transport.http.server.wire");
+
+ private final Socket socket;
+ private final SessionOutputBuffer outbuffer;
+ private final SessionInputBuffer inbuffer;
+ private final HttpMessageParser requestParser;
+ private final HttpMessageWriter responseWriter;
+ private final ContentLengthStrategy contentLenStrategy;
+
+ private OutputStream out = null;
+ private InputStream in = null;
+
+ public AxisHttpConnectionImpl(final Socket socket, final HttpParams params)
+ throws IOException {
+ super();
+ if (socket == null) {
+ throw new IllegalArgumentException("Socket may not be null");
+ }
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
+ socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
+
+ int linger = HttpConnectionParams.getLinger(params);
+ if (linger >= 0) {
+ socket.setSoLinger(linger > 0, linger);
+ }
+
+ int buffersize = HttpConnectionParams.getSocketBufferSize(params);
+ this.socket = socket;
+ this.outbuffer = new SocketOutputBuffer(socket, buffersize, params);
+ this.inbuffer = new SocketInputBuffer(socket, buffersize, params);
+ this.contentLenStrategy = new StrictContentLengthStrategy();
+ this.requestParser = new HttpRequestParser(
+ this.inbuffer, null, new DefaultHttpRequestFactory(), params);
+ this.responseWriter = new HttpResponseWriter(
+ this.outbuffer, null, params);
+ }
+
+ public void close() throws IOException {
+ this.outbuffer.flush();
+ try {
+ this.socket.shutdownOutput();
+ } catch (IOException ignore) {
+ }
+ try {
+ this.socket.shutdownInput();
+ } catch (IOException ignore) {
+ }
+ this.socket.close();
+ }
+
+ public boolean isOpen() {
+ return !this.socket.isClosed();
+ }
+
+ public boolean isStale() {
+ try {
+ this.inbuffer.isDataAvailable(1);
+ return false;
+ } catch (IOException ex) {
+ return true;
+ }
+ }
+
+ public void shutdown() throws IOException {
+ Socket tmpsocket = this.socket;
+ if (tmpsocket != null) {
+ tmpsocket.close();
+ }
+ }
+
+ public HttpRequest receiveRequest() throws HttpException, IOException {
+ HttpRequest request = (HttpRequest) this.requestParser.parse();
+ if (HEADERLOG.isDebugEnabled()) {
+ HEADERLOG.debug(">> " + request.getRequestLine().toString());
+ for (HeaderIterator it = request.headerIterator(); it.hasNext(); ) {
+ HEADERLOG.debug(">> " + it.nextHeader().toString());
+ }
+ }
+
+ // Prepare input stream
+ this.in = null;
+ if (request instanceof HttpEntityEnclosingRequest) {
+ long len = this.contentLenStrategy.determineLength(request);
+ if (len == ContentLengthStrategy.CHUNKED) {
+ this.in = new ChunkedInputStream(this.inbuffer);
+ } else if (len == ContentLengthStrategy.IDENTITY) {
+ this.in = new IdentityInputStream(this.inbuffer);
+ } else {
+ this.in = new ContentLengthInputStream(inbuffer, len);
+ }
+ }
+ return request;
+ }
+
+ public void sendResponse(final HttpResponse response)
+ throws HttpException, IOException {
+ if (response == null) {
+ throw new IllegalArgumentException("HTTP response may not be null");
+ }
+
+ if (HEADERLOG.isDebugEnabled()) {
+ HEADERLOG.debug("<< " + response.getStatusLine().toString());
+ for (HeaderIterator it = response.headerIterator(); it.hasNext(); ) {
+ HEADERLOG.debug("<< " + it.nextHeader().toString());
+ }
+ }
+
+ this.responseWriter.write(response);
+
+ // Prepare output stream
+ this.out = null;
+ ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
+ HttpEntity entity = response.getEntity();
+ if (entity != null) {
+ long len = entity.getContentLength();
+ if (entity.isChunked() && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
+ this.out = new ChunkedOutputStream(this.outbuffer);
+ } else if (len >= 0) {
+ this.out = new ContentLengthOutputStream(this.outbuffer, len);
+ } else {
+ this.out = new IdentityOutputStream(this.outbuffer);
+ }
+ } else {
+ this.outbuffer.flush();
+ }
+ }
+
+ public InputStream getInputStream() {
+ return this.in;
+ }
+
+ public OutputStream getOutputStream() {
+ return this.out;
+ }
+
+ public void flush() throws IOException {
+ if (this.out != null) {
+ this.out.flush();
+ } else {
+ this.outbuffer.flush();
+ }
+ }
+
+ public void reset() throws IOException {
+ if (this.in != null) {
+ this.in.close();
+ this.in = null;
+ }
+ if (this.out != null) {
+ this.out.flush();
+ this.out.close();
+ this.out = null;
+ }
+ }
+
+ public int getSocketTimeout() {
+ try {
+ return this.socket.getSoTimeout();
+ } catch (SocketException ex) {
+ return -1;
+ }
+ }
+
+ public void setSocketTimeout(int timeout) {
+ try {
+ this.socket.setSoTimeout(timeout);
+ } catch (SocketException ex) {
+ }
+ }
+
+ public InetAddress getLocalAddress() {
+ if (this.socket != null) {
+ return this.socket.getLocalAddress();
+ } else {
+ return null;
+ }
+ }
+
+ public int getLocalPort() {
+ if (this.socket != null) {
+ return this.socket.getLocalPort();
+ } else {
+ return -1;
+ }
+ }
+
+ public InetAddress getRemoteAddress() {
+ if (this.socket != null) {
+ return this.socket.getInetAddress();
+ } else {
+ return null;
+ }
+ }
+
+ public int getRemotePort() {
+ if (this.socket != null) {
+ return this.socket.getPort();
+ } else {
+ return -1;
+ }
+ }
+
+ public HttpConnectionMetrics getMetrics() {
+ return null;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("[");
+ if (isOpen()) {
+ buffer.append(this.socket.getInetAddress());
+ } else {
+ buffer.append("closed");
+ }
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.http.HttpMessage;
+
+import java.io.InputStream;
+
+public interface AxisHttpRequest extends HttpMessage {
+
+ String getMethod();
+
+ String getRequestURI();
+
+ String getContentType();
+
+ InputStream getInputStream();
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class AxisHttpRequestImpl implements AxisHttpRequest {
+
+ private final HttpRequest request;
+ private final AxisHttpConnection conn;
+ private final HttpProcessor httpproc;
+ private final HttpContext context;
+
+ public AxisHttpRequestImpl(
+ final AxisHttpConnection conn,
+ final HttpRequest request,
+ final HttpProcessor httpproc,
+ final HttpContext context) {
+ super();
+ if (conn == null) {
+ throw new IllegalArgumentException("HTTP connection may not be null");
+ }
+ if (request == null) {
+ throw new IllegalArgumentException("HTTP request may not be null");
+ }
+ if (httpproc == null) {
+ throw new IllegalArgumentException("HTTP processor may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+ this.request = request;
+ this.conn = conn;
+ this.httpproc = httpproc;
+ this.context = context;
+ }
+
+ public void prepare() throws IOException, HttpException {
+ this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn);
+ this.context.setAttribute(ExecutionContext.HTTP_REQUEST, this.request);
+
+ this.httpproc.process(this.request, this.context);
+ }
+
+ public String getMethod() {
+ return this.request.getRequestLine().getMethod();
+ }
+
+ public String getRequestURI() {
+ return this.request.getRequestLine().getUri();
+ }
+
+ public ProtocolVersion getProtocolVersion() {
+ return this.request.getRequestLine().getProtocolVersion();
+ }
+
+ public String getContentType() {
+ Header header = this.request.getFirstHeader(HTTP.CONTENT_TYPE);
+ if (header != null) {
+ return header.getValue();
+ } else {
+ return null;
+ }
+ }
+
+ public InputStream getInputStream() {
+ return this.conn.getInputStream();
+ }
+
+ public void addHeader(final Header header) {
+ this.request.addHeader(header);
+ }
+
+ public void addHeader(final String name, final String value) {
+ this.request.addHeader(name, value);
+ }
+
+ public boolean containsHeader(final String name) {
+ return this.request.containsHeader(name);
+ }
+
+ public Header[] getAllHeaders() {
+ return this.request.getAllHeaders();
+ }
+
+ public Header getFirstHeader(final String name) {
+ return this.request.getFirstHeader(name);
+ }
+
+ public Header[] getHeaders(String name) {
+ return this.request.getHeaders(name);
+ }
+
+ public Header getLastHeader(final String name) {
+ return this.request.getLastHeader(name);
+ }
+
+ public HeaderIterator headerIterator() {
+ return this.request.headerIterator();
+ }
+
+ public HeaderIterator headerIterator(final String name) {
+ return this.request.headerIterator(name);
+ }
+
+ public void removeHeader(final Header header) {
+ this.request.removeHeader(header);
+ }
+
+ public void removeHeaders(final String name) {
+ this.request.removeHeaders(name);
+ }
+
+ public void setHeader(final Header header) {
+ this.request.setHeader(header);
+ }
+
+ public void setHeader(final String name, final String value) {
+ this.request.setHeader(name, value);
+ }
+
+ public void setHeaders(Header[] headers) {
+ this.request.setHeaders(headers);
+ }
+
+ public HttpParams getParams() {
+ return this.request.getParams();
+ }
+
+ public void setParams(final HttpParams params) {
+ this.request.setParams(params);
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.http.HttpMessage;
+
+import java.io.OutputStream;
+
+public interface AxisHttpResponse extends HttpMessage {
+
+ void setStatus(int sc);
+
+ void sendError(int sc, String msg);
+
+ void sendError(int sc);
+
+ void setContentType(String contentType);
+
+ OutputStream getOutputStream();
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.axis2.transport.OutTransportInfo;
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class AxisHttpResponseImpl implements AxisHttpResponse, OutTransportInfo {
+
+ private final HttpResponse response;
+ private final AxisHttpConnection conn;
+ private final HttpProcessor httpproc;
+ private final HttpContext context;
+
+ private AutoCommitOutputStream outstream;
+ private String contentType;
+
+ private volatile boolean commited;
+
+ public AxisHttpResponseImpl(
+ final AxisHttpConnection conn,
+ final HttpResponse response,
+ final HttpProcessor httpproc,
+ final HttpContext context) {
+ super();
+ if (response == null) {
+ throw new IllegalArgumentException("HTTP response may not be null");
+ }
+ if (conn == null) {
+ throw new IllegalArgumentException("HTTP connection may not be null");
+ }
+ if (httpproc == null) {
+ throw new IllegalArgumentException("HTTP processor may not be null");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException("HTTP context may not be null");
+ }
+ this.response = response;
+ this.conn = conn;
+ this.httpproc = httpproc;
+ this.context = context;
+ }
+
+ private void assertNotCommitted() {
+ if (this.commited) {
+ throw new IllegalStateException("Response already committed");
+ }
+ }
+
+ public boolean isCommitted() {
+ return this.commited;
+ }
+
+ public void commit() throws IOException, HttpException {
+ if (this.commited) {
+ return;
+ }
+ this.commited = true;
+
+ this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn);
+ this.context.setAttribute(ExecutionContext.HTTP_RESPONSE, this.response);
+
+ BasicHttpEntity entity = new BasicHttpEntity();
+ entity.setChunked(true);
+ entity.setContentType(this.contentType);
+
+ this.response.setEntity(entity);
+
+ this.httpproc.process(this.response, this.context);
+ this.conn.sendResponse(this.response);
+ }
+
+ public OutputStream getOutputStream() {
+ if (this.outstream == null) {
+ this.outstream = new AutoCommitOutputStream();
+ }
+ return this.outstream;
+ }
+
+ public void sendError(int sc, final String msg) {
+ assertNotCommitted();
+ ProtocolVersion ver = this.response.getProtocolVersion();
+ this.response.setStatusLine(ver, sc, msg);
+ }
+
+ public void sendError(int sc) {
+ assertNotCommitted();
+ this.response.setStatusCode(sc);
+ }
+
+ public void setStatus(int sc) {
+ assertNotCommitted();
+ this.response.setStatusCode(sc);
+ }
+
+ public void setContentType(final String contentType) {
+ assertNotCommitted();
+ this.contentType = contentType;
+ }
+
+ public ProtocolVersion getProtocolVersion() {
+ return this.response.getProtocolVersion();
+ }
+
+ public void addHeader(final Header header) {
+ assertNotCommitted();
+ this.response.addHeader(header);
+ }
+
+ public void addHeader(final String name, final String value) {
+ assertNotCommitted();
+ this.response.addHeader(name, value);
+ }
+
+ public boolean containsHeader(final String name) {
+ return this.response.containsHeader(name);
+ }
+
+ public Header[] getAllHeaders() {
+ return this.response.getAllHeaders();
+ }
+
+ public Header getFirstHeader(final String name) {
+ return this.response.getFirstHeader(name);
+ }
+
+ public Header[] getHeaders(String name) {
+ return this.response.getHeaders(name);
+ }
+
+ public Header getLastHeader(final String name) {
+ return this.response.getLastHeader(name);
+ }
+
+ public HeaderIterator headerIterator() {
+ return this.response.headerIterator();
+ }
+
+ public HeaderIterator headerIterator(String name) {
+ return this.response.headerIterator(name);
+ }
+
+ public void removeHeader(final Header header) {
+ assertNotCommitted();
+ this.response.removeHeader(header);
+ }
+
+ public void removeHeaders(final String name) {
+ assertNotCommitted();
+ this.response.removeHeaders(name);
+ }
+
+ public void setHeader(final Header header) {
+ assertNotCommitted();
+ this.response.setHeader(header);
+ }
+
+ public void setHeader(final String name, final String value) {
+ assertNotCommitted();
+ this.response.setHeader(name, value);
+ }
+
+ public void setHeaders(Header[] headers) {
+ assertNotCommitted();
+ this.response.setHeaders(headers);
+ }
+
+ public HttpParams getParams() {
+ return this.response.getParams();
+ }
+
+ public void setParams(final HttpParams params) {
+ this.response.setParams(params);
+ }
+
+ class AutoCommitOutputStream extends OutputStream {
+
+ private OutputStream out;
+
+ public AutoCommitOutputStream() {
+ super();
+ }
+
+ private void ensureCommitted() throws IOException {
+ try {
+ commit();
+ } catch (HttpException ex) {
+ throw (IOException) new IOException().initCause(ex);
+ }
+ if (this.out == null) {
+ this.out = conn.getOutputStream();
+ }
+ }
+
+ public void close() throws IOException {
+ ensureCommitted();
+ this.out.close();
+ }
+
+ public void write(final byte[] b, int off, int len) throws IOException {
+ ensureCommitted();
+ this.out.write(b, off, len);
+ }
+
+ public void write(final byte[] b) throws IOException {
+ ensureCommitted();
+ this.out.write(b);
+ }
+
+ public void write(int b) throws IOException {
+ ensureCommitted();
+ this.out.write(b);
+ }
+
+ public void flush() throws IOException {
+ ensureCommitted();
+ this.out.flush();
+ }
+
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpService.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpService.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisHttpService.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,379 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingHelper;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.transport.RequestResponseTransport;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.MessageContextBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.Header;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.MethodNotSupportedException;
+import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.RequestLine;
+import org.apache.http.UnsupportedHttpVersionException;
+import org.apache.http.params.DefaultedHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.SocketException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * This class is an extension of the default HTTP service responsible for
+ * maintaining and populating the {@link MessageContext} for incoming Axis
+ * requests.
+ */
+public class AxisHttpService {
+
+ private static final Log LOG = LogFactory.getLog(AxisHttpService.class);
+
+ private final HttpProcessor httpProcessor;
+ private final ConnectionReuseStrategy connStrategy;
+ private final HttpResponseFactory responseFactory;
+ private final ConfigurationContext configurationContext;
+ private final Worker worker;
+
+ private HttpParams params;
+
+ public AxisHttpService(
+ final HttpProcessor httpProcessor,
+ final ConnectionReuseStrategy connStrategy,
+ final HttpResponseFactory responseFactory,
+ final ConfigurationContext configurationContext,
+ final Worker worker) {
+ super();
+ if (httpProcessor == null) {
+ throw new IllegalArgumentException("HTTP processor may not be null");
+ }
+ if (connStrategy == null) {
+ throw new IllegalArgumentException("Connection strategy may not be null");
+ }
+ if (responseFactory == null) {
+ throw new IllegalArgumentException("Response factory may not be null");
+ }
+ if (worker == null) {
+ throw new IllegalArgumentException("Worker may not be null");
+ }
+ if (configurationContext == null) {
+ throw new IllegalArgumentException("Configuration context may not be null");
+ }
+ this.httpProcessor = httpProcessor;
+ this.connStrategy = connStrategy;
+ this.responseFactory = responseFactory;
+ this.configurationContext = configurationContext;
+ this.worker = worker;
+
+ }
+
+ public HttpParams getParams() {
+ return this.params;
+ }
+
+ public void setParams(final HttpParams params) {
+ this.params = params;
+ }
+
+ public void handleRequest(final AxisHttpConnection conn, final HttpContext context)
+ throws IOException, HttpException {
+
+ MessageContext msgContext = configurationContext.createMessageContext();
+ msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
+
+ if (conn != null) {
+ msgContext.setProperty(MessageContext.REMOTE_ADDR,
+ conn.getRemoteAddress().getHostAddress());
+ msgContext.setProperty(MessageContext.TRANSPORT_ADDR,
+ conn.getLocalAddress().getHostAddress());
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Remote address of the connection : " +
+ conn.getRemoteAddress().getHostAddress());
+ }
+ }
+
+ HttpResponse response;
+ try {
+ HttpRequest request = conn.receiveRequest();
+ RequestLine requestLine = request.getRequestLine();
+ if (requestLine != null) {
+ msgContext.setProperty(HTTPConstants.HTTP_METHOD, requestLine.getMethod());
+ }
+ request.setParams(
+ new DefaultedHttpParams(request.getParams(), this.params));
+ ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
+ if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
+ // Downgrade protocol version if greater than HTTP/1.1
+ ver = HttpVersion.HTTP_1_1;
+ }
+
+ response = this.responseFactory.newHttpResponse
+ (ver, HttpStatus.SC_OK, context);
+ response.setParams(
+ new DefaultedHttpParams(response.getParams(), this.params));
+
+ if (request instanceof HttpEntityEnclosingRequest) {
+ if (((HttpEntityEnclosingRequest) request).expectContinue()) {
+ HttpResponse ack = this.responseFactory.newHttpResponse
+ (ver, HttpStatus.SC_CONTINUE, context);
+ ack.setParams(
+ new DefaultedHttpParams(ack.getParams(), this.params));
+ conn.sendResponse(ack);
+ conn.flush();
+ }
+ }
+
+ // Create Axis request and response objects
+ AxisHttpRequestImpl axisreq = new AxisHttpRequestImpl(
+ conn,
+ request,
+ this.httpProcessor,
+ context);
+ AxisHttpResponseImpl axisres = new AxisHttpResponseImpl(
+ conn,
+ response,
+ this.httpProcessor,
+ context);
+
+ // Prepare HTTP request
+ axisreq.prepare();
+
+ // Run the service
+ doService(axisreq, axisres, context, msgContext);
+
+ // Make sure the request content is fully consumed
+ InputStream instream = conn.getInputStream();
+ if (instream != null) {
+ instream.close();
+ }
+
+ // Commit response if not committed
+ if (!axisres.isCommitted()) {
+ axisres.commit();
+ }
+
+ // Make sure the response content is properly terminated
+ OutputStream outstream = conn.getOutputStream();
+ if (outstream != null) {
+ outstream.close();
+ }
+
+ } catch (HttpException ex) {
+ response = this.responseFactory.newHttpResponse
+ (HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ context);
+ response.setParams(
+ new DefaultedHttpParams(response.getParams(), this.params));
+ handleException(ex, response);
+ this.httpProcessor.process(response, context);
+ conn.sendResponse(response);
+ }
+
+ conn.flush();
+ if (!this.connStrategy.keepAlive(response, context)) {
+ conn.close();
+ } else {
+ conn.reset();
+ }
+ }
+
+ protected void handleException(final HttpException ex, final HttpResponse response) {
+ if (ex instanceof MethodNotSupportedException) {
+ response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
+ } else if (ex instanceof UnsupportedHttpVersionException) {
+ response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
+ } else if (ex instanceof ProtocolException) {
+ response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+ } else {
+ response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+
+ protected void doService(
+ final AxisHttpRequest request,
+ final AxisHttpResponse response,
+ final HttpContext context,
+ final MessageContext msgContext) throws HttpException, IOException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Request method: " + request.getMethod());
+ LOG.debug("Target URI: " + request.getRequestURI());
+ }
+
+ try {
+ TransportOutDescription transportOut = this.configurationContext.getAxisConfiguration()
+ .getTransportOut(Constants.TRANSPORT_HTTP);
+ TransportInDescription transportIn = this.configurationContext.getAxisConfiguration()
+ .getTransportIn(Constants.TRANSPORT_HTTP);
+
+ String sessionKey = (String) context.getAttribute(HTTPConstants.COOKIE_STRING);
+ msgContext.setTransportIn(transportIn);
+ msgContext.setTransportOut(transportOut);
+ msgContext.setServerSide(true);
+ msgContext.setProperty(HTTPConstants.COOKIE_STRING, sessionKey);
+ msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL,
+ request.getRequestURI());
+
+ // set the transport Headers
+ HashMap headerMap = new HashMap();
+ for (Iterator it = request.headerIterator(); it.hasNext();) {
+ Header header = (Header) it.next();
+ headerMap.put(header.getName(), header.getValue());
+ }
+ msgContext.setProperty(MessageContext.TRANSPORT_HEADERS,
+ headerMap);
+ msgContext.setProperty(Constants.Configuration.CONTENT_TYPE,
+ request.getContentType());
+
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT,
+ response.getOutputStream());
+ msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
+ response);
+ msgContext.setTo(new EndpointReference(request.getRequestURI()));
+ msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL,
+ new SimpleHTTPRequestResponseTransport());
+
+
+ this.worker.service(request, response, msgContext);
+ } catch (SocketException ex) {
+ // Socket is unreliable.
+ throw ex;
+ } catch (HttpException ex) {
+ // HTTP protocol violation. Transport is unreliable
+ throw ex;
+ } catch (Throwable e) {
+
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT,
+ response.getOutputStream());
+ msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
+ response);
+
+ MessageContext faultContext =
+ MessageContextBuilder.createFaultMessageContext(msgContext, e);
+ // If the fault is not going along the back channel we should be 202ing
+ if (AddressingHelper.isFaultRedirected(msgContext)) {
+ response.setStatus(HttpStatus.SC_ACCEPTED);
+ } else {
+ String state = (String) msgContext.getProperty(Constants.HTTP_RESPONSE_STATE);
+ if (state != null) {
+ int stateInt = Integer.parseInt(state);
+ response.setStatus(stateInt);
+ if (stateInt == HttpServletResponse.SC_UNAUTHORIZED) { // Unauthorized
+ String realm =
+ (String) msgContext.getProperty(Constants.HTTP_BASIC_AUTH_REALM);
+ response.addHeader("WWW-Authenticate",
+ "basic realm=\"" + realm + "\"");
+ }
+ } else {
+ if (e instanceof AxisFault) {
+ response.sendError(getStatusFromAxisFault((AxisFault)e), e.getMessage());
+ } else {
+ response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ "Internal server error");
+ }
+ }
+ }
+ AxisEngine.sendFault(faultContext);
+ }
+ }
+
+ public int getStatusFromAxisFault(AxisFault fault) {
+ QName faultCode = fault.getFaultCode();
+ if (SOAP12Constants.QNAME_SENDER_FAULTCODE.equals(faultCode) ||
+ SOAP11Constants.QNAME_SENDER_FAULTCODE.equals(faultCode)) {
+ return HttpServletResponse.SC_BAD_REQUEST;
+ }
+
+ return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+ }
+
+ class SimpleHTTPRequestResponseTransport implements RequestResponseTransport {
+
+ private CountDownLatch responseReadySignal = new CountDownLatch(1);
+ RequestResponseTransportStatus status = RequestResponseTransportStatus.WAITING;
+ AxisFault faultToBeThrownOut = null;
+ private boolean responseWritten = false;
+
+ public void acknowledgeMessage(MessageContext msgContext) throws AxisFault {
+ //TODO: Once the core HTTP API allows us to return an ack before unwinding, then the should be fixed
+ status = RequestResponseTransportStatus.ACKED;
+ responseReadySignal.countDown();
+ }
+
+ public void awaitResponse() throws InterruptedException, AxisFault {
+ responseReadySignal.await();
+
+ if (faultToBeThrownOut != null) {
+ throw faultToBeThrownOut;
+ }
+ }
+
+ public void signalResponseReady() {
+ status = RequestResponseTransportStatus.SIGNALLED;
+ responseReadySignal.countDown();
+ }
+
+ public RequestResponseTransportStatus getStatus() {
+ return status;
+ }
+
+ public void signalFaultReady(AxisFault fault) {
+ faultToBeThrownOut = fault;
+ signalResponseReady();
+ }
+
+ public boolean isResponseWritten() {
+ return responseWritten;
+ }
+
+ public void setResponseWritten(boolean responseWritten) {
+ this.responseWritten = responseWritten;
+ }
+
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisParams.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisParams.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisParams.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/AxisParams.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 AxisParams {
+
+ private AxisParams() {
+ }
+
+ public static final String LISTENER_PORT = "axis.listener.port";
+
+ public static final String MESSAGE_CONTEXT = "axis.message.context";
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/ConnectionListenerFailureHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/ConnectionListenerFailureHandler.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/ConnectionListenerFailureHandler.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/ConnectionListenerFailureHandler.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 interface ConnectionListenerFailureHandler {
+
+ /**
+ * The associated connection listener IOProcessor has failed
+ *
+ * @param connectionListener the associated connection listener
+ * @param cause cause of failure
+ * @return true if the listener should attempt to re-establish itself, false if it should terminate.
+ */
+ public boolean failed(IOProcessor connectionListener, Throwable cause);
+
+ /**
+ * The associated connection listener IOProcessor is terminating abnormally
+ *
+ * @param connectionListener the associated connection listener
+ * @param message explanation of termination
+ * @param cause last exception that is causing termination
+ */
+ public void notifyAbnormalTermination(IOProcessor connectionListener, String message,
+ Throwable cause);
+
+}
Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/DefaultConnectionListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/DefaultConnectionListener.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/DefaultConnectionListener.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/server/DefaultConnectionListener.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.params.HttpParams;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class DefaultConnectionListener implements IOProcessor {
+
+ private static Log LOG = LogFactory.getLog(DefaultConnectionListener.class);
+
+ private volatile boolean destroyed = false;
+
+ private final int port;
+ private final HttpConnectionManager connmanager;
+ private final ConnectionListenerFailureHandler failureHandler;
+ private final HttpParams params;
+
+ private ServerSocket serversocket = null;
+
+ /**
+ * Use this constructor to provide a custom ConnectionListenerFailureHandler, e.g. by subclassing DefaultConnectionListenerFailureHandler
+ */
+ public DefaultConnectionListener(
+ int port,
+ final HttpConnectionManager connmanager,
+ final ConnectionListenerFailureHandler failureHandler,
+ final HttpParams params) throws IOException {
+ super();
+ if (connmanager == null) {
+ throw new IllegalArgumentException("Connection manager may not be null");
+ }
+ if (failureHandler == null) {
+ throw new IllegalArgumentException("Failure handler may not be null");
+ }
+ if (params == null) {
+ throw new IllegalArgumentException("HTTP parameters may not be null");
+ }
+ this.port = port;
+ this.connmanager = connmanager;
+ this.failureHandler = failureHandler;
+ this.params = params;
+ }
+
+ public void run() {
+ try {
+ while (!Thread.interrupted()) {
+ try {
+ if (serversocket == null || serversocket.isClosed()) {
+ serversocket = new ServerSocket(port);
+ serversocket.setReuseAddress(true);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Listening on port " + this.serversocket.getLocalPort());
+ }
+ }
+ LOG.debug("Waiting for incoming HTTP connection");
+ Socket socket = this.serversocket.accept();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Incoming HTTP connection from " +
+ socket.getRemoteSocketAddress());
+ }
+ AxisHttpConnection conn = new AxisHttpConnectionImpl(socket, this.params);
+ this.connmanager.process(conn);
+ } catch (Throwable ex) {
+ if (Thread.interrupted()) {
+ break;
+ }
+ if (!failureHandler.failed(this, ex)) {
+ break;
+ }
+ }
+ }
+ } finally {
+ destroy();
+ }
+ }
+
+ public void close() throws IOException {
+ if (this.serversocket != null) {
+ this.serversocket.close();
+ }
+ }
+
+ public void destroy() {
+ this.destroyed = true;
+ try {
+ close();
+ } catch (IOException ex) {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("I/O error closing listener", ex);
+ }
+ }
+ }
+
+ public boolean isDestroyed() {
+ return this.destroyed;
+ }
+
+}