costin 02/04/08 15:59:37 Modified: jk/java/org/apache/jk/server JkCoyoteHandler.java Log: More impl. Now it kind-of-works ( something is broken in headers, but close ) Revision Changes Path 1.4 +142 -14 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JkCoyoteHandler.java 6 Apr 2002 17:02:47 -0000 1.3 +++ JkCoyoteHandler.java 8 Apr 2002 22:59:37 -0000 1.4 @@ -76,15 +76,24 @@ /** Plugs Jk2 into Coyote */ -public class JkCoyoteHandler extends JkHandler implements ProtocolHandler, ActionHook +public class JkCoyoteHandler extends JkHandler implements + ProtocolHandler, ActionHook { + protected static org.apache.commons.logging.Log log + = org.apache.commons.logging.LogFactory.getLog(JkCoyoteHandler.class); + int headersMsgNote; + int c2bConvertersNote; + int utfC2bNote; + int obNote; + int epNote; + Adapter adapter; protected JkMain jkMain=new JkMain(); /** Pass config info */ public void setAttribute( String name, Object value ) { - System.out.println("Set attribute " + name + " " + value ); + log.info("setAttribute " + name + " " + value ); } public Object getAttribute( String name ) { @@ -114,6 +123,14 @@ try { jkMain.init(); jkMain.start(); + + log.info("Jk2 started "); + + headersMsgNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "headerMsg" ); + utfC2bNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "utfC2B" ); + epNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "ep" ); + obNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "coyoteBuffer" ); + } catch( Exception ex ) { ex.printStackTrace(); } @@ -122,16 +139,71 @@ public void destroy() { // jkMain.stop(); } + // -------------------- OutputBuffer implementation -------------------- + static class JkCoyoteBuffers implements org.apache.coyote.OutputBuffer, + org.apache.coyote.InputBuffer + { + int epNote; + int headersMsgNote; + org.apache.coyote.Response res; + + void setResponse( org.apache.coyote.Response res ) { + this.res=res; + } + + public int doWrite(ByteChunk chunk) + throws IOException + { + if( log.isInfoEnabled() ) + log.info("doWrite " ); + MsgContext ep=(MsgContext)res.getNote( epNote ); + + MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote ); + msg.reset(); + msg.appendByte( HandlerRequest.JK_AJP13_SEND_BODY_CHUNK); + msg.appendBytes( chunk.getBytes(), chunk.getOffset(), chunk.getLength() ); + ep.getChannel().send( msg, ep ); + + return 0; + } + + public int doRead(ByteChunk chunk) + throws IOException + { + if( log.isInfoEnabled() ) + log.info("doRead " ); + return 0; + } + } + // -------------------- Jk handler implementation -------------------- // Jk Handler mehod public int invoke( Msg msg, MsgContext ep ) throws IOException { - System.out.println("XXX Invoke " ); org.apache.coyote.Request req=(org.apache.coyote.Request)ep.getRequest(); org.apache.coyote.Response res=req.getResponse(); res.setHook( this ); + + JkCoyoteBuffers ob=(JkCoyoteBuffers)res.getNote( obNote ); + if( ob == null ) { + // Buffers not initialized yet + // Workaround - IB, OB require state. + ob=new JkCoyoteBuffers(); + ob.epNote=epNote; + ob.headersMsgNote=headersMsgNote; + ob.setResponse(res); + res.setOutputBuffer( ob ); + req.setInputBuffer( ob ); + + Msg msg2=new MsgAjp(); + ep.setNote( headersMsgNote, msg ); + + res.setNote( obNote, ob ); + } + res.setNote( epNote, ep ); + try { adapter.service( req, res ); } catch( Exception ex ) { @@ -140,18 +212,74 @@ return OK; } + // -------------------- Coyote Action implementation -------------------- + public void action(ActionCode actionCode, Object param) { - System.out.println("XXX Action " + actionCode + " " + param ); - if( actionCode==ActionCode.ACTION_COMMIT ) { - - } - if( actionCode==ActionCode.ACTION_RESET ) { - - } - if( actionCode==ActionCode.ACTION_CLOSE ) { - } - if( actionCode==ActionCode.ACTION_ACK ) { - + try { + if( actionCode==ActionCode.ACTION_COMMIT ) { + if( log.isInfoEnabled() ) + log.info("COMMIT sending headers " ); + + org.apache.coyote.Response res=(org.apache.coyote.Response)param; + + C2B c2b=(C2B)res.getNote( utfC2bNote ); + if( c2b==null ) { + c2b=new C2B( "UTF8" ); + res.setNote( utfC2bNote, c2b ); + } + + MsgContext ep=(MsgContext)res.getNote( epNote ); + MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote ); + msg.reset(); + msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS); + msg.appendInt( res.getStatus() ); + + // s->b conversion, message + msg.appendBytes( null ); + + // XXX add headers + + MimeHeaders headers=res.getMimeHeaders(); + int numHeaders = headers.size(); + msg.appendInt(numHeaders); + for( int i=0; i<numHeaders; i++ ) { + MessageBytes hN=headers.getName(i); + // no header to sc conversion - there's little benefit + // on this direction + c2b.convert ( hN ); + msg.appendBytes( hN ); + + MessageBytes hV=headers.getValue(i); + c2b.convert( hV ); + msg.appendBytes( hV ); + } + ep.getChannel().send( msg, ep ); + } + if( actionCode==ActionCode.ACTION_RESET ) { + if( log.isInfoEnabled() ) + log.info("RESET " ); + + } + if( actionCode==ActionCode.ACTION_CLOSE ) { + if( log.isInfoEnabled() ) + log.info("CLOSE " ); + org.apache.coyote.Response res=(org.apache.coyote.Response)param; + MsgContext ep=(MsgContext)res.getNote( epNote ); + + MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote ); + msg.reset(); + msg.appendByte( HandlerRequest.JK_AJP13_END_RESPONSE ); + msg.appendInt( 1 ); + + ep.getChannel().send(msg, ep ); + } + if( actionCode==ActionCode.ACTION_ACK ) { + if( log.isInfoEnabled() ) + log.info("ACK " ); + + } + } catch( Exception ex ) { + log.error( "Error in action code ", ex ); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>