You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2002/02/27 07:41:18 UTC
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common ChannelSocket.java HandlerRequest.java JkInputStream.java MsgAjp.java
costin 02/02/26 22:41:18
Modified: jk/java/org/apache/jk/common ChannelSocket.java
HandlerRequest.java JkInputStream.java MsgAjp.java
Log:
More debug cleanup and improvements.
The Content-Length header may be sent either as an id or as a string.
( a patch for requestutil.c to deal with mixed chars is almost done ).
The problem is that if we use 'native' map, the headers are the
ones in request_rec, not our lower-cased copy.
Revision Changes Path
1.7 +4 -13 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java
Index: ChannelSocket.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ChannelSocket.java 20 Feb 2002 23:39:58 -0000 1.6
+++ ChannelSocket.java 27 Feb 2002 06:41:18 -0000 1.7
@@ -235,7 +235,7 @@
throws IOException
{
if (log.isDebugEnabled()) {
- log.debug("receive()");
+ log.debug("receive() ");
}
byte buf[]=msg.getBuffer();
@@ -278,8 +278,6 @@
return -2;
}
- if (log.isDebugEnabled())
- log.debug("receive: total read = " + total_read);
return total_read;
}
@@ -309,15 +307,12 @@
int pos = 0;
int got;
- if (log.isTraceEnabled()) {
- log.trace("reading # " + b + " " + (b==null ? 0: b.length) + " " +
- offset + " " + len);
- }
while(pos < len) {
got = is.read(b, pos + offset, len - pos);
if (log.isTraceEnabled()) {
- log.trace("read got # " + got);
+ log.trace("read() " + b + " " + (b==null ? 0: b.length) + " " +
+ offset + " " + len + " = " + got );
}
// connection just closed by remote.
@@ -325,7 +320,7 @@
// This happens periodically, as apache restarts
// periodically.
// It should be more gracefull ! - another feature for Ajp14
- log.warn( "Returning " );
+ log.warn( "Read result -1, connection close by server" );
return -3;
}
@@ -364,13 +359,9 @@
/** Process a single ajp connection.
*/
void processConnection(MsgContext ep) {
- if( log.isDebugEnabled() )
- log.debug( "New ajp connection ");
try {
MsgAjp recv=new MsgAjp();
while( running ) {
- if( log.isDebugEnabled() )
- log.debug("Receiving " );
int status= this.receive( recv, ep );
if( status <= 0 ) {
log.warn("Invalid packet, closing connection" );
1.7 +11 -3 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerRequest.java
Index: HandlerRequest.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerRequest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HandlerRequest.java 20 Feb 2002 23:39:58 -0000 1.6
+++ HandlerRequest.java 27 Feb 2002 06:41:18 -0000 1.7
@@ -331,7 +331,13 @@
switch( type ) {
case JK_AJP13_FORWARD_REQUEST:
- decodeRequest( msg, ep, tmpMB );
+ try {
+ decodeRequest( msg, ep, tmpMB );
+ } catch( Exception ex ) {
+ log.error( "Error decoding request ", ex );
+ msg.dump( "Incomming message");
+ return ERROR;
+ }
if( requiredSecret != null ) {
String epSecret=(String)ep.getNote( secretNote );
@@ -593,11 +599,13 @@
vMB=headers.addValue( hName );
msg.getBytes(vMB);
- if (hId == SC_REQ_CONTENT_LENGTH) {
+ if (hId == SC_REQ_CONTENT_LENGTH ||
+ hName.equalsIgnoreCase("Content-Length")) {
// just read the content-length header, so set it
int contentLength = (vMB == null) ? -1 : vMB.getInt();
req.setContentLength(contentLength);
- } else if (hId == SC_REQ_CONTENT_TYPE) {
+ } else if (hId == SC_REQ_CONTENT_TYPE ||
+ hName.equalsIgnoreCase("Content-Type")) {
// just read the content-type header, so set it
ByteChunk bchunk = vMB.getByteChunk();
req.contentType().setBytes(bchunk.getBytes(),
1.3 +25 -11 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkInputStream.java
Index: JkInputStream.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkInputStream.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JkInputStream.java 20 Feb 2002 23:39:58 -0000 1.2
+++ JkInputStream.java 27 Feb 2002 06:41:18 -0000 1.3
@@ -88,10 +88,14 @@
}
public int available() throws IOException {
+ if( log.isDebugEnabled() )
+ log.debug( "available(): " + blen + " " + pos );
return blen-pos;
}
public void close() throws IOException {
+ if( log.isDebugEnabled() )
+ log.debug( "cloae() " );
this.closed=true;
}
@@ -119,7 +123,14 @@
return doRead1();
}
-
+
+ public int read(byte[] b) throws IOException {
+ int rd=read( b, 0, b.length);
+ if( log.isDebugEnabled() )
+ log.debug("read(" + b + ")=" + rd + " / " + b.length);
+ return rd;
+ }
+
public int read(byte[] b, int off, int len) throws IOException {
int rd=-1;
if( contentLength == -1 ) {
@@ -177,18 +188,18 @@
boolean end_of_stream; // true if we've received an empty packet
private int doRead1() throws IOException {
- if( log.isDebugEnabled() ) log.debug("doRead1 " );
if(pos >= blen) {
if( ! refillReadBuffer()) {
return -1;
}
}
- return bodyBuff[pos++] & 0xFF; // prevent sign extension of byte value
+ int i=bodyBuff[pos++] & 0xFF;
+ if( log.isDebugEnabled() ) log.debug("doRead1 " + (char)i );
+ return i; // prevent sign extension of byte value
}
public int doRead1(byte[] b, int off, int len) throws IOException
{
- if( log.isDebugEnabled() ) log.debug("doRead1 " );
if(pos >= blen) {
if( ! refillReadBuffer()) {
return -1;
@@ -199,8 +210,9 @@
// Sanity check b.length > off + len?
System.arraycopy(bodyBuff, pos, b, off, len);
if( log.isDebugEnabled() )
- log.debug("doRead1: " + pos + " " + len + " " + blen + " " +
- new String( b, off, len ) + " " + Thread.currentThread());
+ log.debug("doRead1: " + pos + " " + len + " " + blen);
+ if( log.isTraceEnabled() )
+ log.trace("Data: \n" + new String( b, off, len ));
pos += len;
return len;
}
@@ -215,9 +227,10 @@
System.arraycopy(bodyBuff, pos, b, off, c);
if( log.isDebugEnabled() )
- log.debug("doRead2: " + pos + " " + len + " " + blen + " " +
- c + " " + new String( b, off, c ) + " " +
- new String( bodyBuff, pos, c ));
+ log.debug("doRead2: " + pos + " " + len + " " +
+ blen + " " + c);
+ if( log.isTraceEnabled() )
+ log.trace("Data: \n" + new String( b, off, len ));
toCopy -= c;
@@ -281,8 +294,9 @@
int cpl=bodyMsg.getBytes(bodyBuff);
if( log.isDebugEnabled() )
log.debug( "Copy into body buffer2 " + bodyBuff + " " +
- cpl + " " + blen + " " +
- new String( bodyBuff, 0, cpl ));
+ cpl + " " + blen );
+ if( log.isTraceEnabled() )
+ log.trace( "Data:\n" + new String( bodyBuff, 0, cpl ));
return (blen > 0);
}
1.6 +25 -30 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/MsgAjp.java
Index: MsgAjp.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/MsgAjp.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MsgAjp.java 6 Feb 2002 17:48:52 -0000 1.5
+++ MsgAjp.java 27 Feb 2002 06:41:18 -0000 1.6
@@ -89,6 +89,8 @@
* @author Costin Manolache
*/
public class MsgAjp extends Msg {
+ private static org.apache.commons.logging.Log log=
+ org.apache.commons.logging.LogFactory.getLog( MsgAjp.class );
private byte buf[]=new byte[8300];
// The current read or write position in the buffer
@@ -181,8 +183,8 @@
}
public void appendByteChunk(ByteChunk bc) throws IOException {
- if(bc==null ) {
- System.out.println("XXX appending BC null" + bc);
+ if(bc==null) {
+ log.error("appendByteChunk() null");
appendInt( 0);
appendByte(0);
return;
@@ -208,8 +210,8 @@
*/
public void appendBytes( byte b[], int off, int numBytes ) {
if( pos + numBytes >= buf.length ) {
- System.out.println("Buffer overflow " + buf.length + " " +
- pos + " " + numBytes );
+ log.error( "Buffer overflow buf.len" + buf.length + " pos=" +
+ pos + " data=" + numBytes );
return;
}
appendInt( numBytes );
@@ -219,8 +221,8 @@
private void cpBytes( byte b[], int off, int numBytes ) {
if( pos + numBytes >= buf.length ) {
- System.out.println("Buffer overflow " + buf.length + " " +
- pos + " " + numBytes );
+ log.error("Buffer overflow: buffer.len=" + buf.length + " pos=" +
+ pos + " data=" + numBytes );
return;
}
System.arraycopy( b, off, buf, pos, numBytes);
@@ -284,11 +286,11 @@
int length = getInt();
if( length > buf.length ) {
// XXX Should be if(pos + length > buff.legth)?
- System.out.println("XXX Assert failed, buff too small ");
+ log.error("Try to get data after the end of the buffer");
}
if( (length == 0xFFFF) || (length == -1) ) {
- System.out.println("null string " + length);
+ log.info("Null string " + length);
return 0;
}
@@ -326,45 +328,45 @@
if( mark != 0x1234 ) {
// XXX Logging
- System.out.println("BAD packet " + mark);
+ log.error("BAD packet signature " + mark);
dump( "In: " );
return -1;
}
-
- if( dL > 5 )
- d( "Received " + len + " " + buf[0] );
+
+ if( log.isDebugEnabled() )
+ log.debug( "Received " + len + " " + buf[0] );
return len;
}
public void dump(String msg) {
- System.out.println( msg + ": " + buf + " " + pos +"/" + (len + 4));
+ log.debug( msg + ": " + buf + " " + pos +"/" + (len + 4));
int max=pos;
if( len + 4 > pos )
max=len+4;
for( int j=0; j < max; j+=16 )
- hexLine( buf, j, len );
+ System.out.println( hexLine( buf, j, len ));
- System.out.println();
}
/* -------------------- Utilities -------------------- */
// XXX Move to util package
- public static void hexLine( byte buf[], int start, int len ) {
+ public static String hexLine( byte buf[], int start, int len ) {
+ StringBuffer sb=new StringBuffer();
for( int i=start; i< start+16 ; i++ ) {
if( i < len + 4)
- System.out.print( hex( buf[i] ) + " ");
+ sb.append( hex( buf[i] ) + " ");
else
- System.out.print( " " );
+ sb.append( " " );
}
- System.out.print(" | ");
+ sb.append(" | ");
for( int i=start; i < start+16 && i < len + 4; i++ ) {
- if( Character.isLetterOrDigit( (char)buf[i] ))
- System.out.print( new Character((char)buf[i]) );
+ if( ! Character.isISOControl( (char)buf[i] ))
+ sb.append( new Character((char)buf[i]) );
else
- System.out.print( "." );
+ sb.append( "." );
}
- System.out.println();
+ return sb.toString();
}
private static String hex( int x ) {
@@ -374,11 +376,4 @@
return h.substring( h.length() - 2 );
}
-
- private static final int dL=0;
- private static void d(String s ) {
- System.err.println( "MsgAjp: " + s );
- }
-
-
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>