001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with 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,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.transport.http.server;
021:
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.util.Iterator;
025:
026: import org.apache.http.Header;
027: import org.apache.http.HttpException;
028: import org.apache.http.HttpRequest;
029: import org.apache.http.HttpVersion;
030: import org.apache.http.params.HttpParams;
031: import org.apache.http.protocol.HTTP;
032: import org.apache.http.protocol.HttpContext;
033: import org.apache.http.protocol.HttpExecutionContext;
034: import org.apache.http.protocol.HttpProcessor;
035:
036: public class AxisHttpRequestImpl implements AxisHttpRequest {
037:
038: private final HttpRequest request;
039: private final AxisHttpConnection conn;
040: private final HttpProcessor httpproc;
041: private final HttpContext context;
042:
043: public AxisHttpRequestImpl(final AxisHttpConnection conn,
044: final HttpRequest request, final HttpProcessor httpproc,
045: final HttpContext context) {
046: super ();
047: if (conn == null) {
048: throw new IllegalArgumentException(
049: "HTTP connection may not be null");
050: }
051: if (request == null) {
052: throw new IllegalArgumentException(
053: "HTTP request may not be null");
054: }
055: if (httpproc == null) {
056: throw new IllegalArgumentException(
057: "HTTP processor may not be null");
058: }
059: if (context == null) {
060: throw new IllegalArgumentException(
061: "HTTP context may not be null");
062: }
063: this .request = request;
064: this .conn = conn;
065: this .httpproc = httpproc;
066: this .context = context;
067: }
068:
069: public void prepare() throws IOException, HttpException {
070: this .context.setAttribute(HttpExecutionContext.HTTP_CONNECTION,
071: this .conn);
072: this .context.setAttribute(HttpExecutionContext.HTTP_REQUEST,
073: this .request);
074:
075: this .httpproc.process(this .request, this .context);
076: }
077:
078: public String getMethod() {
079: return this .request.getRequestLine().getMethod();
080: }
081:
082: public String getRequestURI() {
083: return this .request.getRequestLine().getUri();
084: }
085:
086: public HttpVersion getHttpVersion() {
087: return this .request.getRequestLine().getHttpVersion();
088: }
089:
090: public String getContentType() {
091: Header header = this .request.getFirstHeader(HTTP.CONTENT_TYPE);
092: if (header != null) {
093: return header.getValue();
094: } else {
095: return null;
096: }
097: }
098:
099: public InputStream getInputStream() {
100: return this .conn.getInputStream();
101: }
102:
103: public void addHeader(final Header header) {
104: this .request.addHeader(header);
105: }
106:
107: public void addHeader(final String name, final String value) {
108: this .request.addHeader(name, value);
109: }
110:
111: public boolean containsHeader(final String name) {
112: return this .request.containsHeader(name);
113: }
114:
115: public Header[] getAllHeaders() {
116: return this .request.getAllHeaders();
117: }
118:
119: public Header getFirstHeader(final String name) {
120: return this .request.getFirstHeader(name);
121: }
122:
123: public Header[] getHeaders(String name) {
124: return this .request.getHeaders(name);
125: }
126:
127: public Header getLastHeader(final String name) {
128: return this .request.getLastHeader(name);
129: }
130:
131: public Iterator headerIterator() {
132: return this .request.headerIterator();
133: }
134:
135: public void removeHeader(final Header header) {
136: this .request.removeHeader(header);
137: }
138:
139: public void removeHeaders(final String name) {
140: this .request.removeHeaders(name);
141: }
142:
143: public void setHeader(final Header header) {
144: this .request.setHeader(header);
145: }
146:
147: public void setHeader(final String name, final String value) {
148: this .request.setHeader(name, value);
149: }
150:
151: public void setHeaders(Header[] headers) {
152: this .request.setHeaders(headers);
153: }
154:
155: public HttpParams getParams() {
156: return this .request.getParams();
157: }
158:
159: public void setParams(final HttpParams params) {
160: this.request.setParams(params);
161: }
162:
163: }
|