Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » server » httpd » [javadoc | source]
    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.server.httpd;
   19   
   20   import javax.servlet.ServletContext;
   21   import javax.servlet.http.HttpServletRequest;
   22   import javax.servlet.http.HttpServletResponse;
   23   import java.io.IOException;
   24   import java.io.InputStream;
   25   import java.net.URI;
   26   import java.net.URISyntaxException;
   27   import java.util.Map;
   28   
   29   public class ServletRequestAdapter implements HttpRequest {
   30       private final HttpServletRequest request;
   31   
   32       public ServletRequestAdapter(HttpServletRequest request) {
   33           this.request = request;
   34       }
   35   
   36       public ServletRequestAdapter(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) {
   37           this.request = request;
   38           request.setAttribute(HttpRequest.SERVLET_REQUEST, request);
   39           request.setAttribute(HttpRequest.SERVLET_RESPONSE, response);
   40           request.setAttribute(HttpRequest.SERVLET_CONTEXT, servletContext);
   41       }
   42   
   43       public HttpSession getSession(boolean create) {
   44           javax.servlet.http.HttpSession session = request.getSession(create);
   45           if (session != null) {
   46               return new ServletSessionAdapter(session);
   47           } else {
   48               return null;
   49           }
   50       }
   51   
   52       public HttpSession getSession() {
   53           javax.servlet.http.HttpSession session = request.getSession();
   54           if (session != null) {
   55               return new ServletSessionAdapter(session);
   56           } else {
   57               return null;
   58           }
   59       }
   60   
   61       public String getHeader(String name) {
   62           return request.getHeader(name);
   63       }
   64   
   65       public URI getURI() {
   66           try {
   67               return new URI(request.getScheme(), null, request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null);
   68           } catch (URISyntaxException e) {
   69               throw new IllegalStateException(e.getMessage(), e);
   70           }
   71       }
   72   
   73       public int getContentLength() {
   74           return request.getContentLength();
   75       }
   76   
   77       public String getContentType() {
   78           return request.getContentType();
   79       }
   80   
   81       public String getContextPath() {
   82           return request.getContextPath();
   83       }
   84   
   85       public InputStream getInputStream() throws IOException {
   86           return request.getInputStream();
   87       }
   88   
   89       public Method getMethod() {
   90           try {
   91               return Method.valueOf(request.getMethod());
   92           } catch (IllegalArgumentException e) {
   93               return Method.UNSUPPORTED;
   94           }
   95       }
   96   
   97       public String getParameter(String name) {
   98           return request.getParameter(name);
   99       }
  100   
  101       public Map getParameters() {
  102           return request.getParameterMap();
  103       }
  104   
  105       public Object getAttribute(String s) {
  106           Object o = request.getAttribute(s);
  107   
  108           return o;
  109       }
  110   
  111       public void setAttribute(String s, Object o) {
  112           request.setAttribute(s, o);
  113       }
  114   
  115       public String getRemoteAddr() {
  116           return request.getRemoteAddr();
  117       }
  118   
  119   }

Save This Page
Home » openejb-3.1.2-src » org.apache » openejb » server » httpd » [javadoc | source]