use of javax.ws.rs.client.CompletionStageRxInvoker in project jersey by jersey.
the class JerseyCompletionStageRxInvokerTest method testNotFoundResponse.
@Test
public void testNotFoundResponse() throws Exception {
CompletionStageRxInvoker invoker = client.target("http://jersey.java.net").request().header("Response-Status", 404).rx();
testInvoker(invoker, 404, false);
}
use of javax.ws.rs.client.CompletionStageRxInvoker in project meecrowave by apache.
the class ProxyServlet method doRequest.
protected CompletionStage<Response> doRequest(final Routes.Route route, final HttpServletRequest req, final HttpServletResponse response, final String prefix) throws IOException {
WebTarget target = route.client.target(route.responseConfiguration.target);
target = target.path(prefix);
final Map<String, String> queryParams = ofNullable(req.getQueryString()).filter(it -> !it.isEmpty()).map(queries -> Stream.of(queries.split("&")).map(it -> {
final int eq = it.indexOf('=');
if (eq > 0) {
return new AbstractMap.SimpleEntry<>(it.substring(0, eq), it.substring(eq + 1));
}
return new AbstractMap.SimpleEntry<>(it, "");
}).collect(toMap(Map.Entry::getKey, Map.Entry::getValue))).orElseGet(Collections::emptyMap);
for (final Map.Entry<String, String> q : queryParams.entrySet()) {
target = target.queryParam(q.getKey(), q.getValue());
}
final String type = route.requestConfiguration.addedHeaders != null ? route.requestConfiguration.addedHeaders.getOrDefault("Content-Type", req.getContentType()) : req.getContentType();
Invocation.Builder request = type != null ? target.request(type) : target.request();
final Enumeration<String> headerNames = req.getHeaderNames();
while (headerNames.hasMoreElements()) {
final String name = headerNames.nextElement();
if (!filterHeader(route.requestConfiguration.skippedHeaders, name)) {
request = request.header(name, list(req.getHeaders(name)));
}
}
if (route.requestConfiguration.addedHeaders != null) {
for (final Map.Entry<String, String> header : route.requestConfiguration.addedHeaders.entrySet()) {
request = request.header(header.getKey(), header.getValue());
}
}
final Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (final Cookie cookie : cookies) {
if (filterCookie(route.requestConfiguration.skippedCookies, cookie.getName(), cookie.getValue())) {
continue;
}
request = request.cookie(new javax.ws.rs.core.Cookie(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getVersion()));
}
}
final CompletionStageRxInvoker rx = request.rx();
final CompletionStage<Response> result;
if (isWrite(req)) {
result = rx.method(req.getMethod(), Entity.entity(req.getInputStream(), ofNullable(req.getContentType()).orElse(MediaType.WILDCARD)));
} else {
result = rx.method(req.getMethod());
}
return result;
}
Aggregations