View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with 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,
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.mina.proxy.handlers.http;
21  
22  import java.util.List;
23  import java.util.Map;
24  
25  /**
26   * HttpProxyResponse.java - Wrapper class for HTTP requests.
27   * 
28   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
29   * @since MINA 2.0.0-M3
30   */
31  public class HttpProxyResponse {
32      /**
33       * The HTTP response protocol version.
34       */
35      public final String httpVersion;
36  
37      /**
38       * The HTTP response status line.
39       */
40      public final String statusLine;
41  
42      /**
43       * The HTTP response status code;
44       */
45      public final int statusCode;
46  
47      /**
48       * The HTTP response headers.
49       */
50      public final Map<String, List<String>> headers;
51  
52      /**
53       * The HTTP response body.
54       */
55      public String body;
56  
57      /**
58       * Constructor of an HTTP proxy response.
59       *  
60       * @param httpVersion the protocol version
61       * @param statusLine the response status line
62       * @param headers the response headers
63       */
64      protected HttpProxyResponse(final String httpVersion,
65              final String statusLine, final Map<String, List<String>> headers) {
66          this.httpVersion = httpVersion;
67          this.statusLine = statusLine;
68  
69          // parses the status code from the status line
70          this.statusCode = statusLine.charAt(0) == ' ' ? Integer
71                  .parseInt(statusLine.substring(1, 4)) : Integer
72                  .parseInt(statusLine.substring(0, 3));
73  
74          this.headers = headers;
75      }
76  
77      /**
78       * Returns the HTTP response protocol version.
79       */
80      public final String getHttpVersion() {
81          return httpVersion;
82      }
83  
84      /**
85       * Returns the HTTP response status code.
86       */
87      public final int getStatusCode() {
88          return statusCode;
89      }
90  
91      /**
92       * Returns the HTTP response status line.
93       */
94      public final String getStatusLine() {
95          return statusLine;
96      }
97  
98      /**
99       * Returns the HTTP response body.
100      */
101     public String getBody() {
102         return body;
103     }
104 
105     /**
106      * Sets the HTTP response body.
107      */
108     public void setBody(String body) {
109         this.body = body;
110     }
111 
112     /**
113      * Returns the HTTP response headers.
114      */
115     public final Map<String, List<String>> getHeaders() {
116         return headers;
117     }
118 }