01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.http.server;
07:
08: import java.net.HttpURLConnection;
09:
10: /**
11: * HTTP-related exception indicating that an HTTP client has erred. Status codes
12: * for these types of errors are in the 4xx range. The default status code for
13: * constructors without a <tt>statusCode</tt> parameter is
14: * <tt>400 Bad Request</tt>.
15: *
16: * @author Arjohn Kampman
17: */
18: public class ClientHTTPException extends HTTPException {
19:
20: private static final long serialVersionUID = 7722604284325312749L;
21:
22: private static final int DEFAULT_STATUS_CODE = HttpURLConnection.HTTP_BAD_REQUEST;
23:
24: /**
25: * Creates a {@link ClientHTTPException} with status code 400 "Bad Request".
26: */
27: public ClientHTTPException() {
28: this (DEFAULT_STATUS_CODE);
29: }
30:
31: /**
32: * Creates a {@link ClientHTTPException} with status code 400 "Bad Request".
33: */
34: public ClientHTTPException(String msg) {
35: this (DEFAULT_STATUS_CODE, msg);
36: }
37:
38: /**
39: * Creates a {@link ClientHTTPException} with status code 400 "Bad Request".
40: */
41: public ClientHTTPException(String msg, Throwable t) {
42: this (DEFAULT_STATUS_CODE, t);
43: }
44:
45: /**
46: * Creates a {@link ClientHTTPException} with the specified status code.
47: *
48: * @throws IllegalArgumentException
49: * If <tt>statusCode</tt> is not in the 4xx range.
50: */
51: public ClientHTTPException(int statusCode) {
52: super (statusCode);
53: }
54:
55: /**
56: * Creates a {@link ClientHTTPException} with the specified status code.
57: *
58: * @throws IllegalArgumentException
59: * If <tt>statusCode</tt> is not in the 4xx range.
60: */
61: public ClientHTTPException(int statusCode, String message) {
62: super (statusCode, message);
63: }
64:
65: /**
66: * Creates a {@link ClientHTTPException} with the specified status code.
67: *
68: * @throws IllegalArgumentException
69: * If <tt>statusCode</tt> is not in the 4xx range.
70: */
71: public ClientHTTPException(int statusCode, String message,
72: Throwable t) {
73: super (statusCode, message, t);
74: }
75:
76: /**
77: * Creates a {@link ClientHTTPException} with the specified status code.
78: *
79: * @throws IllegalArgumentException
80: * If <tt>statusCode</tt> is not in the 4xx range.
81: */
82: public ClientHTTPException(int statusCode, Throwable t) {
83: super (statusCode, t);
84: }
85:
86: @Override
87: protected void setStatusCode(int statusCode) {
88: if (statusCode < 400 || statusCode > 499) {
89: throw new IllegalArgumentException(
90: "Status code must be in the 4xx range, is: "
91: + statusCode);
92: }
93:
94: super.setStatusCode(statusCode);
95: }
96: }
|