private static HeaderValueException exception(final String headerName, Object headerValue, Exception e) { return new HeaderValueException(LocalizationMessages.UNABLE_TO_PARSE_HEADER_VALUE(headerName, headerValue), e, HeaderValueException.Context.INBOUND); }
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
Locale detectLocale(HttpHeaders headers) { final List<Locale> languages; try { languages = headers.getAcceptableLanguages(); } catch (HeaderValueException e) { throw new WebApplicationException(e.getMessage(), Response.Status.BAD_REQUEST); } for (Locale locale : languages) { if (!locale.toString().contains("*")) { // Freemarker doesn't do wildcards well return locale; } } return Locale.getDefault(); }
private static HeaderValueException exception(final String headerName, Object headerValue, Exception e) { return new HeaderValueException(LocalizationMessages.UNABLE_TO_PARSE_HEADER_VALUE(headerName, headerValue), e, HeaderValueException.Context.INBOUND); }
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
@Override public Response toResponse(final HeaderValueException e) { debugException(this, e, LOGGER); return status(BAD_REQUEST).entity(e.getMessage() + " ...should value be quoted?").type(TEXT_PLAIN_WITH_CHARSET) .build(); } }
private static HeaderValueException exception(final String headerName, Object headerValue, Exception e) { return new HeaderValueException(LocalizationMessages.UNABLE_TO_PARSE_HEADER_VALUE(headerName, headerValue), e, HeaderValueException.Context.OUTBOUND); }
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
@VisibleForTesting Locale detectLocale(HttpHeaders headers) { final List<Locale> languages; try { languages = headers.getAcceptableLanguages(); } catch (HeaderValueException e) { throw new WebApplicationException(e.getMessage(), Response.Status.BAD_REQUEST); } for (Locale locale : languages) { if (!locale.toString().contains("*")) { // Freemarker doesn't do wildcards well return locale; } } return Locale.getDefault(); }
private static HeaderValueException exception(final String headerName, Object headerValue, Exception e) { return new HeaderValueException(LocalizationMessages.UNABLE_TO_PARSE_HEADER_VALUE(headerName, headerValue), e, HeaderValueException.Context.OUTBOUND); }
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
/** * Get a single typed header value. * * @param name header name. * @param converter from string conversion function. Is expected to throw {@link ProcessingException} * if conversion fails. * @param convertNull if {@code true} this method calls the provided converter even for {@code null}. Otherwise this * method returns the {@code null} without calling the converter. * @return value of the header, or (possibly converted) {@code null} if not present. */ private <T> T singleHeader(String name, Function<String, T> converter, boolean convertNull) { final List<String> values = this.headers.get(name); if (values == null || values.isEmpty()) { return convertNull ? converter.apply(null) : null; } if (values.size() > 1) { throw new HeaderValueException(LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()), HeaderValueException.Context.INBOUND); } Object value = values.get(0); if (value == null) { return convertNull ? converter.apply(null) : null; } try { return converter.apply(HeaderUtils.asString(value, null)); } catch (ProcessingException ex) { throw exception(name, value, ex); } }
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
/** * Get a single typed header value. * * @param name header name. * @param converter from string conversion function. Is expected to throw {@link ProcessingException} * if conversion fails. * @param convertNull if {@code true} this method calls the provided converter even for {@code null}. Otherwise this * method returns the {@code null} without calling the converter. * @return value of the header, or (possibly converted) {@code null} if not present. */ private <T> T singleHeader(String name, Function<String, T> converter, boolean convertNull) { final List<String> values = this.headers.get(name); if (values == null || values.isEmpty()) { return convertNull ? converter.apply(null) : null; } if (values.size() > 1) { throw new HeaderValueException(LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()), HeaderValueException.Context.INBOUND); } Object value = values.get(0); if (value == null) { return convertNull ? converter.apply(null) : null; } try { return converter.apply(HeaderUtils.asString(value, null)); } catch (ProcessingException ex) { throw exception(name, value, ex); } }
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
throw new HeaderValueException( LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()), HeaderValueException.Context.OUTBOUND);
if (((HeaderValueException) throwable).getContext() == HeaderValueException.Context.INBOUND) { return Response.status(Response.Status.BAD_REQUEST).build();
throw new HeaderValueException( LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()), HeaderValueException.Context.OUTBOUND);
private static HeaderValueException exception(final String headerName, Object headerValue, Exception e) { return new HeaderValueException(LocalizationMessages.UNABLE_TO_PARSE_HEADER_VALUE(headerName, headerValue), e, HeaderValueException.Context.OUTBOUND); }
private static HeaderValueException exception(final String headerName, Object headerValue, Exception e) { return new HeaderValueException(LocalizationMessages.UNABLE_TO_PARSE_HEADER_VALUE(headerName, headerValue), e, HeaderValueException.Context.INBOUND); }