01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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: /** A dummy worker, will just send back a dummy response.
28: * Used for testing and tunning.
29: */
30: public class WorkerDummy extends JkHandler {
31: public WorkerDummy() {
32: String msg = "HelloWorld";
33: byte b[] = msg.getBytes();
34: body.setBytes(b, 0, b.length);
35: }
36:
37: /* ==================== Start/stop ==================== */
38:
39: /** Initialize the worker. After this call the worker will be
40: * ready to accept new requests.
41: */
42: public void init() throws IOException {
43: headersMsgNote = wEnv.getNoteId(WorkerEnv.ENDPOINT_NOTE,
44: "headerMsg");
45: }
46:
47: MessageBytes body = new MessageBytes();
48: private int headersMsgNote;
49:
50: public int invoke(Msg in, MsgContext ep) throws IOException {
51: MsgAjp msg = (MsgAjp) ep.getNote(headersMsgNote);
52: if (msg == null) {
53: msg = new MsgAjp();
54: ep.setNote(headersMsgNote, msg);
55: }
56:
57: msg.reset();
58: msg.appendByte(HandlerRequest.JK_AJP13_SEND_HEADERS);
59: msg.appendInt(200);
60: msg.appendBytes(null);
61:
62: msg.appendInt(0);
63:
64: ep.setType(JkHandler.HANDLE_SEND_PACKET);
65: ep.getSource().invoke(msg, ep);
66: // msg.dump("out:" );
67:
68: msg.reset();
69: msg.appendByte(HandlerRequest.JK_AJP13_SEND_BODY_CHUNK);
70: msg.appendInt(body.getLength());
71: msg.appendBytes(body);
72:
73: ep.getSource().invoke(msg, ep);
74:
75: msg.reset();
76: msg.appendByte(HandlerRequest.JK_AJP13_END_RESPONSE);
77: msg.appendInt(1);
78:
79: ep.getSource().invoke(msg, ep);
80: return OK;
81: }
82:
83: private static final int dL = 0;
84:
85: private static void d(String s) {
86: System.err.println("WorkerDummy: " + s);
87: }
88: }
|