本文整理匯總了Java中javax.ws.rs.client.ClientResponseContext類的典型用法代碼示例。如果您正苦於以下問題:Java ClientResponseContext類的具體用法?Java ClientResponseContext怎麽用?Java ClientResponseContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClientResponseContext類屬於javax.ws.rs.client包,在下文中一共展示了ClientResponseContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext)
throws IOException {
final Object requestId = requestContext.getProperty(LOGGING_ID_PROPERTY);
final long id = requestId != null ? (Long) requestId : _id.incrementAndGet();
StringBuilder b = (StringBuilder) requestContext.getProperty(LOGGER_BUFFER_PROPERTY);
if (b == null) {
b = new StringBuilder();
requestContext.setProperty(LOGGER_BUFFER_PROPERTY, b);
}
printResponseLine(b, "Client response received", id, responseContext.getStatus());
printPrefixedHeaders(b, id, RESPONSE_PREFIX, responseContext.getHeaders());
if (printEntity && responseContext.hasEntity() && isSupportPrintType(responseContext.getMediaType())) {
responseContext.setEntityStream(logInboundEntity(b, responseContext.getEntityStream(),
MessageUtils.getCharset(responseContext.getMediaType())));
}
log(b);
}
示例2: 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 );
}
}
}
}
}
示例3: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
logger.info("getAllowedMethods : " + responseContext.getAllowedMethods());
logger.info("getCookies : " + responseContext.getCookies());
logger.info("getDate : " + responseContext.getDate());
logger.info("getEntityStream : " + responseContext.getEntityStream());
logger.info("getEntityTag : " + responseContext.getEntityTag());
logger.info("getHeaders : " + responseContext.getHeaders());
logger.info("getLanguage : " + responseContext.getLanguage());
logger.info("getLastModified : " + responseContext.getLastModified());
logger.info("getLength : " + responseContext.getLength());
logger.info("getLinks : " + responseContext.getLinks());
logger.info("getLocation : " + responseContext.getLocation());
logger.info("getMediaType : " + responseContext.getMediaType());
logger.info("getStatus : " + responseContext.getStatus());
logger.info("getStatusInfo : " + responseContext.getStatusInfo());
responseContext.getHeaders().putSingle(CONTENT_TYPE_STRING,
requestContext.getHeaderString(CONTENT_TYPE_STRING));
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:20,代碼來源:MyClientResponseFilter.java
示例4: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
logger.info("getAllowedMethods : " + responseContext.getAllowedMethods());
logger.info("getCookies : " + responseContext.getCookies());
logger.info("getDate : " + responseContext.getDate());
logger.info("getEntityStream : " + responseContext.getEntityStream());
logger.info("getEntityTag : " + responseContext.getEntityTag());
logger.info("getHeaders : " + responseContext.getHeaders());
logger.info("getLanguage : " + responseContext.getLanguage());
logger.info("getLastModified : " + responseContext.getLastModified());
logger.info("getLength : " + responseContext.getLength());
logger.info("getLinks : " + responseContext.getLinks());
logger.info("getLocation : " + responseContext.getLocation());
logger.info("getMediaType : " + responseContext.getMediaType());
logger.info("getStatus : " + responseContext.getStatus());
logger.info("getStatusInfo : " + responseContext.getStatusInfo());
}
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:18,代碼來源:OtherClientResponseFilter.java
示例5: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
System.out.println("Response = " + requestContext + " " + responseContext);
Long start = concurrentRequests.get(requestContext);
concurrentRequests.remove(requestContext);
long duration = (System.nanoTime() - start);
System.out.println("Duration: " + duration);
URI uri = requestContext.getUri();
String ipv4 = extractIpAddress(uri);
System.out.println("ipv4 = " + ipv4);
String serviceName = extractServiceName(uri);
System.out.println("serviceName = " + serviceName);
String spanName = uri.getPath();
System.out.println("spanName = " + spanName);
String traceId = extractTraceId(requestContext).orElse("--no spanid--");
Boolean spanExists = Optional.ofNullable(requestContext.getProperty(SPAN_EXISTED)).
map((o) -> (boolean) o).
orElse(false);
if (spanExists) {
this.tracEE.saveChildSpan(traceId, spanName, serviceName, ipv4, duration);
} else {
this.tracEE.saveParentSpan(spanName, serviceName, ipv4, duration);
}
}
示例6: 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);
}
}
示例7: 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)));
}
示例8: response
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Test
public void response() throws IOException {
final String key = UUID.randomUUID().toString();
final String key2 = UUID.randomUUID().toString();
final String value = UUID.randomUUID().toString();
final MultivaluedMap<String, String> map = new MultivaluedMapImpl<>();
map.add(key, value);
map.addAll(key2, Collections.emptyList());
final ClientRequestContext ctx = Mockito.mock(ClientRequestContext.class);
final ClientResponseContext ctx2 = Mockito.mock(ClientResponseContext.class);
Mockito.when(ctx2.getHeaders()).thenReturn(map);
Mockito.when(ctx2.getStatusInfo()).thenReturn(Mockito.mock(Response.StatusType.class));
final RoboZonkyFilter filter = new RoboZonkyFilter();
filter.filter(ctx, ctx2);
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(filter.getLastResponseHeader(key)).contains(value);
softly.assertThat(filter.getLastResponseHeader(key2)).isEmpty();
});
}
示例9: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (LOG.isTraceEnabled()) {
LOG.trace("Response status: {} {}", responseContext.getStatus(), responseContext.getStatusInfo().toString());
LOG.trace("Response headers: {}", responseContext.getHeaders());
InputStream stream = responseContext.getEntityStream();
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = stream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
stream.close();
LOG.trace("Response body: {}", result.toString("UTF-8"));
responseContext.setEntityStream(new ByteArrayInputStream(result.toByteArray()));
}
}
示例10: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
SpanWrapper spanWrapper = CastUtils
.cast(requestContext.getProperty(PROPERTY_NAME), SpanWrapper.class);
if (spanWrapper != null && !spanWrapper.isFinished()) {
log.finest("Finishing client span");
if (spanDecorators != null) {
for (ClientSpanDecorator decorator: spanDecorators) {
decorator.decorateResponse(responseContext, spanWrapper.get());
}
}
spanWrapper.finish();
}
}
示例11: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
@Override
public void filter(ClientRequestContext request, ClientResponseContext response) throws IOException {
StringBuilder debugMsgBuilder = new StringBuilder();
debugMsgBuilder.append("ClientRequest: ").append(request.getMethod()).append("\t");
debugMsgBuilder.append(request.getUri().toASCIIString()).append("\t");
appendObjectHeaders(debugMsgBuilder, "> ", request.getHeaders().entrySet());
appendStringHeaders(debugMsgBuilder, "< ", response.getHeaders().entrySet());
debugMsgBuilder.append(response.getStatusInfo()).append(", length=").append(response.getLength()).append(" ");
Long requestStartTime = (Long) request.getProperty(PROPERTY_NANOS);
if (requestStartTime != null) {
debugMsgBuilder
.append((System.nanoTime() - requestStartTime) / MILLISECONDS_PER_NANOSECOND)
.append(" ms\t");
}
LOG.debug(debugMsgBuilder.toString());
RequestLog.stopTiming(CLIENT_TOTAL_TIMER);
}
示例12: 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);
}
}
}
示例13: filter
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
/**
* Intercepts the client response flow and extract response information
* to be published to the DAS server for tracing.
*/
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
long time = new Date().getTime();
TraceEvent traceEvent = (TraceEvent) requestContext.getProperty(TRACE_EVENT_ATTRIBUTE);
if (traceEvent != null) {
TraceEvent endTraceEvent = new TraceEvent(
TracingConstants.CLIENT_TRACE_END,
traceEvent.getTraceId(),
traceEvent.getOriginId(),
time
);
endTraceEvent.setStatusCode(responseContext.getStatus());
TracingUtil.pushToDAS(endTraceEvent, dasUrl);
}
}
示例14: 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());
}
}
示例15: stripResponse
import javax.ws.rs.client.ClientResponseContext; //導入依賴的package包/類
private void stripResponse(ClientResponseContext responseContext) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = responseContext.getEntityStream();
final StringBuilder b = new StringBuilder();
try {
if (in.available() > 0) {
ReaderWriter.writeTo(in, out);
StringBuffer sbuf = new StringBuffer(new String(out.toByteArray()));
if (sbuf.indexOf(ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX) == 0) {
if (log.isDebugEnabled()) { log.debug("Stripping "+ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX); }
responseContext.setEntityStream(new ByteArrayInputStream(sbuf.substring(ALLOW_ILLEGAL_RESOURCE_CALL_PREFIX.length()).getBytes()));
} else {
responseContext.setEntityStream(new ByteArrayInputStream(out.toByteArray()));
} // end if
} // end if
} catch (IOException ex) {
throw new ContainerException(ex);
} // end try/catch
}