Java Code Examples for javax.ws.rs.client.ClientRequestContext#abortWith()
The following examples show how to use
javax.ws.rs.client.ClientRequestContext#abortWith() .
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: InvokedMethodClientRequestFilter.java From cxf with Apache License 2.0 | 6 votes |
@Override public void filter(ClientRequestContext ctx) throws IOException { try { Method m = (Method) ctx.getProperty("org.eclipse.microprofile.rest.client.invokedMethod"); Path path = m.getAnnotation(Path.class); ctx.abortWith(Response.ok("OK") .header("ReturnType", m.getReturnType().getName()) .header("PUT", m.getAnnotation(PUT.class) == null ? "null" : "PUT") .header("Path", path == null ? "null" : path.value()) .header("Parm1", m.getParameters()[0].getType().getName()) .header("Parm1Annotation", m.getParameters()[0].getAnnotations()[0].annotationType().getName()) .header("Parm2", m.getParameters()[1].getType().getName()) .build()); } catch (Throwable t) { t.printStackTrace(); ctx.abortWith(Response.serverError().build()); } }
Example 2
Source File: InvokedMethodRequestFilter.java From microprofile-rest-client with Apache License 2.0 | 6 votes |
@Override public void filter(ClientRequestContext ctx) throws IOException { try { Method m = (Method) ctx.getProperty("org.eclipse.microprofile.rest.client.invokedMethod"); Path path = m.getAnnotation(Path.class); ctx.abortWith(Response.ok("OK") .header("ReturnType", m.getReturnType().getName()) .header("POST", m.getAnnotation(POST.class) == null ? "null" : "POST") .header("Path", path == null ? "null" : path.value()) .build()); } catch (Throwable t) { t.printStackTrace(); ctx.abortWith(Response.serverError().build()); } }
Example 3
Source File: InvocationBuilderImplTest.java From cxf with Apache License 2.0 | 5 votes |
/** {@inheritDoc}*/ @Override public void filter(ClientRequestContext context) throws IOException { MultivaluedMap<String, Object> headers = context.getHeaders(); StringBuilder entity = new StringBuilder(); for (String key : headers.keySet()) { entity.append(key).append('=').append(headers.getFirst(key)).append(';'); } context.abortWith(Response.ok(entity.toString()).build()); }
Example 4
Source File: ClientRequestFilterTest.java From cxf with Apache License 2.0 | 5 votes |
/** {@inheritDoc}*/ @Override public void filter(ClientRequestContext context) throws IOException { Object o = context.getHeaders().getFirst("MyHeader"); Response r = (o instanceof String) ? Response.ok(o).build() : Response.serverError().build(); context.abortWith(r); }
Example 5
Source File: ReturnAllOutboundHeadersFilter.java From cxf with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext requestContext) throws IOException { StringBuilder sb = new StringBuilder(); requestContext.getStringHeaders().forEach((k, v) -> { sb.append(k).append('=').append(v.stream().collect(Collectors.joining(","))) .append(System.lineSeparator()); }); requestContext.abortWith(Response.ok(sb.toString()).build()); }
Example 6
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 7
Source File: CustomHttpMethodFilter.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext clientRequestContext) throws IOException { String httpMethod = clientRequestContext.getMethod(); if ("MYMETHOD".equals(httpMethod)) { clientRequestContext.abortWith(Response.ok(httpMethod).build()); } else { clientRequestContext.abortWith(Response.status(405).entity(httpMethod).build()); } }
Example 8
Source File: ReturnWithAllClientHeadersFilter.java From microprofile-rest-client with Apache License 2.0 | 5 votes |
@Override public void filter(ClientRequestContext clientRequestContext) throws IOException { JsonObjectBuilder allClientHeaders = Json.createObjectBuilder(); MultivaluedMap<String, Object> clientHeaders = clientRequestContext.getHeaders(); for (String headerName : clientHeaders.keySet()) { allClientHeaders.add(headerName, clientHeaders.getFirst(headerName).toString()); } clientRequestContext.abortWith(Response.ok(allClientHeaders.build()).build()); }
Example 9
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 10
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 11
Source File: ReturnWith500RequestFilter.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext clientRequestContext) throws IOException { clientRequestContext.abortWith(Response.serverError().build()); }
Example 12
Source File: CDIManagedProviderTest.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext requestContext) throws IOException { requestContext.abortWith(Response.status(beanManager != null && postConstructInvoked ? 200 : 204).build()); }
Example 13
Source File: JAXRS20ClientServerBookTest.java From cxf with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext context) throws IOException { context.abortWith(Response.status(201).entity(context.getEntity()).type(MediaType.TEXT_XML_TYPE).build()); }
Example 14
Source File: ReturnWith200RequestFilter.java From microprofile-rest-client with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext clientRequestContext) throws IOException { clientRequestContext.abortWith(Response.ok("OK").build()); }
Example 15
Source File: EchoClientReqFilter.java From cxf with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext crc) throws IOException { crc.abortWith(Response.ok(crc.getEntity()).build()); }
Example 16
Source File: HighPriorityClientReqFilter.java From cxf with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext paramClientRequestContext) throws IOException { paramClientRequestContext.abortWith(Response.ok("high").build()); }
Example 17
Source File: HeaderCaptureClientRequestFilter.java From cxf with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext ctx) throws IOException { setOutboundHeaders(ctx.getStringHeaders()); ctx.abortWith(Response.ok("SUCCESS").build()); }
Example 18
Source File: NotFoundClientReqFilter.java From cxf with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext crc) throws IOException { crc.abortWith(Response.status(404).entity(crc.getEntity()).build()); }
Example 19
Source File: LowPriorityClientReqFilter.java From cxf with Apache License 2.0 | 4 votes |
@Override public void filter(ClientRequestContext paramClientRequestContext) throws IOException { paramClientRequestContext.abortWith(Response.ok("low").build()); }
Example 20
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)); }