Java Code Examples for javax.ws.rs.client.ClientRequestContext#getHeaderString()
The following examples show how to use
javax.ws.rs.client.ClientRequestContext#getHeaderString() .
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: ProducesConsumesFilter.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext ctx) throws IOException { String contentType = ctx.getHeaderString(HttpHeaders.CONTENT_TYPE); String accept = ctx.getHeaderString(HttpHeaders.ACCEPT); ctx.abortWith(Response.ok() .header("Sent-Accept", accept) .header("Sent-ContentType", contentType) .build()); }
Example 2
Source File: ReturnWithSpecifiedHeaderFilter.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext clientRequestContext) throws IOException { String headerValue = null; Object headerName = clientRequestContext.getEntity(); if (headerName != null) { headerValue = clientRequestContext.getHeaderString(headerName.toString()); } clientRequestContext.abortWith(Response.ok(headerValue == null ? "null" : headerValue).build()); }
Example 3
Source File: BeanParamFilter.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext clientRequestContext) throws IOException { String body = (String)clientRequestContext.getEntity(); String query = clientRequestContext.getUri().getQuery(); Cookie cookie = clientRequestContext.getCookies().get("cookie"); String cookieValue = cookie==null?"null":cookie.getValue(); String header = clientRequestContext.getHeaderString("MyHeader"); clientRequestContext.abortWith(Response.ok(query + " " + cookieValue + " " + header + " " + body).build()); }
Example 4
Source File: JaxrsClientExtractor.java From opencensus-java with Apache License 2.0 | 4 votes |
@Nullable @Override public String getUserAgent(ClientRequestContext request) { return request.getHeaderString("user-agent"); }
Example 5
Source File: CacheControlClientRequestFilter.java From cxf with Apache License 2.0 | 4 votes |
@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)); }