costin 02/01/06 00:50:56 Modified: jk/java/org/apache/jk/server JkMain.java JkServlet.java Log: JkServlet is now functional. For 3.3 you can just add jk or a symlink to modules. For 4.0 you just need to add the declaration for the 'trusted' app in server.xml _and_ copy the jar files in servler/lib ( that will not be needed in 4.1 ). The 3.3 impl is working ( at least simple servlets/jsps). I still have some lines to add to the 4.0 impl ( but it starts fine and receives the request ). Revision Changes Path 1.3 +34 -7 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java Index: JkMain.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JkMain.java 5 Jan 2002 10:03:43 -0000 1.2 +++ JkMain.java 6 Jan 2002 08:50:56 -0000 1.3 @@ -78,27 +78,53 @@ public class JkMain { WorkerEnv wEnv=new WorkerEnv(); + String propFile; + Properties props; + + Worker defaultWorker; public JkMain() { } - + public void setPropFile( String p ) { + propFile=p; + props=new Properties(); + try { + props.load( new FileInputStream(propFile) ); + } catch(IOException ex ){ + ex.printStackTrace(); + } + } + + public void setProperties( Properties p ) { + props=p; + } + + public void setDefaultWorker( Worker w ) { + defaultWorker=w; + } + public void start() throws IOException { - ChannelSocket csocket=new ChannelSocket(); + ChannelUn csocket=new ChannelUn(); + csocket.setFile( "/tmp/tomcatApr" ); + /* ChannelSocket csocket=new ChannelSocket(); csocket.setPort( 8009 ); + */ /* ChannelUnixSocket csocket=new ChannelUnixSocket(); // JFC tests - wEnv.addChannel( csocket ); */ + wEnv.addChannel( csocket ); + + if( defaultWorker == null ) + defaultWorker=new WorkerDummy(); - WorkerDummy wdummy=new WorkerDummy(); - csocket.setWorker( wdummy ); - wEnv.addWorker( wdummy ); + csocket.setWorker( defaultWorker ); + wEnv.addWorker( defaultWorker ); HandlerRequest hReq=new HandlerRequest(); wEnv.addHandler( hReq ); - hReq.setWorker( wdummy ); + hReq.setWorker( defaultWorker ); HandlerEcho hEcho=new HandlerEcho(); wEnv.addHandler( hEcho ); @@ -118,6 +144,7 @@ String propFile=args[0]; JkMain jkMain=new JkMain(); + jkMain.setPropFile(propFile); jkMain.start(); } catch( Exception ex ) { ex.printStackTrace(); 1.2 +102 -1 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkServlet.java Index: JkServlet.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JkServlet.java 31 Dec 2001 19:09:59 -0000 1.1 +++ JkServlet.java 6 Jan 2002 08:50:56 -0000 1.2 @@ -78,9 +78,110 @@ * It'll just start/init jk and use a dummy endpoint ( i.e. no servlet * container ). */ -public class JkServlet +public class JkServlet extends HttpServlet { + String password; + String user; + /* Parameters for the ajp channel */ + String port; + String host; /* If it starts with '/' we'll use ud */ + ServletContext sctx; + public JkServlet() { } + + protected Properties servletConfig2properties(ServletConfig conf ) { + Properties props=new Properties(); + Enumeration paramNE=conf.getInitParameterNames(); + while( paramNE.hasMoreElements() ){ + String s=(String)paramNE.nextElement(); + String v=conf.getInitParameter(s); + + props.put( s, v ); + } + return props; + } + + + public void init(ServletConfig conf) throws ServletException { + super.init(conf); + sctx=conf.getServletContext(); + getServletAdapter(); + } + + /* Ok, this is a bit hacky - there is ( or I couldn't find ) any clean + way to access tomcat40 internals without implementing the interface, + and that will brake 3.3 ( and probably other things ). + + It does seem to work for 4.0, and in future we can add a tomcat40 valve/whatever + that will provide an Attribute for 'trusted' apps with pointer to + the internals. + */ + private void getServletAdapter() { + try40(); + try33(); + } + + private void try33() { + // 33 ? + try { + JkServlet t33=(JkServlet)newInstance( "org.apache.jk.server.tomcat33.JkServlet33" ); + if( t33 == null ) { + d("3.3 not detected or untrusted app"); + return; + } + t33.initializeContainer( getServletConfig()); + } catch( Exception ex ) { + ex.printStackTrace(); + } + } + + private void try40() { + // 4.x ? + try { + HttpServletRequest req=(HttpServletRequest) + newInstance( "org.apache.catalina.connector.HttpRequestBase"); + if( req==null ) { + d("4.0 not detected or untrusted app"); + return; + } + HttpServletResponse res=(HttpServletResponse) + newInstance( "org.apache.catalina.connector.HttpResponseBase"); + + RequestDispatcher rd= + sctx.getNamedDispatcher( "JkServlet40" ); + if( rd==null ) return; + + try { + rd.include( req, res ); + } catch( Exception ex ) { + ex.printStackTrace(); + // ignore it - what would you expect, we pass dummy objects + } + } catch( Exception ex ) { + ex.printStackTrace(); + } + } + + private Object newInstance( String s ) { + try { + Class c=Class.forName( s ); + return c.newInstance(); + } catch( Exception ex ) { + // ex.printStackTrace(); + return null; + } + } + + public void initializeContainer(ServletConfig cfg) { + } + + + private static final int dL=0; + private static void d(String s ) { + System.err.println( "JkServlet: " + s ); + } } + +
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>