本文整理匯總了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 );
}
}
}
}
}
示例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);
}
}
示例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)));
}
示例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);
}
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
}
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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");
}
}
示例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");
}
}
示例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());
}
示例14: isSuccess
import javax.ws.rs.client.ClientResponseContext; //導入方法依賴的package包/類
private boolean isSuccess(ClientResponseContext response) {
return 200 <= response.getStatus() && response.getStatus() < 300;
}
示例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();
}