14
14
import io .undertow .server .handlers .Cookie ;
15
15
import io .undertow .server .handlers .ExceptionHandler ;
16
16
import io .undertow .util .*;
17
- import jakarta .ws .rs .core .Response ;
18
17
import org .slf4j .Logger ;
19
18
import org .slf4j .LoggerFactory ;
20
19
33
32
/**
34
33
* @author jbauer
35
34
* Base server response. Friendlier interface to underlying exchange.
36
- * @TODO extend jakarta.ws.rs.core.Response
37
35
*/
38
36
39
37
public class ServerResponse <T >
@@ -57,7 +55,7 @@ public class ServerResponse<T>
57
55
protected int status = StatusCodes .OK ;
58
56
protected final HeaderMap headers = new HeaderMap ();
59
57
protected final Map <String , Cookie > cookies = new HashMap <>();
60
- protected String contentType = jakarta . ws . rs . core . MediaType .APPLICATION_JSON ;
58
+ protected String contentType = MediaType .APPLICATION_JSON . contentType () ;
61
59
protected T entity ;
62
60
protected Throwable throwable ;
63
61
// protected Class<? extends JsonContext> jsonContext;
@@ -175,14 +173,7 @@ public void setStatus(int status)
175
173
this .status = status ;
176
174
}
177
175
178
- /**
179
- * @param status
180
- * the status to set
181
- */
182
- public void setStatus (Response .Status status )
183
- {
184
- this .status = status .getStatusCode ();
185
- }
176
+
186
177
187
178
public ServerResponse <T > body (ByteBuffer body )
188
179
{
@@ -266,11 +257,7 @@ public ServerResponse<T> throwable(Throwable throwable)
266
257
return this ;
267
258
}
268
259
269
- public ServerResponse <T > status (Response .Status status )
270
- {
271
- this .status = status .getStatusCode ();
272
- return this ;
273
- }
260
+
274
261
275
262
public ServerResponse <T > status (int status )
276
263
{
@@ -301,11 +288,11 @@ protected void setContentType(String contentType)
301
288
{
302
289
this .contentType = contentType ;
303
290
304
- if (this .contentType .contains (jakarta . ws . rs . core . MediaType .APPLICATION_JSON )) {
291
+ if (this .contentType .contains (MediaType .APPLICATION_JSON . contentType () )) {
305
292
if (!this .preprocessed ) {
306
293
this .processJson = true ;
307
294
}
308
- } else if (this .contentType .contains (jakarta . ws . rs . core . MediaType .APPLICATION_XML )) {
295
+ } else if (this .contentType .contains (MediaType .APPLICATION_XML . contentType () )) {
309
296
if (!this .preprocessed ) {
310
297
this .processXml = true ;
311
298
}
@@ -319,12 +306,6 @@ public ServerResponse<T> contentType(String contentType)
319
306
}
320
307
321
308
322
- public ServerResponse <T > contentType (jakarta .ws .rs .core .MediaType mediaType )
323
- {
324
- this .setContentType (mediaType .toString ());
325
- return this ;
326
- }
327
-
328
309
public ServerResponse <T > contentType (MediaType mediaType )
329
310
{
330
311
this .setContentType (mediaType .contentType ());
@@ -336,19 +317,19 @@ public ServerResponse<T> applicationJson()
336
317
if (!this .preprocessed ) {
337
318
this .processJson = true ;
338
319
}
339
- this .contentType = jakarta . ws . rs . core . MediaType .APPLICATION_JSON ;
320
+ this .contentType = MediaType .APPLICATION_JSON . contentType () ;
340
321
return this ;
341
322
}
342
323
343
324
public ServerResponse <T > textHtml ()
344
325
{
345
- this .contentType = jakarta . ws . rs . core . MediaType .TEXT_HTML ;
326
+ this .contentType = MediaType .TEXT_HTML_UTF8 . contentType () ;
346
327
return this ;
347
328
}
348
329
349
330
public ServerResponse <T > applicationOctetStream ()
350
331
{
351
- this .contentType = jakarta . ws . rs . core . MediaType .APPLICATION_OCTET_STREAM ;
332
+ this .contentType = MediaType .APPLICATION_OCTET_STREAM . contentType () ;
352
333
return this ;
353
334
}
354
335
@@ -357,13 +338,13 @@ public ServerResponse<T> applicationXml()
357
338
if (!this .preprocessed ) {
358
339
this .processXml = true ;
359
340
}
360
- this .contentType = jakarta . ws . rs . core . MediaType .APPLICATION_XML ;
341
+ this .contentType = MediaType .APPLICATION_XML . contentType () ;
361
342
return this ;
362
343
}
363
344
364
345
public ServerResponse <T > textPlain ()
365
346
{
366
- this .contentType = jakarta . ws . rs . core . MediaType .TEXT_PLAIN ;
347
+ this .contentType = MediaType .TEXT_PLAIN_UTF8 . contentType () ;
367
348
return this ;
368
349
}
369
350
0 commit comments