01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.transport.http.server;
21:
22: import org.apache.axis2.Constants;
23: import org.apache.axis2.transport.http.HTTPConstants;
24: import org.apache.http.Header;
25: import org.apache.http.HeaderElement;
26: import org.apache.http.HttpException;
27: import org.apache.http.HttpRequest;
28: import org.apache.http.HttpRequestInterceptor;
29: import org.apache.http.protocol.HttpContext;
30:
31: import java.io.IOException;
32:
33: public class RequestSessionCookie implements HttpRequestInterceptor {
34:
35: public void process(final HttpRequest request,
36: final HttpContext context) throws HttpException,
37: IOException {
38: if (request == null) {
39: throw new IllegalArgumentException(
40: "HTTP request may not be null");
41: }
42: if (context == null) {
43: throw new IllegalArgumentException(
44: "HTTP context may not be null");
45: }
46:
47: String sessionCookie = null;
48: Header[] headers = request
49: .getHeaders(HTTPConstants.HEADER_COOKIE);
50: for (int i = 0; i < headers.length; i++) {
51: HeaderElement[] elements = headers[i].getElements();
52: for (int e = 0; e < elements.length; e++) {
53: HeaderElement element = elements[e];
54: if (Constants.SESSION_COOKIE.equalsIgnoreCase(element
55: .getName())
56: || Constants.SESSION_COOKIE_JSESSIONID
57: .equalsIgnoreCase(element.getName())) {
58: sessionCookie = element.getValue();
59: }
60: }
61: }
62: context
63: .setAttribute(HTTPConstants.COOKIE_STRING,
64: sessionCookie);
65: }
66:
67: }
|