Java Code Examples for javax.ws.rs.client.ClientResponseContext#getStatus()

The following examples show how to use javax.ws.rs.client.ClientResponseContext#getStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoboZonkyFilter.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(final ClientRequestContext clientRequestContext,
        final ClientResponseContext clientResponseContext) throws IOException {
    logger.debug("HTTP {} Response from {}: {} {}.", clientRequestContext.getMethod(),
            clientRequestContext.getUri(), clientResponseContext.getStatus(),
            clientResponseContext.getStatusInfo()
                .getReasonPhrase());
    final String responseEntity = getResponseEntity(clientResponseContext);
    if (clientResponseContext.getStatus() == 400 && responseEntity.contains("invalid_token")) {
        // Zonky is dumb and throws 400 when it should throw 401
        clientResponseContext.setStatus(401);
    }
    responseHeaders = clientResponseContext.getHeaders()
        .entrySet()
        .stream()
        .filter(e -> !e.getValue()
            .isEmpty())
        .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()
            .get(0), (a, b) -> a, TreeMap::new));
}
 
Example 2
Source File: ResponseStatusExceptionFilter.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    int status = responseContext.getStatus();
    switch (status) {
        case 200:
        case 201:
        case 204:
            return;
        case 304:
            throw new NotModifiedException(getBodyAsMessage(responseContext));
        case 400:
            throw new BadRequestException(getBodyAsMessage(responseContext));
        case 401:
            throw new UnauthorizedException(getBodyAsMessage(responseContext));
        case 404:
            throw new NotFoundException(getBodyAsMessage(responseContext));
        case 406:
            throw new NotAcceptableException(getBodyAsMessage(responseContext));
        case 409:
            throw new ConflictException(getBodyAsMessage(responseContext));
        case 500:
            throw new InternalServerErrorException(getBodyAsMessage(responseContext));
        default:
            throw new DockerException(getBodyAsMessage(responseContext), status);
    }
}
 
Example 3
Source File: BearerAuthFilter.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    if (responseContext.getStatus() == 401 && tokenManager != null) {
        List<Object> authHeaders = requestContext.getHeaders().get(HttpHeaders.AUTHORIZATION);
        if (authHeaders == null) {
            return;
        }
        for (Object authHeader : authHeaders) {
            if (authHeader instanceof String) {
                String headerValue = (String) authHeader;
                if (headerValue.startsWith(AUTH_HEADER_PREFIX)) {
                    String token = headerValue.substring( AUTH_HEADER_PREFIX.length() );
                    tokenManager.invalidate( token );
                }
            }
        }
    }
}
 
Example 4
Source File: NewRelicClientException.java    From newrelic-alerts-configurator with Apache License 2.0 5 votes vote down vote up
private static String formatMessage(ClientRequestContext request, ClientResponseContext response) {
    String method = request.getMethod();
    String url = request.getUri().toString();
    int statusCode = response.getStatus();
    String statusText = response.getStatusInfo().getReasonPhrase();
    return String.format("%s %s: %d %s", method, url, statusCode, statusText);
}
 
Example 5
Source File: RoboZonkyFilter.java    From robozonky with Apache License 2.0 5 votes vote down vote up
private static boolean shouldLogEntity(final ClientResponseContext responseCtx) {
    if (!responseCtx.hasEntity()) {
        return false;
    } else if (responseCtx.getStatus() < 400) {
        return Settings.INSTANCE.isDebugHttpResponseLoggingEnabled();
    } else {
        return true;
    }
}
 
Example 6
Source File: BraveClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void filter(final ClientRequestContext requestContext,
        final ClientResponseContext responseContext) throws IOException {
    final TraceScopeHolder<TraceScope> holder =
        (TraceScopeHolder<TraceScope>)requestContext.getProperty(TRACE_SPAN);
    super.stopTraceSpan(holder, responseContext.getStatus());
}
 
Example 7
Source File: OpenTracingClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void filter(final ClientRequestContext requestContext,
        final ClientResponseContext responseContext) throws IOException {
    final TraceScopeHolder<TraceScope> holder =
        (TraceScopeHolder<TraceScope>)requestContext.getProperty(TRACE_SPAN);
    super.stopTraceSpan(holder, responseContext.getStatus());
}
 
Example 8
Source File: NewRelicClientInterceptor.java    From newrelic-alerts-configurator with Apache License 2.0 4 votes vote down vote up
private boolean isSuccess(ClientResponseContext response) {
    return 200 <= response.getStatus() && response.getStatus() < 300;
}
 
Example 9
Source File: JaxrsClientExtractor.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@Override
public int getStatusCode(@Nullable ClientResponseContext response) {
  return response != null ? response.getStatus() : 0;
}
 
Example 10
Source File: HttpClientProducer.java    From hawkular-apm with Apache License 2.0 4 votes vote down vote up
@Override
public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) throws IOException {
    final HttpResponse response = () -> clientResponseContext.getStatus();

    responseInterceptor.handle(new HttpClientResponseAdapter(response));
}