01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.jk.common;
19:
20: import java.io.IOException;
21:
22: import org.apache.jk.core.JkHandler;
23: import org.apache.jk.core.Msg;
24: import org.apache.jk.core.MsgContext;
25: import org.apache.jk.core.WorkerEnv;
26: import org.apache.tomcat.util.buf.MessageBytes;
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: public WorkerDummy() {
33: String msg = "HelloWorld";
34: byte b[] = msg.getBytes();
35: body.setBytes(b, 0, b.length);
36: }
37:
38: /* ==================== Start/stop ==================== */
39:
40: /** Initialize the worker. After this call the worker will be
41: * ready to accept new requests.
42: */
43: public void init() throws IOException {
44: headersMsgNote = wEnv.getNoteId(WorkerEnv.ENDPOINT_NOTE,
45: "headerMsg");
46: }
47:
48: MessageBytes body = MessageBytes.newInstance();
49: private int headersMsgNote;
50:
51: public int invoke(Msg in, MsgContext ep) throws IOException {
52: MsgAjp msg = (MsgAjp) ep.getNote(headersMsgNote);
53: if (msg == null) {
54: msg = new MsgAjp();
55: ep.setNote(headersMsgNote, msg);
56: }
57:
58: msg.reset();
59: msg.appendByte(AjpConstants.JK_AJP13_SEND_HEADERS);
60: msg.appendInt(200);
61: msg.appendBytes(null);
62:
63: msg.appendInt(0);
64:
65: ep.setType(JkHandler.HANDLE_SEND_PACKET);
66: ep.getSource().invoke(msg, ep);
67: // msg.dump("out:" );
68:
69: msg.reset();
70: msg.appendByte(AjpConstants.JK_AJP13_SEND_BODY_CHUNK);
71: msg.appendInt(body.getLength());
72: msg.appendBytes(body);
73:
74: ep.getSource().invoke(msg, ep);
75:
76: msg.reset();
77: msg.appendByte(AjpConstants.JK_AJP13_END_RESPONSE);
78: msg.appendInt(1);
79:
80: ep.getSource().invoke(msg, ep);
81: return OK;
82: }
83:
84: private static final int dL = 0;
85: }
|