Skip to content

Commit

Permalink
Set default content type for exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jan 5, 2020
1 parent ba63bd0 commit 20c6753
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ServerResponse<T>
protected int status = StatusCodes.OK;
protected final HeaderMap headers = new HeaderMap();
protected final Map<String, Cookie> cookies = new HashMap<>();
protected String contentType = null;
protected String contentType = javax.ws.rs.core.MediaType.APPLICATION_JSON;
protected T entity;
protected Throwable throwable;
// protected Class<? extends JsonContext> jsonContext;
Expand Down Expand Up @@ -270,11 +270,11 @@ protected void setContentType(String contentType)
{
this.contentType = contentType;

if (this.contentType.equals(javax.ws.rs.core.MediaType.APPLICATION_JSON)) {
if (this.contentType.contains(javax.ws.rs.core.MediaType.APPLICATION_JSON)) {
if (!this.preprocessed) {
this.processJson = true;
}
} else if (this.contentType.equals(javax.ws.rs.core.MediaType.APPLICATION_XML)) {
} else if (this.contentType.contains(javax.ws.rs.core.MediaType.APPLICATION_XML)) {
if (!this.preprocessed) {
this.processXml = true;
}
Expand Down Expand Up @@ -561,6 +561,7 @@ public void send(final HttpHandler handler, final HttpServerExchange exchange) t


if (hasError) {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, javax.ws.rs.core.MediaType.APPLICATION_JSON);
exchange.putAttachment(DefaultResponseListener.EXCEPTION, throwable);
exchange.endExchange();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.undertow.server.RoutingHandler;
import io.undertow.util.HeaderMap;
import io.undertow.util.HeaderValues;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -76,6 +77,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception
{
ServerException serverException = (ServerException) e;
exchange.setStatusCode(serverException.getStatus());
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, javax.ws.rs.core.MediaType.APPLICATION_JSON);
}

defaultResponseListener.handleDefaultResponse(exchange);
Expand Down

0 comments on commit 20c6753

Please sign in to comment.