cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/06/15 08:27:33 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Fix some basic issues with the AJP on APR implementation. - In particular, endRequest is no longer called twice (oops ...). Revision ChangesPath 1.2 +15 -25 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AjpAprProcessor.java 9 Jun 2005 16:14:51 - 1.1 +++ AjpAprProcessor.java 15 Jun 2005 15:27:33 - 1.2 @@ -88,7 +88,7 @@ readBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK); readBodyMessage.appendInt(Constants.MAX_READ_SIZE); - + } @@ -130,7 +130,7 @@ /** * Char version of the message header. */ -protected char[] headerChar = new char[8*1024]; // FIXME: Size should be configurable +//protected char[] headerChar = new char[8*1024]; /** @@ -375,14 +375,12 @@ // (long keepalive), so that the processor should be recycled // and the method should return true rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); -openSocket = true; -// Add the socket to the poller -endpoint.getPoller().add(socket, pool); break; } -// FIXME: Check message type, process right away and break if +// Check message type, process right away and break if // not regular request processing int type = headerMessage.getByte(); +// FIXME: Any other types which should be checked ? if (type == Constants.JK_AJP13_CPING_REQUEST) { headerMessage.reset(); headerMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY); @@ -431,21 +429,6 @@ } } -// Finish the handling of the request -try { -thrA.setCurrentStage(endpoint, "endRequest"); -rp.setStage(org.apache.coyote.Constants.STAGE_ENDINPUT); -endRequest(); -// FXIME: Do one last flush -} catch (IOException e) { -error = true; -} catch (Throwable t) { -log.error("Error finishing request", t); -// 500 - Internal Server Error -response.setStatus(500); -error = true; -} - // If there was an error, make sure the request is counted as // and error, and update the statistics counter if (error) { @@ -459,9 +442,16 @@ } +// Add the socket to the poller +if (!error) { +endpoint.getPoller().add(socket, pool); +} else { +openSocket = false; +} + rp.setStage(org.apache.coyote.Constants.STAGE_ENDED); recycle(); - + return openSocket; } @@ -1122,7 +1112,7 @@ int headerLength = message.getHeaderLength(); // Read the message header -// FIXME: do crazy tricks to avoid doing two reads +// FIXME: better buffering to avoid doing two reads if (first) { int nRead = Socket.recvt (socket, buf, 0, headerLength, readTimeout); @@ -1131,7 +1121,7 @@ if (nRead == headerLength) { message.processHeader(); } else { -if (Status.APR_STATUS_IS_ETIMEDOUT(-nRead)) { +if ((-nRead) == Status.ETIMEDOUT || (-nRead) == Status.TIMEUP) { return false; } else { throw new IOException(sm.getString("iib.failedread")); @@ -1169,7 +1159,6 @@ */ protected void writeMessage(AjpMessage message) throws IOException { -// FIXME: Write to a temporary direct buffer message.end(); if (Socket.send(socket, message.getBuffer(), 0, message.getLen()) < 0) throw new IOException(sm.getString("iib.failedwrite")); @@ -1182,6 +1171,7 @@ public void recycle() { // Recycle Request object +first = true; request.recycle(); response.recycle(); headerMessage.reset(); - To unsubscribe, e-mail: [EMAIL PROTECTED] For add
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/06/15 10:35:24 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Fix uploading. Revision ChangesPath 1.3 +7 -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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AjpAprProcessor.java 15 Jun 2005 15:27:33 - 1.2 +++ AjpAprProcessor.java 15 Jun 2005 17:35:24 - 1.3 @@ -86,9 +86,6 @@ // Cause loading of HexUtils int foo = HexUtils.DEC[0]; -readBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK); -readBodyMessage.appendInt(Constants.MAX_READ_SIZE); - } @@ -1031,14 +1028,10 @@ public boolean receive() throws IOException { first = false; bodyMessage.reset(); -boolean err = readMessage(bodyMessage, false); +readMessage(bodyMessage, false); if( log.isDebugEnabled() ) -log.info( "Receiving: getting request body chunk " + err + " " + bodyMessage.getLen() ); +log.info( "Receiving: getting request body chunk " + bodyMessage.getLen() ); -if(err) { -throw new IOException(); -} - // No data received. if( bodyMessage.getLen() == 0 ) { // just the header // Don't mark 'end of stream' for the first chunk. @@ -1083,6 +1076,9 @@ } // Why not use outBuf?? +readBodyMessage.reset(); +readBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK); +readBodyMessage.appendInt(Constants.MAX_READ_SIZE); writeMessage(readBodyMessage); // In JNI mode, response will be in bodyMsg. In TCP mode, response need to be @@ -1172,6 +1168,8 @@ // Recycle Request object first = true; +endOfStream = false; +empty = true; request.recycle(); response.recycle(); headerMessage.reset(); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/06/23 04:50:34 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Add buffering for output. - This seems to work fine, but I didn't do that much testing yet. - Not done yet: input buffering is still missing, and it will likely be more significant (at least when there's a lot of upload). It's also harder, unfortunately :( Revision ChangesPath 1.6 +179 -106 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AjpAprProcessor.java 17 Jun 2005 09:43:35 - 1.5 +++ AjpAprProcessor.java 23 Jun 2005 11:50:34 - 1.6 @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.net.InetAddress; +import java.nio.ByteBuffer; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; @@ -84,11 +85,45 @@ response.setOutputBuffer(new SocketOutputBuffer()); request.setResponse(response); -readTimeout = endpoint.getFirstReadTimeout() * 1000; +if (endpoint.getFirstReadTimeout() > 0) { +readTimeout = endpoint.getFirstReadTimeout() * 1000; +} else { +readTimeout = 100 * 1000; +} // Cause loading of HexUtils int foo = HexUtils.DEC[0]; +// Allocate input and output buffers +inputBuffer = ByteBuffer.allocateDirect(16 * 1024); +outputBuffer = ByteBuffer.allocateDirect(16 * 1024); + +// Set the get body message buffer +AjpMessage getBodyMessage = new AjpMessage(); +getBodyMessage.reset(); +getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK); +getBodyMessage.appendInt(Constants.MAX_READ_SIZE); +getBodyMessage.end(); +getBodyMessageBuffer = ByteBuffer.allocateDirect(getBodyMessage.getLen()); +getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0, getBodyMessage.getLen()); + +// Set the read body message buffer +AjpMessage pongMessage = new AjpMessage(); +pongMessage.reset(); +pongMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY); +pongMessage.end(); +pongMessageBuffer = ByteBuffer.allocateDirect(pongMessage.getLen()); +pongMessageBuffer.put(pongMessage.getBuffer(), 0, pongMessage.getLen()); + +// Allocate the end message array +AjpMessage endMessage = new AjpMessage(); +endMessage.reset(); +endMessage.appendByte(Constants.JK_AJP13_END_RESPONSE); +endMessage.appendByte(1); +endMessage.end(); +endMessageArray = new byte[endMessage.getLen()]; +System.arraycopy(endMessage.getBuffer(), 0, endMessageArray, 0, endMessage.getLen()); + } @@ -118,13 +153,13 @@ * processing of the first message of a "request", so it might not be a request * header. It will stay unchanged during the processing of the whole request. */ -protected AjpMessage headerMessage = new AjpMessage(); +protected AjpMessage requestHeaderMessage = new AjpMessage(); /** - * Message used for output. + * Message used for response header composition. */ -protected AjpMessage outputMessage = new AjpMessage(); +protected AjpMessage responseHeaderMessage = new AjpMessage(); /** @@ -146,18 +181,6 @@ /** - * All purpose response message. - */ -protected AjpMessage responseMessage = new AjpMessage(); - - -/** - * Read body message. - */ -protected AjpMessage readBodyMessage = new AjpMessage(); - - -/** * State flag. */ protected boolean started = false; @@ -296,6 +319,39 @@ protected boolean finished = false; +/** + * Direct buffer used for output. + */ +protected ByteBuffer outputBuffer = null; + + +/** + * Direct buffer used for input. + */ +protected ByteBuffer inputBuffer = null; + + +/** + * Direct buffer used for sending right away a get body message. + * FIXME: can probably be static + */ +protected ByteBuffer getBodyMessageBuffer = null; + + +/** + * Direct buffer used for sending right away a pong message. + * FIXME: can probably be static + */ +protected ByteBuffer pongMessageBuffer = null; + + +/** + * End message array. + * FIXME: can probably be static
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/06/23 09:31:55 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Redo input, but somehow with no additional performance increase :( - My measurements seem to indicate that this is faster than regular AJP (which could probably use a more aggressive output buffering like I did), but with everything running on localhost, it's not exactly that great a benchmark. Poller only keepalives (firstReadTimeout="0" pollTime="2000") seems to be about as fast as regular AJP, which will mean minimum thread usage in Tomcat at no cost (provided previous performance levels were enough). Another fiding is that about 50% of the CPU usage is in Apache for some reason. - Hopefully this is reasonably bug free (don't expect that much though). Revision ChangesPath 1.7 +143 -87 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- AjpAprProcessor.java 23 Jun 2005 11:50:34 - 1.6 +++ AjpAprProcessor.java 23 Jun 2005 16:31:55 - 1.7 @@ -96,34 +96,9 @@ // Allocate input and output buffers inputBuffer = ByteBuffer.allocateDirect(16 * 1024); +inputBuffer.limit(0); outputBuffer = ByteBuffer.allocateDirect(16 * 1024); -// Set the get body message buffer -AjpMessage getBodyMessage = new AjpMessage(); -getBodyMessage.reset(); -getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK); -getBodyMessage.appendInt(Constants.MAX_READ_SIZE); -getBodyMessage.end(); -getBodyMessageBuffer = ByteBuffer.allocateDirect(getBodyMessage.getLen()); -getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0, getBodyMessage.getLen()); - -// Set the read body message buffer -AjpMessage pongMessage = new AjpMessage(); -pongMessage.reset(); -pongMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY); -pongMessage.end(); -pongMessageBuffer = ByteBuffer.allocateDirect(pongMessage.getLen()); -pongMessageBuffer.put(pongMessage.getBuffer(), 0, pongMessage.getLen()); - -// Allocate the end message array -AjpMessage endMessage = new AjpMessage(); -endMessage.reset(); -endMessage.appendByte(Constants.JK_AJP13_END_RESPONSE); -endMessage.appendByte(1); -endMessage.end(); -endMessageArray = new byte[endMessage.getLen()]; -System.arraycopy(endMessage.getBuffer(), 0, endMessageArray, 0, endMessage.getLen()); - } @@ -333,23 +308,58 @@ /** * Direct buffer used for sending right away a get body message. - * FIXME: can probably be static */ -protected ByteBuffer getBodyMessageBuffer = null; +protected static final ByteBuffer getBodyMessageBuffer; /** * Direct buffer used for sending right away a pong message. - * FIXME: can probably be static */ -protected ByteBuffer pongMessageBuffer = null; +protected static final ByteBuffer pongMessageBuffer; /** * End message array. - * FIXME: can probably be static */ -protected byte[] endMessageArray = null; +protected static final byte[] endMessageArray; + + +// - Static Initializer + + +static { + +// Set the get body message buffer +AjpMessage getBodyMessage = new AjpMessage(); +getBodyMessage.reset(); +getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK); +getBodyMessage.appendInt(Constants.MAX_READ_SIZE); +getBodyMessage.end(); +getBodyMessageBuffer = +ByteBuffer.allocateDirect(getBodyMessage.getLen()); +getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0, +getBodyMessage.getLen()); + +// Set the read body message buffer +AjpMessage pongMessage = new AjpMessage(); +pongMessage.reset(); +pongMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY); +pongMessage.end(); +pongMessageBuffer = ByteBuffer.allocateDirect(pongMessage.getLen()); +pongMessageBuffer.put(pongMessage.getBuffer(), 0, +pongMessage.getLen()); + +// Allocate the end message array +AjpMessage endMessage = new AjpMessage(); +endMessage.reset(); +endMessage.appendByte(Constants.JK_AJP13_END_RESPONSE); +endMessage.appendByte(1); +endMessage.en
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/07/27 12:29:16 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - After flushing, it's a good idea to write the data. - I did spend most time testing uploading, as obviously it's trivial to not mess up downloading. Revision ChangesPath 1.11 +7 -8 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- AjpAprProcessor.java 26 Jul 2005 16:13:33 - 1.10 +++ AjpAprProcessor.java 27 Jul 2005 19:29:16 - 1.11 @@ -1394,15 +1394,14 @@ if (outputBuffer.position() + thisTime + bodyMessage.getHeaderLength() + 4 > outputBuffer.capacity()) { flush(); -} else { -outputBuffer.put((byte) 0x41); -outputBuffer.put((byte) 0x42); -outputBuffer.putShort((short) (thisTime + 4)); -outputBuffer.put(AjpConstants.JK_AJP13_SEND_BODY_CHUNK); -outputBuffer.putShort((short) chunk.getLength()); -outputBuffer.put(chunk.getBytes(), chunk.getOffset() + off, thisTime); -outputBuffer.put((byte) 0x00); } +outputBuffer.put((byte) 0x41); +outputBuffer.put((byte) 0x42); +outputBuffer.putShort((short) (thisTime + 4)); +outputBuffer.put(AjpConstants.JK_AJP13_SEND_BODY_CHUNK); +outputBuffer.putShort((short) chunk.getLength()); +outputBuffer.put(chunk.getBytes(), chunk.getOffset() + off, thisTime); +outputBuffer.put((byte) 0x00); off += thisTime; } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/07/28 05:17:02 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Remove bad import. Revision ChangesPath 1.12 +1 -2 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.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- AjpAprProcessor.java 27 Jul 2005 19:29:16 - 1.11 +++ AjpAprProcessor.java 28 Jul 2005 12:17:02 - 1.12 @@ -32,7 +32,6 @@ import org.apache.coyote.Request; import org.apache.coyote.RequestInfo; import org.apache.coyote.Response; -import org.apache.jk.common.AjpConstants; import org.apache.tomcat.jni.Address; import org.apache.tomcat.jni.Sockaddr; import org.apache.tomcat.jni.Socket; @@ -1398,7 +1397,7 @@ outputBuffer.put((byte) 0x41); outputBuffer.put((byte) 0x42); outputBuffer.putShort((short) (thisTime + 4)); -outputBuffer.put(AjpConstants.JK_AJP13_SEND_BODY_CHUNK); +outputBuffer.put(Constants.JK_AJP13_SEND_BODY_CHUNK); outputBuffer.putShort((short) chunk.getLength()); outputBuffer.put(chunk.getBytes(), chunk.getOffset() + off, thisTime); outputBuffer.put((byte) 0x00); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/07/28 06:48:47 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Cleanup attribute parsing code (shouild be equivalent). Revision ChangesPath 1.13 +22 -27 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- AjpAprProcessor.java 28 Jul 2005 12:17:02 - 1.12 +++ AjpAprProcessor.java 28 Jul 2005 13:48:47 - 1.13 @@ -826,21 +826,13 @@ } // Decode extra attributes -boolean moreAttr = true; +byte attributeCode; +while ((attributeCode = requestHeaderMessage.getByte()) +!= Constants.SC_A_ARE_DONE) { -while (moreAttr) { -byte attributeCode = requestHeaderMessage.getByte(); -if (attributeCode == Constants.SC_A_ARE_DONE) -break; - -if (attributeCode == Constants.SC_A_SSL_KEY_SIZE) { -// Bug 1326: it's an Integer. -request.setAttribute(SSLSupport.KEY_SIZE_KEY, - new Integer(requestHeaderMessage.getInt())); -} - -if (attributeCode == Constants.SC_A_REQ_ATTRIBUTE ) { -// 2 strings ???... +switch (attributeCode) { + +case Constants.SC_A_REQ_ATTRIBUTE : requestHeaderMessage.getBytes(tmpMB); String n = tmpMB.toString(); requestHeaderMessage.getBytes(tmpMB); @@ -848,10 +840,8 @@ request.setAttribute(n, v); if (log.isTraceEnabled()) log.trace("jk Attribute set " + n + "=" + v); -} - -// 1 string attributes -switch (attributeCode) { +break; + case Constants.SC_A_CONTEXT : requestHeaderMessage.getBytes(tmpMB); // nothing @@ -890,7 +880,7 @@ case Constants.SC_A_SSL_CERT : request.scheme().setString("https"); -// SSL certificate extraction is costy, moved to JkCoyoteHandler +// SSL certificate extraction is lazy, moved to JkCoyoteHandler requestHeaderMessage.getBytes(certificates); break; @@ -908,21 +898,26 @@ tmpMB.toString()); break; +case Constants.SC_A_SSL_KEY_SIZE : +request.setAttribute(SSLSupport.KEY_SIZE_KEY, +new Integer(requestHeaderMessage.getInt())); +break; + +// FIXME: no usage for secret attribute here +/* case Constants.SC_A_SECRET : requestHeaderMessage.getBytes(tmpMB); -String secret = tmpMB.toString(); -if(log.isInfoEnabled()) -log.info("Secret: " + secret); -// FIXME: endpoint note - what's that ? -// endpoint.setNote(secretNote, secret); break; +*/ case Constants.SC_A_STORED_METHOD: requestHeaderMessage.getBytes(request.method()); break; default: -break; // ignore, we don't know about it - backward compat +// Ignore unknown attribute for backward compatibility +break; + } } @@ -1390,8 +1385,8 @@ thisTime = chunkSize; } len -= thisTime; -if (outputBuffer.position() + thisTime -+ bodyMessage.getHeaderLength() + 4 > outputBuffer.capacity()) { +if (outputBuffer.position() + thisTime + 4 + 4 > +outputBuffer.capacity()) { flush(); } outputBuffer.put((byte) 0x41); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/07/30 14:19:58 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Add a check for null certificates message bytes (that I forgot to cut & paste somehow). - Handling of addresses was wrong: AJP passes the remote and local addresses. Revision ChangesPath 1.15 +27 -100 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- AjpAprProcessor.java 29 Jul 2005 10:23:55 - 1.14 +++ AjpAprProcessor.java 30 Jul 2005 21:19:58 - 1.15 @@ -32,8 +32,6 @@ import org.apache.coyote.Request; import org.apache.coyote.RequestInfo; import org.apache.coyote.Response; -import org.apache.tomcat.jni.Address; -import org.apache.tomcat.jni.Sockaddr; import org.apache.tomcat.jni.Socket; import org.apache.tomcat.jni.Status; import org.apache.tomcat.util.buf.ByteChunk; @@ -598,115 +596,44 @@ } else if (actionCode == ActionCode.ACTION_REQ_SSL_ATTRIBUTE ) { -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(sm.getString("ajpprocessor.certs.fail"), e); -return; -} - -request.setAttribute(AprEndpoint.CERTIFICATE_KEY, jsseCerts); - -} else if (actionCode == ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE) { - -// Get remote host address -if (remoteAddr == null) { +if (!certificates.isNull()) { +ByteChunk certData = certificates.getByteChunk(); +X509Certificate jsseCerts[] = null; +ByteArrayInputStream bais = +new ByteArrayInputStream(certData.getBytes(), +certData.getStart(), +certData.getLength()); +// Fill the first element. try { -long sa = Address.get(Socket.APR_REMOTE, socket); -remoteAddr = Address.getip(sa); -} catch (Exception e) { -log.warn(sm.getString("ajpprocessor.socket.info"), e); -} -} -request.remoteAddr().setString(remoteAddr); - -} else if (actionCode == ActionCode.ACTION_REQ_LOCAL_NAME_ATTRIBUTE) { - -// Get local host name -if (localName == null) { -try { -long sa = Address.get(Socket.APR_LOCAL, socket); -localName = Address.getnameinfo(sa, 0); -} catch (Exception e) { -log.warn(sm.getString("ajpprocessor.socket.info"), e); +CertificateFactory cf = +CertificateFactory.getInstance("X.509"); +X509Certificate cert = (X509Certificate) +cf.generateCertificate(bais); +jsseCerts = new X509Certificate[1]; +jsseCerts[0] = cert; +request.setAttribute(AprEndpoint.CERTIFICATE_KEY, jsseCerts); +} catch (java.security.cert.CertificateException e) { +log.error(sm.getString("ajpprocessor.certs.fail"), e); +return; } } -request.localName().setString(localName); - + } else if (actionCode == ActionCode.ACTION_REQ_HOST_ATTRIBUTE) { -// Get remote host name -if (remoteHost == null) { +// Get remote host name using a DNS resolution +if (request.remoteHost().isNull()) { try { -long sa = Address.get(Socket.APR_REMOTE, socket); -remoteHost = Address.getnameinfo(sa, 0); -} catch (Exception e) { -log.warn(sm.getString
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java
remm2005/07/30 15:22:58 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java Log: - Remove now uneeded code. Revision ChangesPath 1.16 +0 -84 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- AjpAprProcessor.java 30 Jul 2005 21:19:58 - 1.15 +++ AjpAprProcessor.java 30 Jul 2005 22:22:57 - 1.16 @@ -139,12 +139,6 @@ /** - * Char version of the message header. - */ -//protected char[] headerChar = new char[8*1024]; - - -/** * Body message. */ protected AjpMessage bodyMessage = new AjpMessage(); @@ -169,54 +163,12 @@ /** - * Is there an expectation ? - */ -protected boolean expectation = false; - - -/** * Socket associated with the current connection. */ protected long socket; /** - * Remote Address associated with the current connection. - */ -protected String remoteAddr = null; - - -/** - * Remote Host associated with the current connection. - */ -protected String remoteHost = null; - - -/** - * Local Host associated with the current connection. - */ -protected String localName = null; - - -/** - * Local port to which the socket is connected - */ -protected int localPort = -1; - - -/** - * Remote port to which the socket is connected - */ -protected int remotePort = -1; - - -/** - * The local Host address. - */ -protected String localAddr = null; - - -/** * Host name (used to avoid useless B2C conversion on the host name). */ protected char[] hostNameC = new char[0]; @@ -382,13 +334,6 @@ thrA.setCurrentStage(endpoint, "parsing http request"); rp.setStage(org.apache.coyote.Constants.STAGE_PARSE); -// Set the remote address -remoteAddr = null; -remoteHost = null; -localAddr = null; -remotePort = -1; -localPort = -1; - // Setting up the socket this.socket = socket; @@ -531,18 +476,6 @@ error = true; } -} else if (actionCode == ActionCode.ACTION_ACK) { - -// Acknowlege request - -// Send a 100 status back if it makes sense (response not committed -// yet, and client specified an expectation for 100-continue) - -if ((response.isCommitted()) || !expectation) -return; - -// No expectations in AJP - } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) { if (!response.isCommitted()) { @@ -576,16 +509,6 @@ error = true; } -} else if (actionCode == ActionCode.ACTION_RESET) { - -// Reset response - -// Note: This must be called before the response is committed - -} else if (actionCode == ActionCode.ACTION_CUSTOM) { - -// Do nothing - } else if (actionCode == ActionCode.ACTION_START) { started = true; @@ -826,13 +749,6 @@ new Integer(requestHeaderMessage.getInt())); break; -// FIXME: no usage for secret attribute here -/* -case Constants.SC_A_SECRET : -requestHeaderMessage.getBytes(tmpMB); -break; -*/ - case Constants.SC_A_STORED_METHOD: requestHeaderMessage.getBytes(request.method()); break; - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java Constants.java
remm2005/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 ChangesPath 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 - 1.3 +++ AjpAprProcessor.java 16 Jun 2005 11:52:26 - 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) +
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java LocalStrings.properties
remm2005/06/23 09:35:27 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java LocalStrings.properties Log: - Fix a couple strings. Revision ChangesPath 1.8 +3 -3 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AjpAprProcessor.java 23 Jun 2005 16:31:55 - 1.7 +++ AjpAprProcessor.java 23 Jun 2005 16:35:26 - 1.8 @@ -1185,7 +1185,7 @@ if (nRead > 0) { inputBuffer.limit(inputBuffer.limit() + nRead); } else { -throw new IOException(sm.getString("iib.failedread")); +throw new IOException(sm.getString("ajpprotocol.failedread")); } } @@ -1220,7 +1220,7 @@ if ((-nRead) == Status.ETIMEDOUT || (-nRead) == Status.TIMEUP) { return false; } else { -throw new IOException(sm.getString("iib.failedread")); +throw new IOException(sm.getString("ajpprotocol.failedread")); } } } @@ -1356,7 +1356,7 @@ throws IOException { if (outputBuffer.position() > 0) { if (Socket.sendb(socket, outputBuffer, 0, outputBuffer.position()) < 0) { -throw new IOException(sm.getString("iib.failedwrite")); +throw new IOException(sm.getString("ajpprotocol.failedwrite")); } outputBuffer.clear(); } 1.2 +3 -2 jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/LocalStrings.properties Index: LocalStrings.properties === RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp/LocalStrings.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LocalStrings.properties 9 Jun 2005 16:14:51 - 1.1 +++ LocalStrings.properties 23 Jun 2005 16:35:27 - 1.2 @@ -20,4 +20,5 @@ ajpprotocol.endpoint.pauseerror=Error pausing endpoint ajpprotocol.resume=Resuming Coyote AJP/1.3 on {0} ajpprotocol.endpoint.resumeerror=Error resuming endpoint - +ajpprotocol.failedread=Socket read failed +ajpprotocol.failedwrite=Socket write failed - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java AjpMessage.java
remm2005/06/23 10:22:13 Modified:jk/java/org/apache/coyote/ajp AjpAprProcessor.java AjpMessage.java Log: - Beautify a little. Revision ChangesPath 1.9 +28 -32 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AjpAprProcessor.java 23 Jun 2005 16:35:26 - 1.8 +++ AjpAprProcessor.java 23 Jun 2005 17:22:13 - 1.9 @@ -52,6 +52,12 @@ * Processes HTTP requests. * * @author Remy Maucherat + * @author Henri Gomez + * @author Dan Milstein + * @author Keith Wannamaker + * @author Kevin Seguin + * @author Costin Manolache + * @author Bill Barker */ public class AjpAprProcessor implements ActionHook { @@ -412,6 +418,7 @@ return request; } + /** * Process pipelined HTTP requests using the specified input and output * streams. @@ -465,7 +472,6 @@ // Check message type, process right away and break if // not regular request processing int type = requestHeaderMessage.getByte(); -// FIXME: Any other types which should be checked ? if (type == Constants.JK_AJP13_CPING_REQUEST) { if (Socket.sendb(socket, pongMessageBuffer, 0, pongMessageBuffer.position()) < 0) { @@ -586,7 +592,7 @@ if ((response.isCommitted()) || !expectation) return; -// FIXME: No way to reply to an expectation in AJP ? +// No expectations in AJP } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) { @@ -751,14 +757,9 @@ } request.setLocalPort(localPort); -} else if (actionCode == ActionCode.ACTION_REQ_SSL_CERTIFICATE) { - -// FIXME: Nothing needed here ? - } else if (actionCode == ActionCode.ACTION_REQ_SET_BODY_REPLAY) { -if( log.isTraceEnabled() ) -log.trace("Replay "); +// Set the given bytes as the content ByteChunk bc = (ByteChunk) param; bodyBytes.setBytes(bc.getBytes(), bc.getStart(), bc.getLength()); first = false; @@ -819,7 +820,6 @@ boolean isSSL = requestHeaderMessage.getByte() != 0; if (isSSL) { -// XXX req.setSecure( true ); request.scheme().setString("https"); } @@ -880,13 +880,10 @@ if (attributeCode == Constants.SC_A_ARE_DONE) break; -/* Special case ( XXX in future API make it separate type !) - */ if (attributeCode == Constants.SC_A_SSL_KEY_SIZE) { // Bug 1326: it's an Integer. request.setAttribute(SSLSupport.KEY_SIZE_KEY, new Integer(requestHeaderMessage.getInt())); - //Integer.toString(msg.getInt())); } if (attributeCode == Constants.SC_A_REQ_ATTRIBUTE ) { @@ -944,21 +941,21 @@ requestHeaderMessage.getBytes(certificates); break; -case Constants.SC_A_SSL_CIPHER : -request.scheme().setString( "https" ); +case Constants.SC_A_SSL_CIPHER : +request.scheme().setString("https"); requestHeaderMessage.getBytes(tmpMB); request.setAttribute(SSLSupport.CIPHER_SUITE_KEY, tmpMB.toString()); break; -case Constants.SC_A_SSL_SESSION : -request.scheme().setString( "https" ); +case Constants.SC_A_SSL_SESSION : +request.scheme().setString("https"); requestHeaderMessage.getBytes(tmpMB); request.setAttribute(SSLSupport.SESSION_ID_KEY, tmpMB.toString()); break; -case Constants.SC_A_SECRET : +case Constants.SC_A_SECRET : requestHeaderMessage.getBytes(tmpMB); String secret = tmpMB.toString(); if(log.isInfoEnabled()) @@ -1097,8 +1094,9 @@ responseHeaderMessage.reset(); responseHeaderMessage.appendByte(Constants.JK_AJP13_SEND_HEADERS); -responseHeaderMessage.appendInt(response.getStatus()); +// HTTP header c
Re: cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java Constants.java LocalStrings.properties AjpAprProtocol.java AjpMessage.java
- Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, June 09, 2005 9:14 AM Subject: cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/coyote/ajp AjpAprProcessor.java Constants.java LocalStrings.properties AjpAprProtocol.java AjpMessage.java remm2005/06/09 09:14:51 Added: jk/java/org/apache/coyote/ajp AjpAprProcessor.java Constants.java LocalStrings.properties AjpAprProtocol.java AjpMessage.java Log: - Add my WIP AJP implementation using APR. Performance sucks right now, and I think it has lots of bugs ;) - It won't be compiled in or used for now. Yeah, it has a few bugs ;). Would it mess you up if I were to fix some of the more glaring ones in the CVS copy? I'm thinking mostly of the double call to endRequest, and the failure to clean up the Request body parameters. The handling of remote/localHost/Port is also wrong, but relatively harmless. Also the lack of C2B handling on the Response headers is going to bite you someday, but for initial testing on a iso-8859-1 machine it's alright. This message is intended only for the use of the person(s) listed above as the intended recipient(s), and may contain information that is PRIVILEGED and CONFIDENTIAL. If you are not an intended recipient, you may not read, copy, or distribute this message or any attachment. If you received this communication in error, please notify us immediately by e-mail and then delete all copies of this message and any attachments. In addition you should be aware that ordinary (unencrypted) e-mail sent through the Internet is not secure. Do not send confidential or sensitive information, such as social security numbers, account numbers, personal identification numbers and passwords, to us via ordinary (unencrypted) e-mail. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]