當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientResponseContext.getStatus方法代碼示例

本文整理匯總了Java中javax.ws.rs.client.ClientResponseContext.getStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientResponseContext.getStatus方法的具體用法?Java ClientResponseContext.getStatus怎麽用?Java ClientResponseContext.getStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.client.ClientResponseContext的用法示例。


在下文中一共展示了ClientResponseContext.getStatus方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter( final ClientRequestContext requestContext, final ClientResponseContext responseContext )
  throws IOException
{
  if ( Response.Status.UNAUTHORIZED.getStatusCode() == responseContext.getStatus() )
  {
    final List<Object> headers = requestContext.getHeaders().get( HttpHeaders.AUTHORIZATION );
    if ( null == headers )
    {
      return;
    }
    for ( final Object header : headers )
    {
      if ( header instanceof String )
      {
        final String headerValue = (String) header;
        if ( headerValue.startsWith( AUTH_HEADER_PREFIX ) )
        {
          final String token = headerValue.substring( AUTH_HEADER_PREFIX.length() );
          _keycloak.invalidate( token );
        }
      }
    }
  }
}
 
開發者ID:realityforge,項目名稱:keycloak-jaxrs-client-authfilter,代碼行數:26,代碼來源:BearerAuthFilter.java

示例2: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext)
        throws IOException
{
    // for non-200 response, deal with the custom error messages
    if (! Response.Status.Family.SUCCESSFUL.equals(responseContext.getStatusInfo().getFamily())) {
        MetaData metaData = MetaData.builder()
                .httpRequestMetaData(getRequestMetaData(requestContext))
                .httpResponseMetaData(getResponseMetaData(responseContext))
                .gotAnswer(true)
                .targetName(serviceDefinition.getName())
                .build();
        if (Response.Status.NOT_FOUND.getStatusCode() == responseContext.getStatus()) {
            throw new ExternalResourceNotFoundException(metaData);
        }
        throw new ExternalResourceException(metaData);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:19,代碼來源:ClientErrorResponseFilter.java

示例3: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(final ClientRequestContext clientRequestContext,
                   final ClientResponseContext clientResponseContext) throws IOException {
    this.logger.debug("HTTP {} Response from {}: {} {}.", clientRequestContext.getMethod(),
                      clientRequestContext.getUri(), clientResponseContext.getStatus(),
                      clientResponseContext.getStatusInfo().getReasonPhrase());
    final String responseEntity = getResponseEntity(clientResponseContext);
    if (clientResponseContext.getStatus() == 400) {
        if (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().size() > 0)
            .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get(0)));
}
 
開發者ID:RoboZonky,項目名稱:robozonky,代碼行數:17,代碼來源:RoboZonkyFilter.java

示例4: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    if (responseContext.getStatus() != Response.Status.OK.getStatusCode() && responseContext.hasEntity()) {
        try {
            final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            final Error error = (Error) unmarshaller.unmarshal(responseContext.getEntityStream());

            final Response.ResponseBuilder builder = Response.status(responseContext.getStatusInfo());
            builder.entity(error);
            // copy response headers
            for (Map.Entry<String, List<String>> header : responseContext.getHeaders().entrySet()) {
                builder.header(header.getKey(), header.getValue());
            }

            throw new LinkedInException(error, builder.build());
        } catch (JAXBException e) {
            // log and ignore
            LOG.warn("Unable to parse LinkedIn error: " + e.getMessage(), e);
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:LinkedInExceptionResponseFilter.java

示例5: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(final ClientRequestContext requestContext,
                   final ClientResponseContext responseContext) {
    try {
        // For non-200 response, log the custom error message.
        if (responseContext.getStatus() != Response.Status.OK.getStatusCode()) {
            if (responseContext.hasEntity()) {
                String error = CharStreams.toString(
                    new InputStreamReader(responseContext.getEntityStream(), Charsets.UTF_8));
                LOG.severe(error);
                System.err.println(error);
            }
        }
    } catch (Exception e) {
        // Silently pass. We don't want anything to fail because of this filter.
        LOG.warning("Error while checking response code: " + e.getMessage());
    }
}
 
開發者ID:qubole,項目名稱:qds-sdk-java,代碼行數:19,代碼來源:ErrorResponseFilter.java

示例6: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:docker-java,項目名稱:docker-java,代碼行數:27,代碼來源:ResponseStatusExceptionFilter.java

示例7: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
  public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
      
// TODO - add other non-error responses here
      if (responseContext.getStatus() != Response.Status.OK.getStatusCode() &&
      		responseContext.getStatus() != Response.Status.CREATED.getStatusCode()) {
          if (responseContext.hasEntity()) {
              // get the "real" error message
              Error error = _MAPPER.readValue(responseContext.getEntityStream(), Error.class);

              Response.Status status = Response.Status.fromStatusCode(responseContext.getStatus());
              MaxinetWebException maxinetException;
              switch (status) {
                  case INTERNAL_SERVER_ERROR:
                  	maxinetException = new MaxinetInternalException(error.getMessage(), responseContext.getStatus());
                      break;
                  case BAD_REQUEST:
                  	maxinetException = new MaxinetClientException(error.getMessage(), responseContext.getStatus());
                      break;
                  default:
                  	maxinetException = new MaxinetWebException(error.getMessage(), responseContext.getStatus());
              }

              throw maxinetException;
          }
      }
  }
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:28,代碼來源:ErrorResponseFilter.java

示例8: formatMessage

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
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);
}
 
開發者ID:ocadotechnology,項目名稱:newrelic-alerts-configurator,代碼行數:8,代碼來源:NewRelicClientException.java

示例9: shouldLogEntity

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private static boolean shouldLogEntity(final ClientResponseContext responseCtx) {
    if (!responseCtx.hasEntity()) {
        return false;
    } else if (responseCtx.getStatus() < 400) {
        return Settings.INSTANCE.isDebugHttpResponseLoggingEnabled();
    } else {
        return true;
    }
}
 
開發者ID:RoboZonky,項目名稱:robozonky,代碼行數:10,代碼來源:RoboZonkyFilter.java

示例10: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
    if (responseContext.getStatus() == SC_BAD_REQUEST) {
        throw new ClcBadRequestException(responseContext);
    } else if (responseContext.getStatus() >= 400) {
        throw new ClcHttpClientException(responseContext);
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:clc-java-sdk,代碼行數:9,代碼來源:ErrorProcessingFilter.java

示例11: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
	if (200 == responseContext.getStatus() && responseContext.getHeaderString(HttpHeaders.CONTENT_TYPE) != null
			&& responseContext.getHeaderString(HttpHeaders.CONTENT_TYPE).toLowerCase().startsWith("text/html")) {
		responseContext.getHeaders().remove(HttpHeaders.CONTENT_TYPE);
		responseContext.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
	}
}
 
開發者ID:Stratehm,項目名稱:multipool-stats-backend,代碼行數:9,代碼來源:TextHtmlJsonFilter.java

示例12: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
	if (200 == responseContext.getStatus() && responseContext.getHeaderString(HttpHeaders.CONTENT_TYPE) != null
			&& responseContext.getHeaderString(HttpHeaders.CONTENT_TYPE).equalsIgnoreCase("binary/octet-stream")) {
		responseContext.getHeaders().remove(HttpHeaders.CONTENT_TYPE);
		responseContext.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
	}
}
 
開發者ID:Stratehm,項目名稱:multipool-stats-backend,代碼行數:9,代碼來源:BinaryJsonFilter.java

示例13: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException
{
    if (requestContext == null || responseContext == null || responseContext.getStatus() != Response.Status.FOUND.getStatusCode()) {
       return;
    }

    log.debug("Processing redirect for " + requestContext.getMethod() + " " + requestContext.getUri().toASCIIString() + " to " + responseContext.getLocation().toASCIIString());

    Client inClient = requestContext.getClient();
    Object entity = requestContext.getEntity();
    MultivaluedMap<String, Object> headers = requestContext.getHeaders();
    String method = requestContext.getMethod();
    Response resp;
    if ("POST".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method)) {
        resp = inClient.target(responseContext.getLocation())
                .request(requestContext.getMediaType())
                .headers(headers)
                .method(requestContext.getMethod(), Entity.entity(new GenericEntity<JAXBElement<?>>((JAXBElement<?>)entity) {}, NsiConstants.NSI_DDS_V1_XML));
    }
    else {
        resp = inClient.target(responseContext.getLocation())
                .request(requestContext.getMediaType())
                .headers(headers)
                .method(requestContext.getMethod());
    }

    responseContext.setEntityStream((InputStream) resp.getEntity());
    responseContext.setStatusInfo(resp.getStatusInfo());
    responseContext.setStatus(resp.getStatus());
    responseContext.getHeaders().putAll(resp.getStringHeaders());

    log.debug("Processing redirect with result " + resp.getStatus());
}
 
開發者ID:BandwidthOnDemand,項目名稱:nsi-dds,代碼行數:35,代碼來源:RestClient.java

示例14: isSuccess

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private boolean isSuccess(ClientResponseContext response) {
    return 200 <= response.getStatus() && response.getStatus() < 300;
}
 
開發者ID:ocadotechnology,項目名稱:newrelic-alerts-configurator,代碼行數:4,代碼來源:NewRelicClientInterceptor.java

示例15: filter

import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ClientRequestContext req, ClientResponseContext resp) throws IOException {
  int status = resp.getStatus();
  tracer.getCurrentSpan().error(status < 200 || status >= 400);
  tracer.closeCurrentSpan();
}
 
開發者ID:chonton,項目名稱:apm-client,代碼行數:7,代碼來源:TraceClientFilter.java


注:本文中的javax.ws.rs.client.ClientResponseContext.getStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。