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/21 00:39:58 UTC
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/common ChannelSocket.java HandlerDispatch.java HandlerRequest.java JkInputStream.java
costin 02/02/20 15:39:58
Modified: jk/java/org/apache/jk/common ChannelSocket.java
HandlerDispatch.java HandlerRequest.java
JkInputStream.java
Log:
Replace our println log with commons-logging
Revision Changes Path
1.6 +33 -27 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ChannelSocket.java 6 Feb 2002 20:33:54 -0000 1.5
+++ ChannelSocket.java 20 Feb 2002 23:39:58 -0000 1.6
@@ -95,6 +95,8 @@
* @author Costin Manolache
*/
public class ChannelSocket extends Channel {
+ private static org.apache.commons.logging.Log log=
+ org.apache.commons.logging.LogFactory.getLog( ChannelSocket.class );
int port=8009;
InetAddress inet;
@@ -160,8 +162,8 @@
public void accept( MsgContext ep ) throws IOException {
Socket s=sSocket.accept();
ep.setNote( socketNote, s );
- if(dL>0 )
- d("Accepted socket " + s );
+ if(log.isDebugEnabled() )
+ log.debug("Accepted socket " + s );
if( linger > 0 )
s.setSoLinger( true, linger);
if( socketTimeout > 0 )
@@ -221,8 +223,8 @@
byte buf[]=msg.getBuffer();
int len=msg.getLen();
- if(dL > 5 )
- d("send() " + len + " " + buf[4] );
+ if(log.isTraceEnabled() )
+ log.trace("send() " + len + " " + buf[4] );
OutputStream os=(OutputStream)ep.getNote( osNote );
os.write( buf, 0, len );
@@ -232,8 +234,8 @@
public int receive( Msg msg, MsgContext ep )
throws IOException
{
- if (dL > 0) {
- d("receive()");
+ if (log.isDebugEnabled()) {
+ log.debug("receive()");
}
byte buf[]=msg.getBuffer();
@@ -248,6 +250,7 @@
if(rd < 0) {
// Most likely normal apache restart.
+ log.warn("Wrong message " + rd );
return rd;
}
@@ -265,18 +268,18 @@
total_read = this.read(ep, buf, hlen, blen);
if (total_read <= 0) {
- d("can't read body, waited #" + blen);
+ log.warn("can't read body, waited #" + blen);
return -1;
}
if (total_read != blen) {
- d( "incomplete read, waited #" + blen +
+ log.warn( "incomplete read, waited #" + blen +
" got only " + total_read);
return -2;
}
- if (dL > 0)
- d("receive: total read = " + total_read);
+ if (log.isDebugEnabled())
+ log.debug("receive: total read = " + total_read);
return total_read;
}
@@ -306,22 +309,23 @@
int pos = 0;
int got;
- if (dL > 5) {
- d("reading # " + b + " " + (b==null ? 0: b.length) + " " +
+ 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 (dL > 5) {
- d("read got # " + got);
+ if (log.isTraceEnabled()) {
+ log.trace("read got # " + got);
}
// connection just closed by remote.
if (got <= 0) {
// This happens periodically, as apache restarts
// periodically.
- // It should be more gracefull ! - another feature for Ajp14
+ // It should be more gracefull ! - another feature for Ajp14
+ log.warn( "Returning " );
return -3;
}
@@ -342,8 +346,8 @@
/** Accept incoming connections, dispatch to the thread pool
*/
void acceptConnections() {
- if( dL>0 )
- d("Accepting ajp connections on " + port);
+ if( log.isDebugEnabled() )
+ log.debug("Accepting ajp connections on " + port);
while( running ) {
try {
MsgContext ep=this.createEndpoint();
@@ -360,15 +364,22 @@
/** Process a single ajp connection.
*/
void processConnection(MsgContext ep) {
- if( dL > 0 )
- d( "New ajp connection ");
+ if( log.isDebugEnabled() )
+ log.debug( "New ajp connection ");
try {
MsgAjp recv=new MsgAjp();
while( running ) {
- this.receive( recv, ep );
- int status= this.invoke( recv, ep );
+ if( log.isDebugEnabled() )
+ log.debug("Receiving " );
+ int status= this.receive( recv, ep );
+ if( status <= 0 ) {
+ log.warn("Invalid packet, closing connection" );
+ break;
+ }
+
+ status= this.invoke( recv, ep );
if( status!= JkHandler.OK ) {
- d("processCallbacks status " + status );
+ log.warn("processCallbacks status " + status );
break;
}
}
@@ -419,11 +430,6 @@
}
- private static final int dL=0;
- private static void d(String s ) {
- System.err.println( "ChannelSocket: " + s );
- }
-
}
class SocketAcceptor implements ThreadPoolRunnable {
1.2 +8 -5 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerDispatch.java
Index: HandlerDispatch.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerDispatch.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HandlerDispatch.java 6 Feb 2002 17:41:29 -0000 1.1
+++ HandlerDispatch.java 20 Feb 2002 23:39:58 -0000 1.2
@@ -79,6 +79,8 @@
*/
public class HandlerDispatch extends JkHandler
{
+ private static org.apache.commons.logging.Log log=
+ org.apache.commons.logging.LogFactory.getLog( HandlerDispatch.class );
public HandlerDispatch()
{
@@ -97,8 +99,8 @@
public int registerMessageType( int id, String name, JkHandler h,
String sig[] )
{
- if( logL > 0 )
- log( "Register message " + id + " " + h.getName() +
+ if( log.isDebugEnabled() )
+ log.debug( "Register message " + id + " " + h.getName() +
" " + h.getClass().getName());
if( id < 0 ) {
// try to find it by name
@@ -128,12 +130,13 @@
if( type > handlers.length ||
handlers[type]==null ) {
- log( "Invalid handler " + type );
+ if( log.isDebugEnabled() )
+ log.debug( "Invalid handler " + type );
return ERROR;
}
- if( logL > 0 )
- log( "Received " + type + " " + handlers[type].getName());
+ if( log.isDebugEnabled() )
+ log.debug( "Received " + type + " " + handlers[type].getName());
JkHandler handler=handlers[type];
1.6 +37 -26 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HandlerRequest.java 7 Feb 2002 17:07:35 -0000 1.5
+++ HandlerRequest.java 20 Feb 2002 23:39:58 -0000 1.6
@@ -93,6 +93,9 @@
*/
public class HandlerRequest extends JkHandler
{
+ private static org.apache.commons.logging.Log log=
+ org.apache.commons.logging.LogFactory.getLog( HandlerRequest.class );
+
// XXX Will move to a registry system.
// Prefix codes for message types from server to container
@@ -199,12 +202,14 @@
"user-agent"
};
+ HandlerDispatch dispatch;
+ String ajpidDir="conf";
+
+
public HandlerRequest()
{
}
- HandlerDispatch dispatch;
-
public void init() {
dispatch=(HandlerDispatch)wEnv.getHandler( "dispatch" );
if( dispatch != null ) {
@@ -226,9 +231,12 @@
bodyNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "jkInputStream" );
tmpBufNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "tmpBuf" );
secretNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "secret" );
-
+
if( next==null )
next=wEnv.getHandler( "container" );
+ if( log.isDebugEnabled() )
+ log.debug( "Container handler " + next + " " + next.getName() +
+ " " + next.getClass().getName());
// should happen on start()
generateAjp13Id();
@@ -253,7 +261,12 @@
public void setTomcatAuthentication(boolean newTomcatAuthentication) {
tomcatAuthentication = newTomcatAuthentication;
}
-
+
+ public void setAjpidDir( String path ) {
+ if( "".equals( path ) ) path=null;
+ ajpidDir=path;
+ }
+
// -------------------- Ajp13.id --------------------
private void generateAjp13Id() {
@@ -265,14 +278,16 @@
File f1=new File( wEnv.getJkHome() );
File f2=new File( f1, "conf" );
+
if( ! f2.exists() ) {
- log( "No conf dir for ajp13.id " + f2 );
+ log.error( "No conf dir for ajp13.id " + f2 );
return;
}
File sf=new File( f2, "ajp13.id");
- if( dL > 0) d( "Using stop file: "+sf);
+ if( log.isDebugEnabled())
+ log.debug( "Using stop file: "+sf);
try {
Properties props=new Properties();
@@ -288,7 +303,7 @@
FileOutputStream stopF=new FileOutputStream( sf );
props.save( stopF, "Automatically generated, don't edit" );
} catch( IOException ex ) {
- d( "Can't create stop file: "+sf );
+ log.debug( "Can't create stop file: "+sf );
ex.printStackTrace();
}
}
@@ -312,7 +327,8 @@
tmpMB=new MessageBytes();
ep.setNote( tmpBufNote, tmpMB);
}
-
+ log.debug( "Handling " + type );
+
switch( type ) {
case JK_AJP13_FORWARD_REQUEST:
decodeRequest( msg, ep, tmpMB );
@@ -323,12 +339,13 @@
return ERROR;
}
/* XXX it should be computed from request, by workerEnv */
- if(dL >0 )
- d("Calling next " + next.getName() + " " +
+ if(log.isDebugEnabled() )
+ log.debug("Calling next " + next.getName() + " " +
next.getClass().getName());
- return next.invoke( msg, ep );
-
+ int err= next.invoke( msg, ep );
+ log.debug( "Invoke returned " + err );
+ return err;
case JK_AJP13_SHUTDOWN:
String epSecret=null;
if( msg.getLen() > 3 ) {
@@ -339,7 +356,7 @@
if( requiredSecret != null &&
requiredSecret.equals( epSecret ) ) {
- d("Received wrong secret, no shutdown ");
+ log.debug("Received wrong secret, no shutdown ");
return ERROR;
}
@@ -347,7 +364,7 @@
Channel ch=ep.getChannel();
if( ch instanceof ChannelSocket ) {
if( ! ((ChannelSocket)ch).isSameAddress(ep) ) {
- d("Shutdown request not from 'same address' ");
+ log.error("Shutdown request not from 'same address' ");
return ERROR;
}
}
@@ -355,7 +372,7 @@
// forward to the default handler - it'll do the shutdown
next.invoke( msg, ep );
- d("Exiting");
+ log.info("Exiting");
System.exit(0);
return OK;
@@ -420,8 +437,8 @@
jkBody.receive();
}
- if (dL > 5) {
- d(req.toString());
+ if (log.isTraceEnabled()) {
+ log.trace(req.toString());
}
return OK;
@@ -505,7 +522,7 @@
jsseCerts = new X509Certificate[1];
jsseCerts[0] = cert;
} catch(java.security.cert.CertificateException e) {
- d("Certificate convertion failed" + e );
+ log.error("Certificate convertion failed" + e );
e.printStackTrace();
}
@@ -530,7 +547,7 @@
case SC_A_SECRET :
msg.getBytes(tmpMB);
String secret=tmpMB.toString();
- d("Secret: " + secret );
+ log.info("Secret: " + secret );
// endpoint note
ep.setNote( secretNote, secret );
break;
@@ -590,10 +607,4 @@
}
}
- private static final int dL=4;
- private static void d(String s ) {
- System.err.println( "HandlerRequest: " + s );
- }
-
-
- }
+}
1.2 +20 -19 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JkInputStream.java 6 Feb 2002 17:11:30 -0000 1.1
+++ JkInputStream.java 20 Feb 2002 23:39:58 -0000 1.2
@@ -81,6 +81,8 @@
/** Generic input stream impl on top of ajp
*/
public class JkInputStream extends InputStream {
+ private static org.apache.commons.logging.Log log=
+ org.apache.commons.logging.LogFactory.getLog( JkInputStream.class );
public JkInputStream() {
}
@@ -109,7 +111,8 @@
return doRead1();
}
if( available <= 0 ) {
- if( dL>0 ) d("doRead() nothing available" );
+ if( log.isDebugEnabled() )
+ log.debug("doRead() nothing available" );
return -1;
}
available--;
@@ -124,13 +127,14 @@
return rd;
}
if( available <= 0 ) {
- if( dL>0 ) d("doRead() nothing available" );
+ if( log.isDebugEnabled() ) log.debug("doRead() nothing available" );
return -1;
}
rd=doRead1( b,off, len );
available -= rd;
- if( dL > 0 ) d("Read: " + new String( b,off, len ));
+ if( log.isDebugEnabled() )
+ log.debug("Read: " + new String( b,off, len ));
return rd;
}
@@ -173,7 +177,7 @@
boolean end_of_stream; // true if we've received an empty packet
private int doRead1() throws IOException {
- if( dL>0 ) d("doRead1 " );
+ if( log.isDebugEnabled() ) log.debug("doRead1 " );
if(pos >= blen) {
if( ! refillReadBuffer()) {
return -1;
@@ -184,7 +188,7 @@
public int doRead1(byte[] b, int off, int len) throws IOException
{
- if( dL>0 ) d("doRead1 " );
+ if( log.isDebugEnabled() ) log.debug("doRead1 " );
if(pos >= blen) {
if( ! refillReadBuffer()) {
return -1;
@@ -194,8 +198,8 @@
if(pos + len <= blen) { // Fear the off by one error
// Sanity check b.length > off + len?
System.arraycopy(bodyBuff, pos, b, off, len);
- if( dL > 0 )
- d("doRead1: " + pos + " " + len + " " + blen + " " +
+ if( log.isDebugEnabled() )
+ log.debug("doRead1: " + pos + " " + len + " " + blen + " " +
new String( b, off, len ) + " " + Thread.currentThread());
pos += len;
return len;
@@ -210,9 +214,10 @@
int c = bytesRemaining < toCopy ? bytesRemaining : toCopy;
System.arraycopy(bodyBuff, pos, b, off, c);
- if( dL > 0 ) d("doRead2: " + pos + " " + len + " " + blen + " " +
- c + " " + new String( b, off, c ) + " " +
- new String( bodyBuff, pos, c ));
+ if( log.isDebugEnabled() )
+ log.debug("doRead2: " + pos + " " + len + " " + blen + " " +
+ c + " " + new String( b, off, c ) + " " +
+ new String( bodyBuff, pos, c ));
toCopy -= c;
@@ -274,8 +279,8 @@
blen = bodyMsg.peekInt();
pos = 0;
int cpl=bodyMsg.getBytes(bodyBuff);
- if( dL > 0 )
- d( "Copy into body buffer2 " + bodyBuff + " " +
+ if( log.isDebugEnabled() )
+ log.debug( "Copy into body buffer2 " + bodyBuff + " " +
cpl + " " + blen + " " +
new String( bodyBuff, 0, cpl ));
@@ -293,7 +298,7 @@
// If the server returns an empty packet, assume that that end of
// the stream has been reached (yuck -- fix protocol??).
if (end_of_stream) {
- if( dL>0 ) d("refillReadBuffer: end of stream " );
+ if( log.isDebugEnabled() ) log.debug("refillReadBuffer: end of stream " );
return false;
}
@@ -302,16 +307,12 @@
bodyMsg.appendByte(JK_AJP13_GET_BODY_CHUNK);
bodyMsg.appendInt(MAX_READ_SIZE);
- if( dL>0 ) d("refillReadBuffer " + Thread.currentThread());
+ if( log.isDebugEnabled() )
+ log.debug("refillReadBuffer " + Thread.currentThread());
mc.getChannel().send(bodyMsg, mc);
return receive();
- }
-
- private static final int dL=10;
- private static void d(String s ) {
- System.err.println( "JkInputStream: " + s );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>