remm 2005/06/16 04:52:26 Modified: jk/java/org/apache/coyote/ajp AjpAprProcessor.java Constants.java Log: - Default to no timeout for AJP connections with APR. - Fix redirects from the mapper (oops). - Copy over SSL certs support from regular AJP (not tested). - Copy over replay support (not tested). - This seems to be working reasonably well overall. Revision Changes Path 1.4 +72 -9 jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java Index: AjpAprProcessor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AjpAprProcessor.java 15 Jun 2005 17:35:24 -0000 1.3 +++ AjpAprProcessor.java 16 Jun 2005 11:52:26 -0000 1.4 @@ -16,9 +16,12 @@ package org.apache.coyote.ajp; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InterruptedIOException; import java.net.InetAddress; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; import org.apache.coyote.ActionCode; import org.apache.coyote.ActionHook; @@ -281,6 +284,18 @@ protected boolean first = true; + /** + * Replay read. + */ + protected boolean replay = false; + + + /** + * Finished response. + */ + protected boolean finished = false; + + // ------------------------------------------------------------- Properties @@ -418,7 +433,6 @@ } catch (InterruptedIOException e) { error = true; } catch (Throwable t) { - t.printStackTrace(); log.error("Error processing request", t); // 500 - Internal Server Error response.setStatus(500); @@ -426,6 +440,15 @@ } } + // Finish the response if not done yet + if (!finished) { + try { + endRequest(); + } catch (Throwable t) { + error = true; + } + } + // If there was an error, make sure the request is counted as // and error, and update the statistics counter if (error) { @@ -536,7 +559,27 @@ } else if (actionCode == ActionCode.ACTION_REQ_SSL_ATTRIBUTE ) { - // FIXME: SSL implementation + ByteChunk certData = certificates.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; + } + + request.setAttribute("javax.servlet.request.X509Certificate", jsseCerts); } else if (actionCode == ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE) { @@ -627,9 +670,22 @@ request.setLocalPort(localPort); } else if (actionCode == ActionCode.ACTION_REQ_SSL_CERTIFICATE) { - // FIXME: SSL implementation + + // FIXME: Nothing needed here ? + + } else if (actionCode == ActionCode.ACTION_REQ_SET_BODY_REPLAY) { + + if( log.isTraceEnabled() ) + log.trace("Replay "); + ByteChunk bc = (ByteChunk) param; + bodyBytes.setBytes(bc.getBytes(), bc.getStart(), bc.getLength()); + first = false; + empty = false; + replay = true; + } + } @@ -680,7 +736,7 @@ request.setLocalPort(headerMessage.getInt()); boolean isSSL = headerMessage.getByte() != 0; - if( isSSL ) { + if (isSSL) { // XXX req.setSecure( true ); request.scheme().setString("https"); } @@ -1014,6 +1070,10 @@ } } + if (finished) + return; + + finished = true; outputMessage.reset(); outputMessage.appendByte(Constants.JK_AJP13_END_RESPONSE); outputMessage.appendByte(1); @@ -1065,10 +1125,10 @@ { // If the server returns an empty packet, assume that that end of // the stream has been reached (yuck -- fix protocol??). - // FIXME: FORM support here ? - //if(replay) { - // endOfStream = true; // we've read everything there is - //} + // FORM support + if (replay) { + endOfStream = true; // we've read everything there is + } if (endOfStream) { if( log.isDebugEnabled() ) log.debug("refillReadBuffer: end of stream " ); @@ -1170,8 +1230,11 @@ first = true; endOfStream = false; empty = true; + replay = false; + finished = false; request.recycle(); response.recycle(); + certificates.recycle(); headerMessage.reset(); } @@ -1208,7 +1271,7 @@ } } ByteChunk bc = bodyBytes.getByteChunk(); - chunk.setBytes( bc.getBuffer(), bc.getStart(), bc.getLength() ); + chunk.setBytes(bc.getBuffer(), bc.getStart(), bc.getLength()); empty = true; return chunk.getLength(); 1.2 +1 -1 jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/Constants.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Constants.java 9 Jun 2005 16:14:51 -0000 1.1 +++ Constants.java 16 Jun 2005 11:52:26 -0000 1.2 @@ -36,7 +36,7 @@ public static final String Package = "org.apache.coyote.ajp"; public static final int DEFAULT_CONNECTION_LINGER = -1; - public static final int DEFAULT_CONNECTION_TIMEOUT = 60000; + public static final int DEFAULT_CONNECTION_TIMEOUT = 0; public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000; public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0; public static final boolean DEFAULT_TCP_NO_DELAY = true;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]