You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bi...@apache.org on 2005/02/03 04:36:57 UTC
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/server JkCoyoteHandler.java
billbarker 2005/02/02 19:36:57
Modified: jk/java/org/apache/jk/server JkCoyoteHandler.java
Log:
Cleanup exception handling in action, and remember error state so that we can close the connection without having to attempt another read.
Fix for Bug #33374
Reported By: Lars George lars@worldlingo.com
Revision Changes Path
1.59 +112 -90 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkCoyoteHandler.java
Index: JkCoyoteHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkCoyoteHandler.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- JkCoyoteHandler.java 11 Jan 2005 13:37:45 -0000 1.58
+++ JkCoyoteHandler.java 3 Feb 2005 03:36:57 -0000 1.59
@@ -96,6 +96,7 @@
public final int JK_STATUS_NEW=0;
public final int JK_STATUS_HEAD=1;
public final int JK_STATUS_CLOSED=2;
+ public final int JK_STATUS_ERROR=3;
/** Set a property. Name is a "component.property". JMX should
* be used instead.
@@ -311,11 +312,13 @@
res.finish();
}
- ep.setStatus( JK_STATUS_NEW );
-
req.recycle();
req.updateCounters();
res.recycle();
+ if( ep.getStatus() == JK_STATUS_ERROR ) {
+ return ERROR;
+ }
+ ep.setStatus( JK_STATUS_NEW );
rp.setStage(Constants.STAGE_KEEPALIVE);
return OK;
}
@@ -410,106 +413,125 @@
// -------------------- Coyote Action implementation --------------------
public void action(ActionCode actionCode, Object param) {
- try {
- if( actionCode==ActionCode.ACTION_COMMIT ) {
- if( log.isDebugEnabled() ) log.debug("COMMIT " );
- org.apache.coyote.Response res=(org.apache.coyote.Response)param;
-
- if( res.isCommitted() ) {
- if( log.isInfoEnabled() )
- log.info("Response already commited " );
- } else {
+ if( actionCode==ActionCode.ACTION_COMMIT ) {
+ if( log.isDebugEnabled() ) log.debug("COMMIT " );
+ org.apache.coyote.Response res=(org.apache.coyote.Response)param;
+
+ if( res.isCommitted() ) {
+ if( log.isInfoEnabled() )
+ log.info("Response already commited " );
+ } else {
+ try {
appendHead( res );
+ } catch(IOException iex) {
+ log.warn("Unable to send headers",iex);
+ MsgContext ep=(MsgContext)res.getNote( epNote );
+ ep.setStatus(JK_STATUS_ERROR);
}
- } else if( actionCode==ActionCode.ACTION_RESET ) {
- if( log.isDebugEnabled() )
- log.debug("RESET " );
-
- } else if( actionCode==ActionCode.ACTION_CLIENT_FLUSH ) {
- if( log.isDebugEnabled() ) log.debug("CLIENT_FLUSH " );
- org.apache.coyote.Response res=(org.apache.coyote.Response)param;
- MsgContext ep=(MsgContext)res.getNote( epNote );
- ep.setType( JkHandler.HANDLE_FLUSH );
+ }
+ } else if( actionCode==ActionCode.ACTION_RESET ) {
+ if( log.isDebugEnabled() )
+ log.debug("RESET " );
+
+ } else if( actionCode==ActionCode.ACTION_CLIENT_FLUSH ) {
+ if( log.isDebugEnabled() ) log.debug("CLIENT_FLUSH " );
+ org.apache.coyote.Response res=(org.apache.coyote.Response)param;
+ MsgContext ep=(MsgContext)res.getNote( epNote );
+ ep.setType( JkHandler.HANDLE_FLUSH );
+ try {
ep.getSource().flush( null, ep );
-
- } else if( actionCode==ActionCode.ACTION_CLOSE ) {
- if( log.isDebugEnabled() ) log.debug("CLOSE " );
-
- org.apache.coyote.Response res=(org.apache.coyote.Response)param;
- MsgContext ep=(MsgContext)res.getNote( epNote );
- if( ep.getStatus()== JK_STATUS_CLOSED ) {
- // Double close - it may happen with forward
- if( log.isDebugEnabled() ) log.debug("Double CLOSE - forward ? " + res.getRequest().requestURI() );
- return;
- }
+ } catch(IOException iex) {
+ // This is logged elsewhere, so debug only here
+ log.debug("Error during flush",iex);
+ res.setErrorException(iex);
+ ep.setStatus(JK_STATUS_ERROR);
+ }
+
+ } else if( actionCode==ActionCode.ACTION_CLOSE ) {
+ if( log.isDebugEnabled() ) log.debug("CLOSE " );
+
+ org.apache.coyote.Response res=(org.apache.coyote.Response)param;
+ MsgContext ep=(MsgContext)res.getNote( epNote );
+ if( ep.getStatus()== JK_STATUS_CLOSED ) {
+ // Double close - it may happen with forward
+ if( log.isDebugEnabled() ) log.debug("Double CLOSE - forward ? " + res.getRequest().requestURI() );
+ return;
+ }
- if( !res.isCommitted() )
- this.action( ActionCode.ACTION_COMMIT, param );
-
- MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
- msg.reset();
- msg.appendByte( HandlerRequest.JK_AJP13_END_RESPONSE );
- msg.appendByte( 1 );
-
- try {
- ep.setType( JkHandler.HANDLE_SEND_PACKET );
- ep.getSource().send( msg, ep );
+ if( !res.isCommitted() )
+ this.action( ActionCode.ACTION_COMMIT, param );
+
+ MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
+ msg.reset();
+ msg.appendByte( HandlerRequest.JK_AJP13_END_RESPONSE );
+ msg.appendByte( 1 );
- ep.setType( JkHandler.HANDLE_FLUSH );
- ep.getSource().flush( msg, ep );
- } catch(IOException iex) {
- log.debug("Connection error ending request.",iex);
- }
+ try {
+ ep.setType( JkHandler.HANDLE_SEND_PACKET );
+ ep.getSource().send( msg, ep );
+
+ ep.setType( JkHandler.HANDLE_FLUSH );
+ ep.getSource().flush( msg, ep );
+ } catch(IOException iex) {
+ log.debug("Connection error ending request.",iex);
+ ep.setStatus(JK_STATUS_ERROR);
+ }
+ if(ep.getStatus() != JK_STATUS_ERROR) {
ep.setStatus(JK_STATUS_CLOSED );
+ }
- if( logTime.isDebugEnabled() )
- logTime(res.getRequest(), res);
- } else if( actionCode==ActionCode.ACTION_REQ_SSL_ATTRIBUTE ) {
- org.apache.coyote.Request req=(org.apache.coyote.Request)param;
-
- // Extract SSL certificate information (if requested)
- MessageBytes certString = (MessageBytes)req.getNote(WorkerEnv.SSL_CERT_NOTE);
- if( certString != null && !certString.isNull() ) {
- ByteChunk certData = certString.getByteChunk();
- ByteArrayInputStream bais =
- new ByteArrayInputStream(certData.getBytes(),
- certData.getStart(),
- certData.getLength());
-
- // Fill the first element.
- X509Certificate jsseCerts[] = null;
- try {
- CertificateFactory cf =
- CertificateFactory.getInstance("X.509");
- X509Certificate cert = (X509Certificate)
- cf.generateCertificate(bais);
- jsseCerts = new X509Certificate[1];
- jsseCerts[0] = cert;
- } catch(java.security.cert.CertificateException e) {
- log.error("Certificate convertion failed" , e );
- return;
- }
+ if( logTime.isDebugEnabled() )
+ logTime(res.getRequest(), res);
+ } else if( actionCode==ActionCode.ACTION_REQ_SSL_ATTRIBUTE ) {
+ org.apache.coyote.Request req=(org.apache.coyote.Request)param;
+
+ // Extract SSL certificate information (if requested)
+ MessageBytes certString = (MessageBytes)req.getNote(WorkerEnv.SSL_CERT_NOTE);
+ if( certString != null && !certString.isNull() ) {
+ ByteChunk certData = certString.getByteChunk();
+ ByteArrayInputStream bais =
+ new ByteArrayInputStream(certData.getBytes(),
+ certData.getStart(),
+ certData.getLength());
- req.setAttribute(SSLSupport.CERTIFICATE_KEY,
- jsseCerts);
+ // Fill the first element.
+ X509Certificate jsseCerts[] = null;
+ try {
+ CertificateFactory cf =
+ CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate)
+ cf.generateCertificate(bais);
+ jsseCerts = new X509Certificate[1];
+ jsseCerts[0] = cert;
+ } catch(java.security.cert.CertificateException e) {
+ log.error("Certificate convertion failed" , e );
+ return;
}
+
+ req.setAttribute(SSLSupport.CERTIFICATE_KEY,
+ jsseCerts);
+ }
- } else if( actionCode==ActionCode.ACTION_REQ_HOST_ATTRIBUTE ) {
- org.apache.coyote.Request req=(org.apache.coyote.Request)param;
+ } else if( actionCode==ActionCode.ACTION_REQ_HOST_ATTRIBUTE ) {
+ org.apache.coyote.Request req=(org.apache.coyote.Request)param;
- // If remoteHost not set by JK, get it's name from it's remoteAddr
- if( req.remoteHost().isNull())
- req.remoteHost().setString(InetAddress.getByName(req.remoteAddr().toString()).getHostName());
-
- // } else if( actionCode==ActionCode.ACTION_POST_REQUEST ) {
-
- } else if( actionCode==ActionCode.ACTION_ACK ) {
- if( log.isDebugEnabled() )
- log.debug("ACK " );
- // What should we do here ? Who calls it ?
+ // If remoteHost not set by JK, get it's name from it's remoteAddr
+ if( req.remoteHost().isNull()) {
+ try {
+ req.remoteHost().setString(InetAddress.getByName(
+ req.remoteAddr().toString()).
+ getHostName());
+ } catch(IOException iex) {
+ if(log.isDebugEnabled())
+ log.debug("Unable to resolve "+req.remoteAddr());
+ }
}
- } catch( Exception ex ) {
- log.error( "Error in action code ", ex );
+ // } else if( actionCode==ActionCode.ACTION_POST_REQUEST ) {
+
+ } else if( actionCode==ActionCode.ACTION_ACK ) {
+ if( log.isDebugEnabled() )
+ log.debug("ACK " );
+ // What should we do here ? Who calls it ?
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org