001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.geronimo.jetty;
019
020 import javax.servlet.http.Cookie;
021
022 import org.mortbay.http.HttpRequest;
023 import org.mortbay.jetty.servlet.ServletHandler;
024 import org.mortbay.jetty.servlet.ServletHttpRequest;
025 import org.mortbay.jetty.servlet.SessionManager;
026
027 /**
028 * @version $Rev$ $Date$
029 */
030 public class GeronimoServletHttpRequest extends ServletHttpRequest {
031 private final ServletHandler servletHandler;
032 private final HttpRequest request;
033 private String requestedSessionId;
034
035 public GeronimoServletHttpRequest(ServletHandler servletHandler, String pathInContext, HttpRequest request) {
036 super(servletHandler, pathInContext, request);
037 this.servletHandler = servletHandler;
038 this.request = request;
039 }
040
041 public String getRequestedSessionId() {
042 return requestedSessionId;
043 }
044
045 public void setRequestedSessionId(String pathParams) {
046 requestedSessionId = null;
047 if (servletHandler.isUsingCookies()) {
048 Cookie[] cookies= request.getCookies();
049 if (cookies!=null && cookies.length>0) {
050 for (int i=0;i<cookies.length;i++) {
051 if (SessionManager.__SessionCookie.equalsIgnoreCase(cookies[i].getName())) {
052 if (null != requestedSessionId) {
053 // Multiple jsessionid cookies. Probably due to
054 // multiple paths and/or domains. Pick the first
055 // known session or the last defined cookie.
056 SessionManager manager = servletHandler.getSessionManager();
057 if (manager!=null && manager.getHttpSession(requestedSessionId)!=null)
058 break;
059 }
060 requestedSessionId = cookies[i].getValue();
061 }
062 }
063 }
064 }
065
066 // check if there is a url encoded session param.
067 if (null != pathParams && pathParams.startsWith(SessionManager.__SessionURL)) {
068 String id = pathParams.substring(SessionManager.__SessionURL.length() + 1);
069 if (null == requestedSessionId) {
070 requestedSessionId = id;
071 }
072 }
073 }
074 }