下面列出了怎么用javax.ws.rs.client.CompletionStageRxInvoker的API类实例代码及写法,或者点击链接到github查看源代码。
public CompletionStage<Response> forward(final InputStream payload, final Function<Response, Response> customizer) {
WebTarget target = client.path(uriInfo.getPath());
for (final Map.Entry<String, List<String>> query : uriInfo.getQueryParameters().entrySet()) {
target = target.queryParam(query.getKey(), query.getValue().toArray(emptyObjectsArray));
}
final MultivaluedMap<String, String> requestHeaders = headers.getRequestHeaders();
final MediaType[] types = headers.getAcceptableMediaTypes().toArray(emptyMediaTypesArray);
final CompletionStageRxInvoker invoker =
target.request(types).headers(MultivaluedMap.class.cast(requestHeaders)).rx();
final CompletionStage<Response> response;
if (payload != null) {
response = invoker.method(request.getMethod(), entity(payload, MediaType.APPLICATION_JSON_TYPE));
} else {
response = invoker.method(request.getMethod());
}
final CompletionStage<Response> decorated = decorate(response);
if (customizer != null) {
return decorated.thenApply(customizer);
}
return decorated;
}
@Override
public UniRxInvoker getRxInvoker(SyncInvoker syncInvoker, ExecutorService executorService) {
if (syncInvoker instanceof ClientInvocationBuilder) {
ClientInvocationBuilder builder = (ClientInvocationBuilder) syncInvoker;
CompletionStageRxInvoker completionStageRxInvoker = builder.rx();
return new UniRxInvokerImpl(completionStageRxInvoker);
} else {
throw new ProcessingException("Expected a ClientInvocationBuilder");
}
}
protected CompletionStageRxInvoker rx(final String path) {
synchronized (clientFactory) {
String original = clientFactory.getAddress();
clientFactory.setAddress(StringUtils.removeEnd(original, "/") + StringUtils.prependIfMissing(path, "/"));
try {
WebClient client = clientFactory.createWebClient().
type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON);
return client.rx();
} finally {
clientFactory.setAddress(original);
}
}
}
@SuppressWarnings({
"rawtypes", "unchecked"
})
public <T extends RxInvoker> T rx(Class<T> rxCls, ExecutorService executorService) {
if (CompletionStageRxInvoker.class.isAssignableFrom(rxCls)) {
return (T)rx(executorService);
}
ClientProviderFactory pf =
ClientProviderFactory.getInstance(WebClient.getConfig(this).getEndpoint());
RxInvokerProvider rxProvider = pf.getRxInvokerProvider();
if (rxProvider != null && rxProvider.isProviderFor(rxCls)) {
return (T)rxProvider.getRxInvoker(sync(), executorService);
}
throw new IllegalStateException("Provider for " + rxCls.getName() + " is not available");
}
public UniRxInvokerImpl(final CompletionStageRxInvoker completionStageRxInvoker) {
this.completionStageRxInvoker = completionStageRxInvoker;
this.UniProvider = new UniProvider();
}
public CompletionStageRxInvoker rx() {
return rx(lookUpExecutorService());
}
public CompletionStageRxInvoker rx(ExecutorService ex) {
return new CompletionStageRxInvokerImpl(this, ex);
}
@Override
public CompletionStageRxInvoker rx() {
return webClient.rx(getConfiguredExecutorService());
}