Skip to content

Commit 1c6614e

Browse files
committed
Add comprehensive Javadoc documentation to org.restheart.exchange package
- Enhanced all 37 classes in org.restheart.exchange package with detailed Javadoc - Added class-level documentation explaining purpose, features, and usage patterns - Documented all public/protected methods with parameters, return values, and exceptions - Included comprehensive examples and cross-references - Improved documentation for Version.java - Follows standard Javadoc conventions for better API documentation
1 parent 3af0bad commit 1c6614e

38 files changed

+4535
-841
lines changed

commons/src/main/java/org/restheart/exchange/BadRequestException.java

Lines changed: 135 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,39 @@
2323
import org.restheart.utils.HttpStatus;
2424

2525
/**
26+
* Exception thrown when a client request is malformed or contains invalid data.
27+
* <p>
28+
* This exception is used throughout the RESTHeart framework to signal various
29+
* types of client errors, typically resulting in HTTP 4xx status codes. It provides
30+
* flexibility in specifying custom status codes, message formats, and content types
31+
* for error responses.
32+
* </p>
33+
* <p>
34+
* The exception supports both plain text and JSON error messages, allowing services
35+
* to return structured error information when appropriate.
36+
* </p>
2637
*
2738
* @author Andrea Di Cesare {@literal <andrea@softinstigate.com>}
2839
*/
2940
public class BadRequestException extends RuntimeException {
30-
/**
31-
*
32-
*/
41+
/** Serial version UID for serialization compatibility. */
3342
private static final long serialVersionUID = -8466126772297299751L;
3443

44+
/** The HTTP status code to be returned with this exception. */
3545
int statusCode = HttpStatus.SC_BAD_REQUEST;
46+
47+
/** Flag indicating whether the exception message is valid JSON. */
3648
private final boolean jsonMessage;
49+
50+
/** The content type to be used in the error response. */
3751
private final String contentType;
3852

3953
/**
40-
*
54+
* Creates a new BadRequestException with default settings.
55+
* <p>
56+
* Uses HTTP 400 (Bad Request) status code, plain text message format,
57+
* and JSON content type.
58+
* </p>
4159
*/
4260
public BadRequestException() {
4361
super();
@@ -46,8 +64,12 @@ public BadRequestException() {
4664
}
4765

4866
/**
67+
* Creates a new BadRequestException with a custom HTTP status code.
68+
* <p>
69+
* Uses plain text message format and JSON content type.
70+
* </p>
4971
*
50-
* @param statusCode
72+
* @param statusCode the HTTP status code to return with this exception
5173
*/
5274
public BadRequestException(int statusCode) {
5375
super();
@@ -57,8 +79,13 @@ public BadRequestException(int statusCode) {
5779
}
5880

5981
/**
82+
* Creates a new BadRequestException with a custom error message.
83+
* <p>
84+
* Uses HTTP 400 (Bad Request) status code, plain text message format,
85+
* and JSON content type.
86+
* </p>
6087
*
61-
* @param message
88+
* @param message the error message to include in the exception
6289
*/
6390
public BadRequestException(String message) {
6491
super(message);
@@ -67,9 +94,13 @@ public BadRequestException(String message) {
6794
}
6895

6996
/**
97+
* Creates a new BadRequestException with a custom error message and message format.
98+
* <p>
99+
* Uses HTTP 400 (Bad Request) status code and JSON content type.
100+
* </p>
70101
*
71-
* @param message
72-
* @param jsonMessage mark message as json, i.e. the string is valid json
102+
* @param message the error message to include in the exception
103+
* @param jsonMessage true if the message is valid JSON, false for plain text
73104
*/
74105
public BadRequestException(String message, boolean jsonMessage) {
75106
super(message);
@@ -78,10 +109,14 @@ public BadRequestException(String message, boolean jsonMessage) {
78109
}
79110

80111
/**
112+
* Creates a new BadRequestException with custom message, format, and content type.
113+
* <p>
114+
* Uses HTTP 400 (Bad Request) status code.
115+
* </p>
81116
*
82-
* @param message
83-
* @param jsonMessage mark message as json, i.e. the string is valid json
84-
* @param contentType error response content type
117+
* @param message the error message to include in the exception
118+
* @param jsonMessage true if the message is valid JSON, false for plain text
119+
* @param contentType the content type to use in the error response
85120
*/
86121
public BadRequestException(String message, boolean jsonMessage, String contentType) {
87122
super(message);
@@ -90,9 +125,13 @@ public BadRequestException(String message, boolean jsonMessage, String contentTy
90125
}
91126

92127
/**
128+
* Creates a new BadRequestException with custom message and status code.
129+
* <p>
130+
* Uses plain text message format and JSON content type.
131+
* </p>
93132
*
94-
* @param message
95-
* @param statusCode
133+
* @param message the error message to include in the exception
134+
* @param statusCode the HTTP status code to return with this exception
96135
*/
97136
public BadRequestException(String message, int statusCode) {
98137
super(message);
@@ -102,10 +141,14 @@ public BadRequestException(String message, int statusCode) {
102141
}
103142

104143
/**
144+
* Creates a new BadRequestException with custom message, status code, and message format.
145+
* <p>
146+
* Uses JSON content type.
147+
* </p>
105148
*
106-
* @param message
107-
* @param statusCode
108-
* @param jsonMessage mark message as json, i.e. the string is valid json
149+
* @param message the error message to include in the exception
150+
* @param statusCode the HTTP status code to return with this exception
151+
* @param jsonMessage true if the message is valid JSON, false for plain text
109152
*/
110153
public BadRequestException(String message, int statusCode, boolean jsonMessage) {
111154
super(message);
@@ -115,11 +158,15 @@ public BadRequestException(String message, int statusCode, boolean jsonMessage)
115158
}
116159

117160
/**
161+
* Creates a new BadRequestException with full customization options.
162+
* <p>
163+
* This constructor provides complete control over all exception properties.
164+
* </p>
118165
*
119-
* @param message
120-
* @param statusCode
121-
* @param jsonMessage mark message as json, i.e. the string is valid json
122-
* @param contentType error response content type
166+
* @param message the error message to include in the exception
167+
* @param statusCode the HTTP status code to return with this exception
168+
* @param jsonMessage true if the message is valid JSON, false for plain text
169+
* @param contentType the content type to use in the error response
123170
*/
124171
public BadRequestException(String message, int statusCode, boolean jsonMessage, String contentType) {
125172
super(message);
@@ -129,9 +176,14 @@ public BadRequestException(String message, int statusCode, boolean jsonMessage,
129176
}
130177

131178
/**
179+
* Creates a new BadRequestException with a message and underlying cause.
180+
* <p>
181+
* Uses HTTP 400 (Bad Request) status code, plain text message format,
182+
* and plain text content type.
183+
* </p>
132184
*
133-
* @param message
134-
* @param cause
185+
* @param message the error message to include in the exception
186+
* @param cause the underlying cause of this exception
135187
*/
136188
public BadRequestException(String message, Throwable cause) {
137189
super(message, cause);
@@ -140,10 +192,14 @@ public BadRequestException(String message, Throwable cause) {
140192
}
141193

142194
/**
195+
* Creates a new BadRequestException with message, cause, and message format.
196+
* <p>
197+
* Uses HTTP 400 (Bad Request) status code and JSON content type.
198+
* </p>
143199
*
144-
* @param message
145-
* @param cause
146-
* @param jsonMessage mark message as json, i.e. the string is valid json
200+
* @param message the error message to include in the exception
201+
* @param jsonMessage true if the message is valid JSON, false for plain text
202+
* @param cause the underlying cause of this exception
147203
*/
148204
public BadRequestException(String message, boolean jsonMessage, Throwable cause) {
149205
super(message, cause);
@@ -152,11 +208,15 @@ public BadRequestException(String message, boolean jsonMessage, Throwable cause)
152208
}
153209

154210
/**
211+
* Creates a new BadRequestException with message, cause, format, and content type.
212+
* <p>
213+
* Uses HTTP 400 (Bad Request) status code.
214+
* </p>
155215
*
156-
* @param message
157-
* @param cause
158-
* @param jsonMessage mark message as json, i.e. the string is valid json
159-
* @param contentType error response content type
216+
* @param message the error message to include in the exception
217+
* @param jsonMessage true if the message is valid JSON, false for plain text
218+
* @param contentType the content type to use in the error response
219+
* @param cause the underlying cause of this exception
160220
*/
161221
public BadRequestException(String message, boolean jsonMessage, String contentType, Throwable cause) {
162222
super(message, cause);
@@ -165,10 +225,14 @@ public BadRequestException(String message, boolean jsonMessage, String contentTy
165225
}
166226

167227
/**
228+
* Creates a new BadRequestException with message, status code, and cause.
229+
* <p>
230+
* Uses plain text message format and JSON content type.
231+
* </p>
168232
*
169-
* @param message
170-
* @param statusCode
171-
* @param cause
233+
* @param message the error message to include in the exception
234+
* @param statusCode the HTTP status code to return with this exception
235+
* @param cause the underlying cause of this exception
172236
*/
173237
public BadRequestException(String message, int statusCode, Throwable cause) {
174238
super(message, cause);
@@ -178,11 +242,15 @@ public BadRequestException(String message, int statusCode, Throwable cause) {
178242
}
179243

180244
/**
245+
* Creates a new BadRequestException with message, status code, format, and cause.
246+
* <p>
247+
* Uses JSON content type.
248+
* </p>
181249
*
182-
* @param message
183-
* @param statusCode
184-
* @param jsonMessage mark message as json, i.e. the string is valid json
185-
* @param cause
250+
* @param message the error message to include in the exception
251+
* @param statusCode the HTTP status code to return with this exception
252+
* @param jsonMessage true if the message is valid JSON, false for plain text
253+
* @param cause the underlying cause of this exception
186254
*/
187255
public BadRequestException(String message, int statusCode, boolean jsonMessage, Throwable cause) {
188256
super(message, cause);
@@ -192,12 +260,17 @@ public BadRequestException(String message, int statusCode, boolean jsonMessage,
192260
}
193261

194262
/**
263+
* Creates a new BadRequestException with full customization and a cause.
264+
* <p>
265+
* This constructor provides complete control over all exception properties
266+
* while also capturing the underlying cause of the error.
267+
* </p>
195268
*
196-
* @param message
197-
* @param statusCode
198-
* @param jsonMessage mark message as json, i.e. the string is valid json
199-
* @param contentType error response content type
200-
* @param cause
269+
* @param message the error message to include in the exception
270+
* @param statusCode the HTTP status code to return with this exception
271+
* @param jsonMessage true if the message is valid JSON, false for plain text
272+
* @param contentType the content type to use in the error response
273+
* @param cause the underlying cause of this exception
201274
*/
202275
public BadRequestException(String message, int statusCode, boolean jsonMessage, String contentType, Throwable cause) {
203276
super(message, cause);
@@ -207,16 +280,36 @@ public BadRequestException(String message, int statusCode, boolean jsonMessage,
207280
}
208281

209282
/**
210-
* @return the statusCode
283+
* Returns the HTTP status code associated with this exception.
284+
*
285+
* @return the HTTP status code to be returned in the error response
211286
*/
212287
public int getStatusCode() {
213288
return statusCode;
214289
}
215290

291+
/**
292+
* Indicates whether the exception message is formatted as valid JSON.
293+
* <p>
294+
* When true, the message can be directly used as JSON content in the response.
295+
* When false, the message should be treated as plain text.
296+
* </p>
297+
*
298+
* @return true if the message is valid JSON, false otherwise
299+
*/
216300
public boolean isJsonMessage() {
217301
return jsonMessage;
218302
}
219303

304+
/**
305+
* Returns the content type to be used in the error response.
306+
* <p>
307+
* This determines how the client should interpret the error message content.
308+
* Common values include "application/json" and "text/plain".
309+
* </p>
310+
*
311+
* @return the content type for the error response
312+
*/
220313
public String contentType() {
221314
return this.contentType;
222315
}

0 commit comments

Comments
 (0)