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