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/01/06 09:52:38 UTC
cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/server/tomcat33 JkRequest33.java JkResponse33.java JkServlet33.java Worker33.java Ajp14Interceptor.java
costin 02/01/06 00:52:38
Added: jk/java/org/apache/jk/server/tomcat33 JkRequest33.java
JkResponse33.java JkServlet33.java Worker33.java
Removed: jk/java/org/apache/jk/server/tomcat33 Ajp14Interceptor.java
Log:
Remove Ajp14Interceptor ( from jk2, it's still part of the stable jk14 ).
It is no longer needed, a simple servlet is enough.
Added the 3.3 specific servlet, the request/response adapters and
the Worker ( which receives the requests and calls ContextManager.service() ).
Revision Changes Path
1.1 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/tomcat33/JkRequest33.java
Index: JkRequest33.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.jk.server.tomcat33;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.jk.*;
import org.apache.jk.core.*;
import org.apache.jk.common.*;
import org.apache.tomcat.modules.server.PoolTcpConnector;
import org.apache.tomcat.core.*;
import org.apache.tomcat.util.net.*;
import org.apache.tomcat.util.buf.*;
import org.apache.tomcat.util.log.*;
import org.apache.tomcat.util.http.*;
class JkRequest33 extends Request
{
BaseRequest ajpReq;
Channel ch;
Endpoint ep;
public JkRequest33(BaseRequest ajpReq)
{
headers = ajpReq.headers();
methodMB=ajpReq.method();
protoMB=ajpReq.protocol();
uriMB = ajpReq.requestURI();
queryMB = ajpReq.queryString();
remoteAddrMB = ajpReq.remoteAddr();
remoteHostMB = ajpReq.remoteHost();
serverNameMB = ajpReq.serverName();
// XXX sync cookies
scookies = new Cookies( headers );
urlDecoder=new UDecoder();
// XXX sync headers
params.setQuery( queryMB );
params.setURLDecoder( urlDecoder );
params.setHeaders( headers );
initRequest();
this.ajpReq=ajpReq;
}
public void setEndpoint( Channel ch, Endpoint ep ) {
this.ch=ch;
this.ep=ep;
}
// -------------------- Wrappers for changed method names, and to use the buffers
public int getServerPort() {
return ajpReq.getServerPort();
}
public void setServerPort(int i ) {
ajpReq.setServerPort( i );
}
public void setRemoteUser( String s ) {
super.setRemoteUser(s);
ajpReq.remoteUser().setString(s);
}
public String getRemoteUser() {
String s=ajpReq.remoteUser().toString();
if( s == null )
s=super.getRemoteUser();
return s;
}
public String getAuthType() {
return ajpReq.authType().toString();
}
public void setAuthType(String s ) {
ajpReq.authType().setString(s);
}
public String getJvmRoute() {
return ajpReq.jvmRoute().toString();
}
public void setJvmRoute(String s ) {
ajpReq.jvmRoute().setString(s);
}
// XXX scheme
public boolean isSecure() {
return ajpReq.getSecure();
}
public int getContentLength() {
int i=ajpReq.getContentLength();
if( i >= 0 ) return i;
i= super.getContentLength();
return i;
}
public void setContentLength( int i ) {
super.setContentLength(i); // XXX sync
}
// -------------------- Attributes --------------------
public void setAttribute(String name, Object value) {
ajpReq.setAttribute( name, value );
}
public Object getAttribute(String name) {
if (name == null) {
return null;
}
return ajpReq.getAttribute( name );
}
// XXX broken
// public Iterator getAttributeNames() {
// return attributes.keySet().iterator();
// }
// --------------------
public void recycle() {
super.recycle();
ajpReq.recycle();
}
public String dumpRequest() {
return ajpReq.toString();
}
// --------------------
// XXX This should go away if we introduce an InputBuffer.
// We almost have it as result of encoding fixes, but for now
// just keep this here, doesn't hurt too much.
public int doRead() throws IOException
{
if( available <= 0 )
return -1;
// available--;
// return ajp13.reqHandler.doRead(ajp13);
return -1;
}
public int doRead(byte[] b, int off, int len) throws IOException
{
if( available <= 0 )
return -1;
// int rd=ajp13.reqHandler.doRead( ajp13, b,off, len );
// available -= rd;
// return rd;
return -1;
}
}
1.1 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/tomcat33/JkResponse33.java
Index: JkResponse33.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.jk.server.tomcat33;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.jk.*;
import org.apache.jk.core.*;
import org.apache.jk.common.*;
import org.apache.tomcat.modules.server.PoolTcpConnector;
import org.apache.tomcat.core.*;
import org.apache.tomcat.util.net.*;
import org.apache.tomcat.util.buf.*;
import org.apache.tomcat.util.log.*;
import org.apache.tomcat.util.http.*;
class JkResponse33 extends Response
{
boolean finished=false;
Channel ch;
Endpoint ep;
int headersMsgNote;
int c2bConvertersNote;
int utfC2bNote;
public JkResponse33(WorkerEnv we)
{
super();
headersMsgNote=we.getNoteId( WorkerEnv.ENDPOINT_NOTE, "headerMsg" );
utfC2bNote=we.getNoteId( WorkerEnv.ENDPOINT_NOTE, "utfC2B" );
}
public void setEndpoint( Channel ch, Endpoint ep ) {
this.ch=ch;
this.ep=ep;
MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
if( msg==null ) {
msg=new MsgAjp();
ep.setNote( headersMsgNote, msg );
}
}
public void recycle() {
super.recycle();
finished=false;
}
// XXX if more headers that MAX_SIZE, send 2 packets!
// XXX Can be implemented using module notification, no need to extend
public void endHeaders() throws IOException
{
super.endHeaders();
if (request.protocol().isNull()) {
return;
}
C2B c2b=(C2B)ep.getNote( utfC2bNote );
if( c2b==null ) {
c2b=new C2B( "UTF8" );
ep.setNote( utfC2bNote, c2b );
}
MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
msg.reset();
msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS);
msg.appendInt( getStatus() );
// s->b conversion, message
msg.appendBytes( null );
// XXX add headers
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 );
}
msg.send( ch, ep );
if( dL > 0 ) d("Sending head");
}
// XXX Can be implemented using module notification, no need to extend
public void finish() throws IOException
{
if(!finished) {
super.finish();
finished = true; // Avoid END_OF_RESPONSE sent 2 times
MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
msg.reset();
msg.appendByte( HandlerRequest.JK_AJP13_END_RESPONSE );
msg.appendInt( 1 );
msg.send(ch, ep );
if( dL > 0 ) d( "sending end message " );
}
}
// XXX Can be implemented using the buffers, no need to extend
public void doWrite( byte b[], int off, int len) throws IOException
{
MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
msg.reset();
msg.appendByte( HandlerRequest.JK_AJP13_SEND_BODY_CHUNK);
msg.appendBytes( b, off, len );
msg.send( ch, ep );
if( dL > 0 ) d( "sending block " + len );
}
private static final int dL=0;
private static void d(String s ) {
System.err.println( "JkResponse33: " + s );
}
}
1.1 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/tomcat33/JkServlet33.java
Index: JkServlet33.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.jk.server.tomcat33;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.jk.core.*;
import org.apache.jk.common.*;
import org.apache.jk.server.*;
import org.apache.tomcat.util.net.*;
import org.apache.tomcat.util.buf.*;
import org.apache.tomcat.util.http.*;
import org.apache.tomcat.core.*;
/**
* Tomcat specific adapter
*/
public class JkServlet33 extends JkServlet
{
ContextManager cm;
public JkServlet33()
{
}
public void init(ServletConfig conf) throws ServletException {
d("init");
}
public void destroy() {
d("Shuting down");
}
public void initializeContainer(ServletConfig cfg) {
d("Initializing 4.0 for jk requests");
ServletContext sctx=cfg.getServletContext();
Context ctx=(Context)sctx.getAttribute( Context.ATTRIB_REAL_CONTEXT );
if( ctx==null ) {
d("Untrusted app or error, ctx==null ");
return;
}
cm=ctx.getContextManager();
// We now have control over the whole thing !
// We could register an interceptor to be notified
registerInterceptors();
// start Jk
JkMain jkMain=new JkMain();
jkMain.setProperties( servletConfig2properties( cfg ));
Worker33 worker=new Worker33();
worker.setContextManager( cm );
jkMain.setDefaultWorker( worker );
try {
jkMain.start();
} catch( Exception ex ) {
ex.printStackTrace();
}
}
public void registerInterceptors() {
}
private static final int dL=0;
private static void d(String s ) {
System.err.println( "JkServlet33: " + s );
}
}
1.1 jakarta-tomcat-connectors/jk/java/org/apache/jk/server/tomcat33/Worker33.java
Index: Worker33.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.jk.server.tomcat33;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.jk.*;
import org.apache.jk.core.*;
import org.apache.jk.common.*;
import org.apache.tomcat.modules.server.PoolTcpConnector;
import org.apache.tomcat.core.*;
import org.apache.tomcat.util.net.*;
import org.apache.tomcat.util.buf.*;
import org.apache.tomcat.util.log.*;
import org.apache.tomcat.util.http.*;
import org.apache.jk.core.*;
/** Tomcat 33 worker
*
*/
public class Worker33 extends Worker
{
ContextManager cm;
public Worker33()
{
super();
}
private int reqNote;
public void init(WorkerEnv we) throws IOException {
reqNote=we.getNoteId( WorkerEnv.REQUEST_NOTE, "tomcat33Request" );
}
public void setContextManager( ContextManager cm ) {
this.cm=cm;
}
public void service( BaseRequest req, Channel ch, Endpoint ep )
throws IOException
{
d("Incoming request " );
JkRequest33 treq=(JkRequest33)req.getNote( reqNote );
JkResponse33 tres;
if( treq==null ) {
treq=new JkRequest33(req);
req.setNote( reqNote, treq );
tres=new JkResponse33(we);
treq.setResponse( tres );
cm.initRequest( treq, tres );
}
tres=(JkResponse33)treq.getResponse();
treq.setEndpoint( ch, ep );
tres.setEndpoint( ch, ep );
try {
cm.service( treq, tres );
} catch(Exception ex ) {
ex.printStackTrace();
}
}
private static final int dL=0;
private static void d(String s ) {
System.err.println( "Worker33: " + s );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>