You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/08/12 20:20:26 UTC
svn commit: r232347 - in
/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote:
HttpProtocolHandler.java impl/HttpConnectionProcessor.java
Author: olegk
Date: Fri Aug 12 11:20:19 2005
New Revision: 232347
URL: http://svn.apache.org/viewcvs?rev=232347&view=rev
Log:
Added several missing bits and pieces. HttpConnector now should have all the essential functions in place
Modified:
jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java?rev=232347&r1=232346&r2=232347&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java (original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java Fri Aug 12 11:20:19 2005
@@ -45,6 +45,7 @@
import org.apache.http.impl.DefaultHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
/**
* <p>
@@ -57,6 +58,7 @@
private static Log LOG = LogFactory.getLog(HttpProtocolHandler.class);
+ private static final String ORIGIN_SERVER = "Apache-Coyote/1.1 (Jakarta HTTP connector)";
private static final int SHUTDOWN_GRACE_PERIOD = 5000; // ms
private final HttpParams params;
@@ -73,7 +75,11 @@
public HttpProtocolHandler() {
super();
this.params = new DefaultHttpParams();
- HttpConnectionParams.setSoTimeout(this.params, 5000);
+ this.params
+ .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 10000)
+ .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+ .setParameter(HttpProtocolParams.ORIGIN_SERVER, ORIGIN_SERVER)
+ .setIntParameter(CoyoteParams.CONNECTOR_PORT, 8080);
}
public int getPort() {
Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java?rev=232347&r1=232346&r2=232347&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java (original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java Fri Aug 12 11:20:19 2005
@@ -75,6 +75,8 @@
import org.apache.http.protocol.AbstractHttpProcessor;
import org.apache.http.protocol.ResponseConnControl;
import org.apache.http.protocol.ResponseContent;
+import org.apache.http.protocol.ResponseDate;
+import org.apache.http.protocol.ResponseServer;
import org.apache.tomcat.util.http.MimeHeaders;
/**
@@ -99,6 +101,9 @@
private final Request coyotereq;
private final Response coyoteres;
+ private ContentInputBuffer inbuffer = null;
+ private ContentOutputBuffer outbuffer = null;
+
private HttpRequest httpreq = null;
private HttpResponse httpres = null;
@@ -130,6 +135,8 @@
// Add required protocol interceptors
addResponseInterceptor(new ResponseContent());
addResponseInterceptor(new ResponseConnControl());
+ addResponseInterceptor(new ResponseDate());
+ addResponseInterceptor(new ResponseServer());
// Add connection to the HTTP context
getContext().setAttribute(HttpProcessingContext.HTTP_CONNECTION, conn);
@@ -145,7 +152,9 @@
callServletContainer();
prepareHttpResponse();
sendHttpResponse();
+ closeOutputBuffer();
manageHttpConnection();
+ reset();
} catch (HttpException ex) {
LOG.debug("Malformed HTTP request");
this.httpres = processHttpException(ex);
@@ -177,7 +186,7 @@
this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_NEW);
this.httpreq = this.conn.receiveRequest(this.params);
this.coyotereq.setStartTime(System.currentTimeMillis());
- LOG.debug("HTTP request received");
+ LOG.debug("HTTP request header received");
this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PREPARE);
if (this.httpreq instanceof HttpMutableRequest) {
@@ -200,20 +209,45 @@
}
return response;
}
-
+
+ private void sendAck() throws IOException {
+ HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
+ BasicHttpResponse ack = new BasicHttpResponse(new StatusLine(ver,
+ HttpStatus.SC_CONTINUE));
+ try {
+ this.conn.sendResponse(ack);
+ LOG.debug("Ack continue sent");
+ } catch (HttpException ex) {
+ LOG.error("Malformed HTTP response", ex);
+ this.conn.close();
+ }
+ }
+
private void sendHttpResponse() throws IOException {
try {
if (this.httpres instanceof HttpMutableResponse) {
postprocessResponse((HttpMutableResponse)this.httpres);
}
this.conn.sendResponse(this.httpres);
- LOG.debug("HTTP response sent");
+ LOG.debug("HTTP response header sent");
} catch (HttpException ex) {
LOG.error("Malformed HTTP response", ex);
this.conn.close();
}
}
+ private void flushOutputBuffer() throws IOException {
+ if (this.outbuffer != null) {
+ this.outbuffer.flush();
+ }
+ }
+
+ private void closeOutputBuffer() throws IOException {
+ if (this.outbuffer != null) {
+ this.outbuffer.close();
+ }
+ }
+
private void prepareCoyoteRequest() throws IOException, HttpException {
this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PARSE);
// Convert the request line
@@ -293,7 +327,8 @@
if (this.httpreq instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest)this.httpreq).getEntity();
if (entity != null) {
- this.coyotereq.setInputBuffer(new ContentInputBuffer(entity));
+ this.inbuffer = new ContentInputBuffer(entity);
+ this.coyotereq.setInputBuffer(this.inbuffer);
}
}
}
@@ -302,6 +337,9 @@
this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_SERVICE);
try {
this.adapter.service(this.coyotereq, this.coyoteres);
+ if (this.coyoteres.isExceptionPresent()) {
+ throw this.coyoteres.getErrorException();
+ }
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
@@ -316,8 +354,7 @@
}
HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
int statuscode = this.coyoteres.getStatus();
- BasicHttpResponse tmp = new BasicHttpResponse(new StatusLine(ver, statuscode,
- HttpStatus.getStatusText(statuscode)));
+ BasicHttpResponse tmp = new BasicHttpResponse(new StatusLine(ver, statuscode));
MimeHeaders headers = this.coyoteres.getMimeHeaders();
int size = headers.size();
for (int i = 0; i < size; i++) {
@@ -331,11 +368,11 @@
}
ResponseStrategy responsestrategy = new DefaultResponseStrategy();
if (responsestrategy.canHaveEntity(this.httpreq, this.httpres)) {
- ContentOutputBuffer buffer = new ContentOutputBuffer();
- buffer.setContentLength(this.coyoteres.getContentLengthLong());
- buffer.setContentType(this.coyoteres.getContentType());
- tmp.setEntity(buffer);
- this.coyoteres.setOutputBuffer(buffer);
+ this.outbuffer = new ContentOutputBuffer();
+ this.outbuffer.setContentLength(this.coyoteres.getContentLengthLong());
+ this.outbuffer.setContentType(this.coyoteres.getContentType());
+ tmp.setEntity(this.outbuffer);
+ this.coyoteres.setOutputBuffer(this.outbuffer);
}
this.httpres = tmp;
}
@@ -352,10 +389,15 @@
this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_KEEPALIVE);
}
}
+ }
+
+ private void reset() {
this.coyotereq.recycle();
this.coyoteres.recycle();
- this.httpreq = null;
- this.httpres = null;
+ this.inbuffer = null;
+ this.outbuffer = null;
+ this.httpreq = null;
+ this.httpres = null;
}
public void close() throws IOException {
@@ -377,16 +419,66 @@
public void action(final ActionCode actionCode, final Object param) {
if (actionCode == ActionCode.ACTION_COMMIT) {
+ LOG.debug("Commit action");
+ if (this.coyoteres.isCommitted()) {
+ return;
+ }
+ try {
+ prepareHttpResponse();
+ sendHttpResponse();
+ this.coyoteres.setCommitted(true);
+ } catch (IOException ex) {
+ this.coyoteres.setErrorException(ex);
+ }
} else if (actionCode == ActionCode.ACTION_ACK) {
+ LOG.debug("Ack action");
+ if (this.coyoteres.isCommitted()) {
+ return;
+ }
+ try {
+ sendAck();
+ } catch (IOException ex) {
+ this.coyoteres.setErrorException(ex);
+ }
} else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) {
+ LOG.debug("Flush action");
+ try {
+ if (!this.coyoteres.isCommitted()) {
+ prepareHttpResponse();
+ sendHttpResponse();
+ this.coyoteres.setCommitted(true);
+ }
+ flushOutputBuffer();
+ } catch (IOException ex) {
+ this.coyoteres.setErrorException(ex);
+ }
} else if (actionCode == ActionCode.ACTION_CLOSE) {
+ LOG.debug("Flush action");
+ try {
+ if (!this.coyoteres.isCommitted()) {
+ prepareHttpResponse();
+ sendHttpResponse();
+ this.coyoteres.setCommitted(true);
+ }
+ closeOutputBuffer();
+ } catch (IOException ex) {
+ this.coyoteres.setErrorException(ex);
+ }
} else if (actionCode == ActionCode.ACTION_RESET) {
+ LOG.debug("Reset action");
+ reset();
} else if (actionCode == ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE) {
+ // Not implemetned
} else if (actionCode == ActionCode.ACTION_REQ_HOST_ATTRIBUTE) {
+ // Not implemetned
} else if (actionCode == ActionCode.ACTION_REQ_REMOTEPORT_ATTRIBUTE) {
+ // Not implemetned
} else if (actionCode == ActionCode.ACTION_REQ_LOCAL_NAME_ATTRIBUTE) {
+ // Not implemetned
} else if (actionCode == ActionCode.ACTION_REQ_LOCALPORT_ATTRIBUTE) {
+ // Not implemetned
} else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) {
+ // Not implemetned
} else {
throw new NotImplementedException("Action code " + actionCode +
" not implemented");