@Override public Response toResponse(WebApplicationException exception) { logger.error(String.format("Error %s url: '%s'", exception.getClass().getSimpleName(), uriInfo.getPath()), exception); Response response = exception.getResponse(); this.code = Code.forValue(response.getStatus()); Map<String, Object> entityMap = new LinkedHashMap<>(); entityMap.put("instance", host); entityMap.put("code", Optional.of(code.toString()).orElse(null)); entityMap.put("message", exception.getCause()); entityMap.put("retryable", false); return Response.status(response.getStatus()).entity(entityMap).build(); }
@Override public Response toResponse(Exception e) { if (e instanceof WebApplicationException) { WebApplicationException exception = (WebApplicationException) e; String message; if (exception.getCause() != null) { message = Log.exceptionStack(exception.getCause()); } else { message = Log.exceptionStack(exception); } return Response.fromResponse(exception.getResponse()).entity(message).build(); } else { return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build(); } }
protected String buildErrorMessage(Response r, WebApplicationException ex) { StringBuilder sb = new StringBuilder(); sb.append(ERROR_MESSAGE_START).append(r.getStatus()); Throwable cause = ex.getCause(); String message = cause == null ? ex.getMessage() : cause.getMessage(); if (message == null && cause != null) { message = "exception cause class: " + cause.getClass().getName(); } if (message != null) { sb.append(", message: ").append(message); } return sb.toString(); }
protected String buildErrorMessage(Response r, WebApplicationException ex) { StringBuilder sb = new StringBuilder(); sb.append(ERROR_MESSAGE_START).append(r.getStatus()); Throwable cause = ex.getCause(); String message = cause == null ? ex.getMessage() : cause.getMessage(); if (message == null && cause != null) { message = "exception cause class: " + cause.getClass().getName(); } if (message != null) { sb.append(", message: ").append(message); } return sb.toString(); }
private List<Locale> getLanguages(final ODataContext context) { try { if (context.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return context.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
private List<Locale> getLanguages(final HttpHeaders httpHeaders) { try { if (httpHeaders.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return httpHeaders.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
@Override public Response toResponse(WebApplicationException exception) { logger.error(String.format("Error %s url: '%s'", exception.getClass().getSimpleName(), uriInfo.getPath()), exception); Response response = exception.getResponse(); this.code = Code.forValue(response.getStatus()); Map<String, Object> entityMap = new LinkedHashMap<>(); entityMap.put("instance", host); entityMap.put("code", Optional.of(code.toString()).orElse(null)); entityMap.put("message", exception.getCause()); entityMap.put("retryable", false); return Response.status(response.getStatus()).entity(entityMap).build(); }
private List<Locale> getLanguages(final HttpHeaders httpHeaders) { try { if (httpHeaders.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return httpHeaders.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
private List<Locale> getLanguages(final HttpHeaders httpHeaders) { try { if (httpHeaders.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return httpHeaders.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
private List<Locale> getLanguages(final ODataContext context) { try { if (context.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return context.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
private List<Locale> getLanguages(final ODataContext context) { try { if (context.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return context.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
private List<Locale> getLanguages(final HttpHeaders httpHeaders) { try { if (httpHeaders.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return httpHeaders.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
private List<Locale> getLanguages(final ODataContext context) { try { if (context.getAcceptableLanguages().isEmpty()) { return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } return context.getAcceptableLanguages(); } catch (WebApplicationException e) { if (e.getCause() != null && e.getCause().getClass() == ParseException.class) { // invalid accept-language string in http header // compensate exception with using default locale return Arrays.asList(DEFAULT_RESPONSE_LOCALE); } // not able to compensate exception -> re-throw throw e; } }
@Override public Response toResponse(Throwable t) { if (t instanceof WebApplicationException) { WebApplicationException webEx = (WebApplicationException) t; if(webEx.getResponse().getStatus() == 500) { this.logger.error("Internal server error while handling a request", webEx); //Important: WebApplications with different status don't get logged //they are used for building responses that are a expected behaviour //but have a different http status } ResponseBuilder rb = Response.status(webEx.getResponse().getStatus()); String message = webEx.getLocalizedMessage(); if (webEx.getCause() != null) { message = message + " caused by " + webEx.getCause().toString(); } return rb.entity(message).type(MediaType.TEXT_PLAIN).build(); } ResponseBuilder rb = Response.status(Status.INTERNAL_SERVER_ERROR); String message = t.toString(); this.logger.error("Error while HTTP Request on the Server", t); return rb.entity(message).type(MediaType.TEXT_PLAIN).build(); }
@Override public Response toResponse(final WebApplicationException exception) { LOGGER.debug("{}", exception.getClass()); LOGGER.debug("{}", exception.getCause() == null ? "No cause" : exception.getCause().getClass()); LOGGER.error("{}", exception.getMessage()); try { throw exception.getCause(); } catch (final UnmarshalException ex) { LOGGER.warn("Unable to unmarshal payload"); return Response.status(Response.Status.BAD_REQUEST) .entity(exception.getMessage()) .type(MediaType.TEXT_PLAIN) .build(); } catch (final Throwable ex) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR) .entity(exception.getMessage()) .type(MediaType.TEXT_PLAIN) .build(); } }
@Override public Response toResponse(final WebApplicationException e) { LOGGER.warn( "WebApplicationException intercepted by WebApplicationExceptionMapper: {}\n", e.getMessage()); debugException(this, e, LOGGER); final String msg = null == e.getCause() ? e.getMessage() : e.getCause().getMessage(); // 204, 205, 304 MUST NOT contain an entity body - RFC2616 switch (e.getResponse().getStatus()) { case 204: case 205: case 304: return fromResponse(e.getResponse()).entity(null).build(); default: return fromResponse(e.getResponse()).entity(msg).type(TEXT_PLAIN_WITH_CHARSET).build(); } } }
public Response toResponse(WebApplicationException exception) { if (exception.getResponse().getStatus() == 500) { return Response.status(500).type("text/plain") .entity(exception.getCause().getMessage()).build(); } return super.toResponse(exception); }
if (OAuth2Exception.class.isInstance(wae.getCause())) { // OAuth2Exception is the marker to transport a Response
WebApplicationException webEx = (WebApplicationException)ex; if (webEx.getResponse().hasEntity() && webEx.getCause() == null) { Object prop = inMessage.getContextualProperty(SUPPORT_WAE_SPEC_OPTIMIZATION); if (MessageUtils.isTrue(prop)) {