当前位置: 首页>>代码示例>>Java>>正文


Java ClientRequestContext类代码示例

本文整理汇总了Java中javax.ws.rs.client.ClientRequestContext的典型用法代码示例。如果您正苦于以下问题:Java ClientRequestContext类的具体用法?Java ClientRequestContext怎么用?Java ClientRequestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClientRequestContext类属于javax.ws.rs.client包,在下文中一共展示了ClientRequestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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);
}
 
开发者ID:icode,项目名称:ameba,代码行数:26,代码来源:LoggingFilter.java

示例2: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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

示例3: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的package包/类
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
	logger.info("getAcceptableLanguages : " + requestContext.getAcceptableLanguages());
	logger.info("getClient : " + requestContext.getClient());
	logger.info("getConfiguration : " + requestContext.getConfiguration());
	logger.info("getCookies : " + requestContext.getCookies());
	logger.info("getDate : " + requestContext.getDate());
	logger.info("getEntity : " + requestContext.getEntity());
	logger.info("getEntityAnnotations : " + requestContext.getEntityAnnotations());
	logger.info("getEntityClass : " + requestContext.getEntityClass());
	logger.info("getEntityStream : " + requestContext.getEntityStream());
	logger.info("getEntityType : " + requestContext.getEntityType());
	logger.info("getHeaders : " + requestContext.getHeaders());
	logger.info("getLanguage : " + requestContext.getLanguage());
	logger.info("getMediaType : " + requestContext.getMediaType());
	logger.info("getMethod : " + requestContext.getMethod());
	logger.info("getPropertyNames : " + requestContext.getPropertyNames());
	logger.info("getStringHeaders : " + requestContext.getStringHeaders());
	logger.info("getUri : " + requestContext.getUri());
	requestContext.getHeaders().add(CONTENT_TYPE_STRING, TEXT_HTML);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:MyClientRequestFilter.java

示例4: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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

示例5: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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

示例6: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的package包/类
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
	logger.info("getAcceptableLanguages : " + requestContext.getAcceptableLanguages());
	logger.info("getClient : " + requestContext.getClient());
	logger.info("getConfiguration : " + requestContext.getConfiguration());
	logger.info("getCookies : " + requestContext.getCookies());
	logger.info("getDate : " + requestContext.getDate());
	logger.info("getEntity : " + requestContext.getEntity());
	logger.info("getEntityAnnotations : " + requestContext.getEntityAnnotations());
	logger.info("getEntityClass : " + requestContext.getEntityClass());
	logger.info("getEntityStream : " + requestContext.getEntityStream());
	logger.info("getEntityType : " + requestContext.getEntityType());
	logger.info("getHeaders : " + requestContext.getHeaders());
	logger.info("getLanguage : " + requestContext.getLanguage());
	logger.info("getMediaType : " + requestContext.getMediaType());
	logger.info("getMethod : " + requestContext.getMethod());
	logger.info("getPropertyNames : " + requestContext.getPropertyNames());
	logger.info("getStringHeaders : " + requestContext.getStringHeaders());
	logger.info("getUri : " + requestContext.getUri());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:21,代码来源:OtherClientRequestFilter.java

示例7: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的package包/类
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    String method = clientRequestContext.getMethod();
    URI uri = clientRequestContext.getUri();
    MultivaluedMap<String, Object> headers = clientRequestContext.getHeaders();
    System.out.printf("Sending %s to: %s\n", method, uri);
    System.out.printf("Headers:\n");
    for(String key : headers.keySet()) {
        System.out.printf("  %s: %s\n", key, headers.getFirst(key));
    }
    if(clientRequestContext.hasEntity()) {
        final OutputStream stream = new LoggingStream(clientRequestContext.getEntityStream());
        clientRequestContext.setEntityStream(stream);
        clientRequestContext.setProperty("client.LoggingStream", stream);
    }
}
 
开发者ID:obsidian-toaster-quickstarts,项目名称:redhat-sso,代码行数:17,代码来源:LoggingFilter.java

示例8: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的package包/类
public void filter(ClientRequestContext requestContext) throws IOException {
    int size = 0;
    for (Map.Entry<String, String> entry : RpcContext.getContext().getAttachments().entrySet()) {
        if (entry.getValue().contains(",") || entry.getValue().contains("=")
                || entry.getKey().contains(",") || entry.getKey().contains("=")) {
            throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol");
        }

        // TODO for now we don't consider the differences of encoding and server limit
        size += entry.getValue().getBytes("UTF-8").length;
        if (size > MAX_HEADER_SIZE) {
            throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " is too big");
        }

        StringBuilder attachments = new StringBuilder();
        attachments.append(entry.getKey());
        attachments.append("=");
        attachments.append(entry.getValue());
        requestContext.getHeaders().add(DUBBO_ATTACHMENT_HEADER, attachments.toString());
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:22,代码来源:RpcContextFilter.java

示例9: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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);
    }
}
 
开发者ID:AdamBien,项目名称:SpanEE,代码行数:26,代码来源:SpanEEClientRequestFilter.java

示例10: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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

示例11: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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

示例12: response

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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();
    });
}
 
开发者ID:RoboZonky,项目名称:robozonky,代码行数:20,代码来源:RoboZonkyFilterTest.java

示例13: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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()));
    }
}
 
开发者ID:KTH,项目名称:camel-alma,代码行数:20,代码来源:AlmaResponseFilter.java

示例14: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的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();
    }
}
 
开发者ID:opentracing-contrib,项目名称:java-jaxrs,代码行数:17,代码来源:ClientTracingFilter.java

示例15: filter

import javax.ws.rs.client.ClientRequestContext; //导入依赖的package包/类
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
    if (token == null) {
        throw new IOException("cannot encode with a null token");
    }
    
    forceJerseyBuffering(requestContext);
    
    Consumer<byte[]> dataInterceptor = data -> {
        if (!requestContext.getHeaders().containsKey(header)) {
            String xhubHeaderValue = XHub.generateHeaderXHubToken(getEncoder(), getHash(), token, data);
            requestContext.getHeaders().putSingle(header, xhubHeaderValue);
        }
    };
    
    requestContext.setEntityStream(new ByteArrayInterceptingOutputStream(requestContext.getEntityStream(), dataInterceptor));
}
 
开发者ID:McFoggy,项目名称:xhub4j,代码行数:18,代码来源:XHubClientRequestFilter.java


注:本文中的javax.ws.rs.client.ClientRequestContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。