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, final String statusLine,
    65              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.parseInt(statusLine.substring(1, 4)) : Integer
    71                  .parseInt(statusLine.substring(0, 3));
    72
    73          this.headers = headers;
    74      }
    75
    76      /**
    77       * Returns the HTTP response protocol version.
    78       */
    79      public final String getHttpVersion() {
    80          return httpVersion;
    81      }
    82
    83      /**
    84       * Returns the HTTP response status code.
    85       */
    86      public final int getStatusCode() {
    87          return statusCode;
    88      }
    89
    90      /**
    91       * Returns the HTTP response status line.
    92       */
    93      public final String getStatusLine() {
    94          return statusLine;
    95      }
    96
    97      /**
    98       * Returns the HTTP response body.
    99       */
    100     public String getBody() {
    101         return body;
    102     }
    103
    104     /**
    105      * Sets the HTTP response body.
    106      */
    107     public void setBody(String body) {
    108         this.body = body;
    109     }
    110
    111     /**
    112      * Returns the HTTP response headers.
    113      */
    114     public final Map<String, List<String>> getHeaders() {
    115         return headers;
    116     }
    117 }