Added sendError(int) to HttpFacade.Response.

This commit is contained in:
Thomas Raehalme 2015-11-06 09:52:41 +02:00
parent 15828e899b
commit 7b7fbd3257
7 changed files with 51 additions and 0 deletions

View file

@ -56,6 +56,7 @@ public interface HttpFacade {
void resetCookie(String name, String path); void resetCookie(String name, String path);
void setCookie(String name, String value, String path, String domain, int maxAge, boolean secure, boolean httpOnly); void setCookie(String name, String value, String path, String domain, int maxAge, boolean secure, boolean httpOnly);
OutputStream getOutputStream(); OutputStream getOutputStream();
void sendError(int code);
void sendError(int code, String message); void sendError(int code, String message);
/** /**

View file

@ -132,6 +132,13 @@ public class JaxrsHttpFacade implements OIDCHttpFacade {
throw new IllegalStateException("Not supported yet"); throw new IllegalStateException("Not supported yet");
} }
@Override
public void sendError(int code) {
javax.ws.rs.core.Response response = responseBuilder.status(code).build();
requestContext.abortWith(response);
responseFinished = true;
}
@Override @Override
public void sendError(int code, String message) { public void sendError(int code, String message) {
javax.ws.rs.core.Response response = responseBuilder.status(code).entity(message).build(); javax.ws.rs.core.Response response = responseBuilder.status(code).entity(message).build();

View file

@ -170,6 +170,15 @@ public class JettyHttpFacade implements HttpFacade {
} }
} }
@Override
public void sendError(int code) {
try {
response.sendError(code);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void sendError(int code, String message) { public void sendError(int code, String message) {
try { try {

View file

@ -156,6 +156,15 @@ public class ServletHttpFacade implements HttpFacade {
} }
} }
@Override
public void sendError(int code) {
try {
response.sendError(code);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void sendError(int code, String message) { public void sendError(int code, String message) {
try { try {

View file

@ -95,6 +95,15 @@ class WrappedHttpServletResponse implements Response {
} }
} }
@Override
public void sendError(int code) {
try {
response.sendError(code);
} catch (IOException e) {
throw new RuntimeException("Unable to set HTTP status", e);
}
}
@Override @Override
public void sendError(int code, String message) { public void sendError(int code, String message) {
try { try {

View file

@ -167,6 +167,15 @@ public class CatalinaHttpFacade implements HttpFacade {
} }
} }
@Override
public void sendError(int code) {
try {
response.sendError(code);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void sendError(int code, String message) { public void sendError(int code, String message) {
try { try {
@ -176,6 +185,7 @@ public class CatalinaHttpFacade implements HttpFacade {
} }
} }
@Override @Override
public void end() { public void end() {
ended = true; ended = true;

View file

@ -170,6 +170,12 @@ public class UndertowHttpFacade implements HttpFacade {
return exchange.getOutputStream(); return exchange.getOutputStream();
} }
@Override
public void sendError(int code) {
exchange.setResponseCode(code);
exchange.endExchange();
}
@Override @Override
public void sendError(int code, String message) { public void sendError(int code, String message) {
exchange.setResponseCode(code); exchange.setResponseCode(code);