Java Code Examples for javax.ws.rs.client.ClientRequestContext#getUri()

The following examples show how to use javax.ws.rs.client.ClientRequestContext#getUri() . 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: HttpClientProducer.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
    final HttpClientRequest httpClientRequest = new HttpClientRequest() {
        @Override
        public void addHeader(String s, String s1) {
            clientRequestContext.getHeaders().add(s, s1);
        }

        @Override
        public URI getUri() {
            return clientRequestContext.getUri();
        }

        @Override
        public String getHttpMethod() {
            return clientRequestContext.getMethod();
        }
    };
    requestInterceptor.handle(new HttpClientRequestAdapter(httpClientRequest, spanNameProvider));
}
 
Example 2
Source File: JaxrsClientExtractor.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getHost(ClientRequestContext request) {
  if (request == null) {
    return "null_request";
  } else if (request.getUri() == null) {
    return "null_uri";
  } else {
    return request.getUri().getHost();
  }
}
 
Example 3
Source File: BraveClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
    final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getStringHeaders(),
        requestContext.getUri(), requestContext.getMethod());

    if (holder != null) {
        requestContext.setProperty(TRACE_SPAN, holder);
    }
}
 
Example 4
Source File: OpenTracingClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
    final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getStringHeaders(),
        requestContext.getUri(), requestContext.getMethod());

    if (holder != null) {
        requestContext.setProperty(TRACE_SPAN, holder);
    }
}
 
Example 5
Source File: CacheControlClientRequestFilter.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public void filter(final ClientRequestContext request) throws IOException {
    if (!HttpMethod.GET.equals(request.getMethod())) {
        //TODO: Review the possibility of supporting POST responses, example,
        //      POST create request may get a created entity representation returned
        request.setProperty(NO_CACHE_PROPERTY, "true");
        return;
    }
    final URI uri = request.getUri();
    final String accepts = request.getHeaderString(HttpHeaders.ACCEPT);
    final Key key = new Key(uri, accepts);
    Entry entry = cache.get(key);
    if (entry != null) {
        //TODO: do the extra validation against the conditional headers
        //      which may be contained in the current request
        if (entry.isOutDated()) {
            String ifNoneMatchHeader = entry.getCacheHeaders().get(HttpHeaders.IF_NONE_MATCH);
            String ifModifiedSinceHeader = entry.getCacheHeaders().get(HttpHeaders.IF_MODIFIED_SINCE);

            if (StringUtils.isEmpty(ifNoneMatchHeader) && StringUtils.isEmpty(ifModifiedSinceHeader)) {
                cache.remove(key, entry);
            } else {
                request.getHeaders().add(HttpHeaders.IF_NONE_MATCH, ifNoneMatchHeader);
                request.getHeaders().add(HttpHeaders.IF_MODIFIED_SINCE, ifModifiedSinceHeader);
                request.setProperty(CACHED_ENTITY_PROPERTY, entry.getData());
            }
        } else {
            Object cachedEntity = entry.getData();
            Response.ResponseBuilder ok = Response.ok(cachedEntity);
            if (entry.getHeaders() != null) {
                for (Map.Entry<String, List<String>> h : entry.getHeaders().entrySet()) {
                    for (final Object instance : h.getValue()) {
                        ok = ok.header(h.getKey(), instance);
                    }
                }
            }
            request.setProperty(CACHED_ENTITY_PROPERTY, cachedEntity);
            request.abortWith(ok.build());
        }
    }
    // Should the map of all request headers shared ?
    request.setProperty(CLIENT_ACCEPTS, accepts);
    request.setProperty(CLIENT_CACHE_CONTROL, request.getHeaderString(HttpHeaders.CACHE_CONTROL));
}