@Override public String toString() { return getCode() + " - " + getDescription(); }
/** * Constructor with status code * @param statusCode HTTP status code */ public HttpStatusCodeException(int statusCode) { super(HttpStatus.of(statusCode).map(s -> s.getCode() + " - " + s.getDescription()) .orElse("HTTP status code: " + statusCode)); this.statusCode = statusCode; }
/** * Get a builder to create a default {@link HttpResponse} instance. * @param <T> Payload type * @param status Response status (not null) * @param payloadType Payload type * @return A new {@link HttpResponse} builder */ static <T> Builder<T> builder(HttpStatus status, Class<? extends T> payloadType) { ObjectUtils.argumentNotNull(status, "HTTP status must be not null"); return new DefaultHttpResponse.DefaultBuilder<>(status.getCode(), payloadType); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { // check SecurityContext type if (!AuthContext.class.isAssignableFrom(requestContext.getSecurityContext().getClass())) { throw new IOException("Invalid SecurityContext type: expecting an AuthContext but found [" + requestContext.getSecurityContext().getClass().getName() + "]"); } final AuthContext authContext = (AuthContext) requestContext.getSecurityContext(); // check authenticated if (!authContext.getAuthentication().isPresent()) { LOGGER.debug(() -> "Authenticate request using AuthContext"); // authenticate try { authContext.authenticate(new JaxrsContainerHttpRequest(requestContext), schemes); } catch (UnsupportedMessageException e) { LOGGER.debug(() -> "Authentication error: aborting request", e); requestContext.abortWith(ResponseUtils.buildAuthenticationErrorResponse(schemes, null, null, HttpStatus.UNAUTHORIZED.getCode(), null)); } catch (AuthenticationException e) { LOGGER.debug(() -> "Authentication error: aborting request", e); requestContext.abortWith(ResponseUtils.buildAuthenticationErrorResponse(e, null)); } } }