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: */package org.apache.openejb.server.httpd;
018:
019: import javax.servlet.ServletContext;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.net.URI;
025: import java.net.URISyntaxException;
026: import java.util.Map;
027:
028: public class ServletRequestAdapter implements HttpRequest {
029: private final HttpServletRequest request;
030:
031: public ServletRequestAdapter(HttpServletRequest request) {
032: this .request = request;
033: }
034:
035: public ServletRequestAdapter(HttpServletRequest request,
036: HttpServletResponse response, ServletContext servletContext) {
037: this .request = request;
038: request.setAttribute(HttpRequest.SERVLET_REQUEST, request);
039: request.setAttribute(HttpRequest.SERVLET_RESPONSE, response);
040: request.setAttribute(HttpRequest.SERVLET_CONTEXT,
041: servletContext);
042: }
043:
044: public HttpSession getSession(boolean create) {
045: javax.servlet.http.HttpSession session = request
046: .getSession(create);
047: if (session != null) {
048: return new ServletSessionAdapter(session);
049: } else {
050: return null;
051: }
052: }
053:
054: public HttpSession getSession() {
055: javax.servlet.http.HttpSession session = request.getSession();
056: if (session != null) {
057: return new ServletSessionAdapter(session);
058: } else {
059: return null;
060: }
061: }
062:
063: public String getHeader(String name) {
064: return request.getHeader(name);
065: }
066:
067: public URI getURI() {
068: try {
069: return new URI(request.getScheme(), null, request
070: .getServerName(), request.getServerPort(), request
071: .getRequestURI(), request.getQueryString(), null);
072: } catch (URISyntaxException e) {
073: throw new IllegalStateException(e.getMessage(), e);
074: }
075: }
076:
077: public int getContentLength() {
078: return request.getContentLength();
079: }
080:
081: public String getContentType() {
082: return request.getContentType();
083: }
084:
085: public String getContextPath() {
086: return request.getContextPath();
087: }
088:
089: public InputStream getInputStream() throws IOException {
090: return request.getInputStream();
091: }
092:
093: public Method getMethod() {
094: try {
095: return Method.valueOf(request.getMethod());
096: } catch (IllegalArgumentException e) {
097: return Method.UNSUPPORTED;
098: }
099: }
100:
101: public String getParameter(String name) {
102: return request.getParameter(name);
103: }
104:
105: public Map getParameters() {
106: return request.getParameterMap();
107: }
108:
109: public Object getAttribute(String s) {
110: Object o = request.getAttribute(s);
111:
112: return o;
113: }
114:
115: public void setAttribute(String s, Object o) {
116: request.setAttribute(s, o);
117: }
118:
119: public String getRemoteAddr() {
120: return request.getRemoteAddr();
121: }
122:
123: }
|