View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.http;
20  
21  /* ------------------------------------------------------------------------------- */
22  /** 
23   * <p>Exception thrown to indicate a Bad HTTP Message has either been received
24   * or attempted to be generated.  Typically these are handled with either 400
25   * or 500 responses.</p>
26   */
27  @SuppressWarnings("serial")
28  public class BadMessageException extends RuntimeException
29  {
30      final int _code;
31      final String _reason;
32  
33      public BadMessageException()
34      {
35          this(400,null);
36      }
37      
38      public BadMessageException(int code)
39      {
40          this(code,null);
41      }
42      
43      public BadMessageException(String reason)
44      {
45          this(400,reason);
46      }
47      
48      public BadMessageException(int code, String reason)
49      {
50          super(code+": "+reason);
51          _code=code;
52          _reason=reason;
53      }
54      
55      public BadMessageException(int code, String reason, Throwable cause)
56      {
57          super(code+": "+reason, cause);
58          _code=code;
59          _reason=reason;
60      }
61      
62      public int getCode()
63      {
64          return _code;
65      }
66      
67      public String getReason()
68      {
69          return _reason;
70      }
71  }