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 sa...@apache.org on 2005/09/09 07:31:14 UTC
svn commit: r279706 - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http:
HTTPWorker.java server/SimpleHttpServerConnection.java
Author: saminda
Date: Thu Sep 8 22:30:55 2005
New Revision: 279706
URL: http://svn.apache.org/viewcvs?rev=279706&view=rev
Log:
SimpleAxisServer modified to get transport configuration via deployment
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=279706&r1=279705&r2=279706&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPWorker.java Thu Sep 8 22:30:55 2005
@@ -26,7 +26,9 @@
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.Parameter;
import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.util.threadpool.AxisWorker;
import org.apache.commons.logging.Log;
@@ -40,11 +42,13 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Enumeration;
+import java.util.Iterator;
public class HTTPWorker implements HttpRequestHandler {
protected Log log = LogFactory.getLog(getClass().getName());
private ConfigurationContext configurationContext;
+
public HTTPWorker(ConfigurationContext configurationContext) {
this.configurationContext = configurationContext;
}
@@ -81,7 +85,10 @@
httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
} else if (HttpVersion.HTTP_1_1.equals(ver)) {
httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
- response.setHeader(new Header(HTTPConstants.HEADER_TRANSFER_ENCODING, HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED));
+ /**
+ * Transport Sender configuration via axis2.xml
+ */
+ this.transportOutConfiguration(configurationContext,response);
} else {
throw new AxisFault("Unknown supported protocol version " + ver);
}
@@ -117,7 +124,7 @@
if (!processed) {
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
response.setBodyString(HTTPTransportReceiver.getServicesHTML(configurationContext));
- setResponseHeaders(conn, request, response);
+ setResponseHeaders(conn, request, response,0);
conn.writeResponse(response);
return true;
}
@@ -142,7 +149,7 @@
}
response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
response.setBody(new ByteArrayInputStream(baos.toByteArray()));
- setResponseHeaders(conn, request, response);
+ setResponseHeaders(conn, request, response,baos.toByteArray().length);
conn.writeResponse(response);
} catch (Throwable e) {
try {
@@ -153,7 +160,7 @@
response.setStatusLine(request.getRequestLine().getHttpVersion(), 500, "Internal server error");
engine.sendFault(faultContext);
response.setBody(new ByteArrayInputStream(baos.toByteArray()));
- setResponseHeaders(conn, request, response);
+ setResponseHeaders(conn, request, response,baos.toByteArray().length);
conn.writeResponse(response);
} else {
log.error(e, e);
@@ -166,7 +173,7 @@
return true;
}
- private void setResponseHeaders(final SimpleHttpServerConnection conn, SimpleRequest request, SimpleResponse response) {
+ private void setResponseHeaders(final SimpleHttpServerConnection conn, SimpleRequest request, SimpleResponse response, long contentLength) {
if (!response.containsHeader("Connection")) {
// See if the the client explicitly handles connection persistence
Header connheader = request.getFirstHeader("Connection");
@@ -190,6 +197,10 @@
}
}
}
+ if (!response.containsHeader("Transfer-Encoding")){
+ Header header = new Header("Content-Length",String.valueOf(contentLength));
+ response.addHeader(header);
+ }
}
private Map getHeaders(SimpleRequest request) {
@@ -200,4 +211,47 @@
}
return headerMap;
}
+
+
+ /**
+ * Simple Axis Transport Selection via deployment
+ * @param configContext
+ * @param response
+ *
+ */
+
+ private void transportOutConfiguration(ConfigurationContext configContext, SimpleResponse response) {
+ AxisConfiguration axisConf = configContext.getAxisConfiguration();
+ HashMap trasportOuts = axisConf.getTransportsOut();
+ Iterator values = trasportOuts.values().iterator();
+
+ String httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+ while (values.hasNext()) {
+ TransportOutDescription transportOut = (TransportOutDescription) values.next();
+ // reading axis2.xml for transport senders..
+ Parameter version =
+ transportOut.getParameter(HTTPConstants.PROTOCOL_VERSION);
+ if (version != null) {
+ if (HTTPConstants.HEADER_PROTOCOL_11.equals(version.getValue())) {
+ httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+ Parameter transferEncoding =
+ transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
+ if (transferEncoding != null){
+ if (HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(transferEncoding.getValue())) {
+ response.setHeader(new Header(HTTPConstants.HEADER_TRANSFER_ENCODING,
+ HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED));
+ }
+ } else {
+ continue;
+ }
+ } else {
+ if (HTTPConstants.HEADER_PROTOCOL_10.equals(version.getValue())) {
+ httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
+ }
+ }
+ }
+
+ }
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java?rev=279706&r1=279705&r2=279706&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/server/SimpleHttpServerConnection.java Thu Sep 8 22:30:55 2005
@@ -44,12 +44,12 @@
/**
* A connection to the SimpleHttpServer.
- *
+ *
* @author Christian Kohlschuetter
* @author Oleg Kalnichevski
*/
public class SimpleHttpServerConnection {
-
+
private static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
private Socket socket = null;
@@ -57,7 +57,7 @@
private OutputStream out = null;
private boolean keepAlive = false;
- public SimpleHttpServerConnection(final Socket socket)
+ public SimpleHttpServerConnection(final Socket socket)
throws IOException {
super();
if (socket == null) {
@@ -85,7 +85,7 @@
public synchronized boolean isOpen() {
return this.socket != null;
}
-
+
public void setKeepAlive(boolean b) {
this.keepAlive = b;
}
@@ -104,7 +104,7 @@
/**
* Returns the ResponseWriter used to write the output to the socket.
- *
+ *
* @return This connection's ResponseWriter
*/
public ResponseWriter getWriter() throws UnsupportedEncodingException {
@@ -122,7 +122,7 @@
setKeepAlive(false);
return null;
}
- SimpleRequest request = new SimpleRequest(
+ SimpleRequest request = new SimpleRequest(
RequestLine.parseLine(line),
HttpParser.parseHeaders(this.in, HTTP_ELEMENT_CHARSET),
this.in);
@@ -168,9 +168,9 @@
}
writer.println();
writer.flush();
-
+
OutputStream outsream = this.out;
- InputStream content = request.getBody();
+ InputStream content = request.getBody();
if (content != null) {
Header transferenc = request.getFirstHeader("Transfer-Encoding");
@@ -184,14 +184,14 @@
int i = 0;
while ((i = content.read(tmp)) >= 0) {
outsream.write(tmp, 0, i);
- }
+ }
if (outsream instanceof ChunkedOutputStream) {
((ChunkedOutputStream)outsream).finish();
}
}
outsream.flush();
}
-
+
public void writeResponse(final SimpleResponse response) throws IOException {
if (response == null) {
return;
@@ -205,9 +205,9 @@
}
writer.println();
writer.flush();
-
+
OutputStream outsream = this.out;
- InputStream content = response.getBody();
+ InputStream content = response.getBody();
if (content != null) {
Header transferenc = response.getFirstHeader("Transfer-Encoding");
@@ -215,28 +215,38 @@
response.removeHeaders("Content-Length");
if (transferenc.getValue().indexOf("chunked") != -1) {
outsream = new ChunkedOutputStream(outsream);
+
+
+ byte[] tmp = new byte[1024];
+ int i = 0;
+ while ((i = content.read(tmp)) >= 0) {
+ outsream.write(tmp, 0, i);
+ }
+ if (outsream instanceof ChunkedOutputStream) {
+ ((ChunkedOutputStream) outsream).finish();
+ }
}
- }
-
- byte[] tmp = new byte[1024];
- int i = 0;
- while ((i = content.read(tmp)) >= 0) {
- outsream.write(tmp, 0, i);
- }
- if (outsream instanceof ChunkedOutputStream) {
- ((ChunkedOutputStream)outsream).finish();
+ } else {
+ /**
+ * read the content when needed to embed content-length
+ */
+ byte[] tmp = new byte[1024];
+ int i = 0;
+ while ((i = content.read(tmp)) >= 0) {
+ outsream.write(tmp, 0, i);
+ }
+
}
}
+
outsream.flush();
}
public int getSocketTimeout() throws SocketException {
return this.socket.getSoTimeout();
}
-
+
public void setSocketTimeout(int timeout) throws SocketException {
this.socket.setSoTimeout(timeout);
}
-
}
-
\ No newline at end of file