View Javadoc

    1   /*
    2    * Copyright 2009 Red Hat, Inc.
    3    *
    4    * Red Hat licenses this file to you under the Apache License, version 2.0
    5    * (the "License"); you may not use this file except in compliance with the
    6    * License.  You may obtain a copy of the License at:
    7    *
    8    *    http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    13   * License for the specific language governing permissions and limitations
    14   * under the License.
    15   */
    16  package org.jboss.netty.handler.codec.http;
    17
    18  import org.jboss.netty.util.internal.StringUtil;
    19
    20  /**
    21   * The default {@link HttpRequest} implementation.
    22   *
    23   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    24   * @author Andy Taylor (andy.taylor@jboss.org)
    25   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    26   * @version $Rev: 2088 $, $Date: 2010-01-27 11:38:17 +0900 (Wed, 27 Jan 2010) $
    27   */
    28  public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest {
    29
    30      private HttpMethod method;
    31      private String uri;
    32
    33      /**
    34       * Creates a new instance.
    35       *
    36       * @param httpVersion the HTTP version of the request
    37       * @param method      the HTTP method of the request
    38       * @param uri         the URI or path of the request
    39       */
    40      public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
    41          super(httpVersion);
    42          setMethod(method);
    43          setUri(uri);
    44      }
    45
    46      public HttpMethod getMethod() {
    47          return method;
    48      }
    49
    50      public void setMethod(HttpMethod method) {
    51          if (method == null) {
    52              throw new NullPointerException("method");
    53          }
    54          this.method = method;
    55      }
    56
    57      public String getUri() {
    58          return uri;
    59      }
    60
    61      public void setUri(String uri) {
    62          if (uri == null) {
    63              throw new NullPointerException("uri");
    64          }
    65          this.uri = uri;
    66      }
    67
    68      @Override
    69      public String toString() {
    70          StringBuilder buf = new StringBuilder();
    71          buf.append(getClass().getSimpleName());
    72          buf.append("(chunked: ");
    73          buf.append(isChunked());
    74          buf.append(')');
    75          buf.append(StringUtil.NEWLINE);
    76          buf.append(getMethod().toString());
    77          buf.append(' ');
    78          buf.append(getUri());
    79          buf.append(' ');
    80          buf.append(getProtocolVersion().getText());
    81          buf.append(StringUtil.NEWLINE);
    82          appendHeaders(buf);
    83
    84          // Remove the last newline.
    85          buf.setLength(buf.length() - StringUtil.NEWLINE.length());
    86          return buf.toString();
    87      }
    88  }