View Javadoc

    1   /*
    2    * Copyright 2010 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.rtsp;
    17
    18  import org.jboss.netty.buffer.ChannelBuffer;
    19  import org.jboss.netty.handler.codec.frame.TooLongFrameException;
    20  import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
    21  import org.jboss.netty.handler.codec.http.HttpMessage;
    22  import org.jboss.netty.handler.codec.http.HttpResponse;
    23  import org.jboss.netty.handler.codec.http.HttpResponseStatus;
    24
    25  /**
    26   * Decodes {@link ChannelBuffer}s into RTSP responses represented in
    27   * {@link HttpResponse}s.
    28   * <p>
    29   * <h3>Parameters that prevents excessive memory consumption</h3>
    30   * <table border="1">
    31   * <tr>
    32   * <th>Name</th><th>Meaning</th>
    33   * </tr>
    34   * <tr>
    35   * <td>{@code maxInitialLineLength}</td>
    36   * <td>The maximum length of the initial line (e.g. {@code "RTSP/1.0 200 OK"})
    37   *     If the length of the initial line exceeds this value, a
    38   *     {@link TooLongFrameException} will be raised.</td>
    39   * </tr>
    40   * <tr>
    41   * <td>{@code maxHeaderSize}</td>
    42   * <td>The maximum length of all headers.  If the sum of the length of each
    43   *     header exceeds this value, a {@link TooLongFrameException} will be raised.</td>
    44   * </tr>
    45   * <tr>
    46   * <td>{@code maxContentLength}</td>
    47   * <td>The maximum length of the content.  If the content length exceeds this
    48   *     value, a {@link TooLongFrameException} will be raised.</td>
    49   * </tr>
    50   * </table>
    51   *
    52   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
    53   * @author <a href="http://amitbhayani.blogspot.com/">Amit Bhayani</a>
    54   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
    55   * @version $Rev: 2282 $, $Date: 2010-05-19 16:51:38 +0900 (Wed, 19 May 2010) $
    56   */
    57  public class RtspResponseDecoder extends RtspMessageDecoder {
    58
    59      /**
    60       * Creates a new instance with the default
    61       * {@code maxInitialLineLength (4096}}, {@code maxHeaderSize (8192)}, and
    62       * {@code maxContentLength (8192)}.
    63       */
    64      public RtspResponseDecoder() {
    65          super();
    66      }
    67
    68      /**
    69       * Creates a new instance with the specified parameters.
    70       */
    71      public RtspResponseDecoder(int maxInitialLineLength, int maxHeaderSize,
    72              int maxContentLength) {
    73          super(maxInitialLineLength, maxHeaderSize, maxContentLength);
    74      }
    75
    76      @Override
    77      protected HttpMessage createMessage(String[] initialLine) throws Exception {
    78          return new DefaultHttpResponse(
    79                  RtspVersions.valueOf(initialLine[0]),
    80                  new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]));
    81      }
    82
    83      @Override
    84      protected boolean isDecodingRequest() {
    85          return false;
    86      }
    87  }