001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.coyote.ajp;
019:
020: import java.util.Hashtable;
021:
022: import org.apache.tomcat.util.buf.ByteChunk;
023:
024: /**
025: * Constants.
026: *
027: * @author Remy Maucherat
028: */
029: public final class Constants {
030:
031: // -------------------------------------------------------------- Constants
032:
033: /**
034: * Package name.
035: */
036: public static final String Package = "org.apache.coyote.ajp";
037:
038: public static final int DEFAULT_CONNECTION_LINGER = -1;
039: public static final int DEFAULT_CONNECTION_TIMEOUT = -1;
040: public static final int DEFAULT_CONNECTION_UPLOAD_TIMEOUT = 300000;
041: public static final int DEFAULT_SERVER_SOCKET_TIMEOUT = 0;
042: public static final boolean DEFAULT_TCP_NO_DELAY = true;
043:
044: // Prefix codes for message types from server to container
045: public static final byte JK_AJP13_FORWARD_REQUEST = 2;
046: public static final byte JK_AJP13_SHUTDOWN = 7;
047: public static final byte JK_AJP13_PING_REQUEST = 8;
048: public static final byte JK_AJP13_CPING_REQUEST = 10;
049:
050: // Prefix codes for message types from container to server
051: public static final byte JK_AJP13_SEND_BODY_CHUNK = 3;
052: public static final byte JK_AJP13_SEND_HEADERS = 4;
053: public static final byte JK_AJP13_END_RESPONSE = 5;
054: public static final byte JK_AJP13_GET_BODY_CHUNK = 6;
055: public static final byte JK_AJP13_CPONG_REPLY = 9;
056:
057: // Integer codes for common response header strings
058: public static final int SC_RESP_CONTENT_TYPE = 0xA001;
059: public static final int SC_RESP_CONTENT_LANGUAGE = 0xA002;
060: public static final int SC_RESP_CONTENT_LENGTH = 0xA003;
061: public static final int SC_RESP_DATE = 0xA004;
062: public static final int SC_RESP_LAST_MODIFIED = 0xA005;
063: public static final int SC_RESP_LOCATION = 0xA006;
064: public static final int SC_RESP_SET_COOKIE = 0xA007;
065: public static final int SC_RESP_SET_COOKIE2 = 0xA008;
066: public static final int SC_RESP_SERVLET_ENGINE = 0xA009;
067: public static final int SC_RESP_STATUS = 0xA00A;
068: public static final int SC_RESP_WWW_AUTHENTICATE = 0xA00B;
069: public static final int SC_RESP_AJP13_MAX = 11;
070:
071: // Integer codes for common (optional) request attribute names
072: public static final byte SC_A_CONTEXT = 1; // XXX Unused
073: public static final byte SC_A_SERVLET_PATH = 2; // XXX Unused
074: public static final byte SC_A_REMOTE_USER = 3;
075: public static final byte SC_A_AUTH_TYPE = 4;
076: public static final byte SC_A_QUERY_STRING = 5;
077: public static final byte SC_A_JVM_ROUTE = 6;
078: public static final byte SC_A_SSL_CERT = 7;
079: public static final byte SC_A_SSL_CIPHER = 8;
080: public static final byte SC_A_SSL_SESSION = 9;
081: public static final byte SC_A_SSL_KEYSIZE = 11;
082: public static final byte SC_A_SECRET = 12;
083: public static final byte SC_A_STORED_METHOD = 13;
084:
085: // Used for attributes which are not in the list above
086: public static final byte SC_A_REQ_ATTRIBUTE = 10;
087:
088: // Terminates list of attributes
089: public static final byte SC_A_ARE_DONE = (byte) 0xFF;
090:
091: // Ajp13 specific - needs refactoring for the new model
092:
093: /**
094: * Default maximum total byte size for a AJP packet
095: */
096: public static final int MAX_PACKET_SIZE = 8192;
097: /**
098: * Size of basic packet header
099: */
100: public static final int H_SIZE = 4;
101:
102: /**
103: * Size of the header metadata
104: */
105: public static final int READ_HEAD_LEN = 6;
106: public static final int SEND_HEAD_LEN = 8;
107:
108: /**
109: * Default maximum size of data that can be sent in one packet
110: */
111: public static final int MAX_READ_SIZE = MAX_PACKET_SIZE
112: - READ_HEAD_LEN;
113: public static final int MAX_SEND_SIZE = MAX_PACKET_SIZE
114: - SEND_HEAD_LEN;
115:
116: // Translates integer codes to names of HTTP methods
117: public static final String[] methodTransArray = { "OPTIONS", "GET",
118: "HEAD", "POST", "PUT", "DELETE", "TRACE", "PROPFIND",
119: "PROPPATCH", "MKCOL", "COPY", "MOVE", "LOCK", "UNLOCK",
120: "ACL", "REPORT", "VERSION-CONTROL", "CHECKIN", "CHECKOUT",
121: "UNCHECKOUT", "SEARCH", "MKWORKSPACE", "UPDATE", "LABEL",
122: "MERGE", "BASELINE-CONTROL", "MKACTIVITY" };
123: public static final int SC_M_JK_STORED = (byte) 0xFF;
124:
125: // id's for common request headers
126: public static final int SC_REQ_ACCEPT = 1;
127: public static final int SC_REQ_ACCEPT_CHARSET = 2;
128: public static final int SC_REQ_ACCEPT_ENCODING = 3;
129: public static final int SC_REQ_ACCEPT_LANGUAGE = 4;
130: public static final int SC_REQ_AUTHORIZATION = 5;
131: public static final int SC_REQ_CONNECTION = 6;
132: public static final int SC_REQ_CONTENT_TYPE = 7;
133: public static final int SC_REQ_CONTENT_LENGTH = 8;
134: public static final int SC_REQ_COOKIE = 9;
135: public static final int SC_REQ_COOKIE2 = 10;
136: public static final int SC_REQ_HOST = 11;
137: public static final int SC_REQ_PRAGMA = 12;
138: public static final int SC_REQ_REFERER = 13;
139: public static final int SC_REQ_USER_AGENT = 14;
140: // AJP14 new header
141: public static final byte SC_A_SSL_KEY_SIZE = 11; // XXX ???
142:
143: // Translates integer codes to request header names
144: public static final String[] headerTransArray = { "accept",
145: "accept-charset", "accept-encoding", "accept-language",
146: "authorization", "connection", "content-type",
147: "content-length", "cookie", "cookie2", "host", "pragma",
148: "referer", "user-agent" };
149:
150: // Translates integer codes to response header names
151: public static final String[] responseTransArray = { "Content-Type",
152: "Content-Language", "Content-Length", "Date",
153: "Last-Modified", "Location", "Set-Cookie", "Set-Cookie2",
154: "Servlet-Engine", "Status", "WWW-Authenticate" };
155:
156: private static final Hashtable<String, Integer> responseTransHash = new Hashtable<String, Integer>(
157: 20);
158:
159: static {
160: try {
161: int i;
162: for (i = 0; i < SC_RESP_AJP13_MAX; i++) {
163: responseTransHash.put(responseTransArray[i],
164: new Integer(0xA001 + i));
165: }
166: } catch (Exception e) {
167: // Do nothing
168: }
169: }
170:
171: public static final int getResponseAjpIndex(String header) {
172: Integer i = responseTransHash.get(header);
173: if (i == null)
174: return 0;
175: else
176: return i.intValue();
177: }
178:
179: /**
180: * CRLF.
181: */
182: public static final String CRLF = "\r\n";
183:
184: /**
185: * Server string.
186: */
187: public static final byte[] SERVER_BYTES = ByteChunk
188: .convertToBytes("Server: Apache-Coyote/1.1" + CRLF);
189:
190: /**
191: * CR.
192: */
193: public static final byte CR = (byte) '\r';
194:
195: /**
196: * LF.
197: */
198: public static final byte LF = (byte) '\n';
199:
200: /**
201: * SP.
202: */
203: public static final byte SP = (byte) ' ';
204:
205: /**
206: * HT.
207: */
208: public static final byte HT = (byte) '\t';
209:
210: /**
211: * COLON.
212: */
213: public static final byte COLON = (byte) ':';
214:
215: /**
216: * 'A'.
217: */
218: public static final byte A = (byte) 'A';
219:
220: /**
221: * 'a'.
222: */
223: public static final byte a = (byte) 'a';
224:
225: /**
226: * 'Z'.
227: */
228: public static final byte Z = (byte) 'Z';
229:
230: /**
231: * '?'.
232: */
233: public static final byte QUESTION = (byte) '?';
234:
235: /**
236: * Lower case offset.
237: */
238: public static final byte LC_OFFSET = A - a;
239:
240: /**
241: * Default HTTP header buffer size.
242: */
243: public static final int DEFAULT_HTTP_HEADER_BUFFER_SIZE = 48 * 1024;
244:
245: /* Various constant "strings" */
246: public static final byte[] CRLF_BYTES = ByteChunk
247: .convertToBytes(CRLF);
248: public static final byte[] COLON_BYTES = ByteChunk
249: .convertToBytes(": ");
250: public static final String CONNECTION = "Connection";
251: public static final String CLOSE = "close";
252: public static final byte[] CLOSE_BYTES = ByteChunk
253: .convertToBytes(CLOSE);
254: public static final String KEEPALIVE = "keep-alive";
255: public static final byte[] KEEPALIVE_BYTES = ByteChunk
256: .convertToBytes(KEEPALIVE);
257: public static final String CHUNKED = "chunked";
258: public static final byte[] ACK_BYTES = ByteChunk
259: .convertToBytes("HTTP/1.1 100 Continue" + CRLF + CRLF);
260: public static final String TRANSFERENCODING = "Transfer-Encoding";
261: public static final byte[] _200_BYTES = ByteChunk
262: .convertToBytes("200");
263: public static final byte[] _400_BYTES = ByteChunk
264: .convertToBytes("400");
265: public static final byte[] _404_BYTES = ByteChunk
266: .convertToBytes("404");
267:
268: /**
269: * Identity filters (input and output).
270: */
271: public static final int IDENTITY_FILTER = 0;
272:
273: /**
274: * Chunked filters (input and output).
275: */
276: public static final int CHUNKED_FILTER = 1;
277:
278: /**
279: * Void filters (input and output).
280: */
281: public static final int VOID_FILTER = 2;
282:
283: /**
284: * GZIP filter (output).
285: */
286: public static final int GZIP_FILTER = 3;
287:
288: /**
289: * Buffered filter (input)
290: */
291: public static final int BUFFERED_FILTER = 3;
292:
293: /**
294: * HTTP/1.0.
295: */
296: public static final String HTTP_10 = "HTTP/1.0";
297:
298: /**
299: * HTTP/1.1.
300: */
301: public static final String HTTP_11 = "HTTP/1.1";
302: public static final byte[] HTTP_11_BYTES = ByteChunk
303: .convertToBytes(HTTP_11);
304:
305: /**
306: * GET.
307: */
308: public static final String GET = "GET";
309:
310: /**
311: * HEAD.
312: */
313: public static final String HEAD = "HEAD";
314:
315: /**
316: * POST.
317: */
318: public static final String POST = "POST";
319:
320: }
|