KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jk > common > WorkerDummy


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jk.common;
18
19 import java.io.IOException JavaDoc;
20
21 import org.apache.jk.core.JkHandler;
22 import org.apache.jk.core.Msg;
23 import org.apache.jk.core.MsgContext;
24 import org.apache.jk.core.WorkerEnv;
25 import org.apache.tomcat.util.buf.MessageBytes;
26
27
28 /** A dummy worker, will just send back a dummy response.
29  * Used for testing and tunning.
30  */

31 public class WorkerDummy extends JkHandler
32 {
33     public WorkerDummy()
34     {
35         String JavaDoc msg="HelloWorld";
36         byte b[]=msg.getBytes();
37         body.setBytes(b, 0, b.length);
38     }
39
40     /* ==================== Start/stop ==================== */
41
42     /** Initialize the worker. After this call the worker will be
43      * ready to accept new requests.
44      */

45     public void init() throws IOException JavaDoc {
46         headersMsgNote=wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "headerMsg" );
47     }
48  
49     MessageBytes body=MessageBytes.newInstance();
50     private int headersMsgNote;
51     
52     public int invoke( Msg in, MsgContext ep )
53         throws IOException JavaDoc
54     {
55         MsgAjp msg=(MsgAjp)ep.getNote( headersMsgNote );
56         if( msg==null ) {
57             msg=new MsgAjp();
58             ep.setNote( headersMsgNote, msg );
59         }
60
61         msg.reset();
62         msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS);
63         msg.appendInt(200);
64         msg.appendBytes(null);
65
66         msg.appendInt(0);
67
68         ep.setType( JkHandler.HANDLE_SEND_PACKET );
69         ep.getSource().invoke( msg, ep );
70         // msg.dump("out:" );
71

72         msg.reset();
73         msg.appendByte( HandlerRequest.JK_AJP13_SEND_BODY_CHUNK);
74         msg.appendInt( body.getLength() );
75         msg.appendBytes( body );
76
77         
78         ep.getSource().invoke(msg, ep);
79
80         msg.reset();
81         msg.appendByte( HandlerRequest.JK_AJP13_END_RESPONSE );
82         msg.appendInt( 1 );
83         
84         ep.getSource().invoke(msg, ep );
85         return OK;
86     }
87     
88     private static final int dL=0;
89 }
90
91
Popular Tags