
com.github.ljtfreitas.restify.http.RestifyProxyBuilder Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
*
* MIT License
*
* Copyright (c) 2016 Tiago de Freitas Lima
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
package com.github.ljtfreitas.restify.http;
import static com.github.ljtfreitas.restify.util.Preconditions.nonNull;
import java.net.Proxy;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import com.github.ljtfreitas.restify.http.client.call.DefaultEndpointCallFactory;
import com.github.ljtfreitas.restify.http.client.call.EndpointCallFactory;
import com.github.ljtfreitas.restify.http.client.call.EndpointMethodExecutor;
import com.github.ljtfreitas.restify.http.client.call.async.DefaultAsyncEndpointCallFactory;
import com.github.ljtfreitas.restify.http.client.call.handler.EndpointCallHandlerProvider;
import com.github.ljtfreitas.restify.http.client.call.handler.EndpointCallHandlers;
import com.github.ljtfreitas.restify.http.client.call.handler.EndpointCallObjectHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.HeadersEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.StatusCodeEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.async.AsyncCallbackEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.async.AsyncEndpointCallObjectHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.CallableEndpointCallHandlerFactory;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.CollectionEndpointCallHandlerFactory;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.CompletionStageCallbackEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.CompletionStageEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.EnumerationEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.FutureEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.FutureTaskEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.IterableEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.IteratorEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.ListIteratorEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.OptionalEndpointCallHandlerFactory;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.QueueEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.RunnableEndpointCallHandlerFactory;
import com.github.ljtfreitas.restify.http.client.call.handler.jdk.StreamEndpointCallHandlerAdapter;
import com.github.ljtfreitas.restify.http.client.jdk.HttpClientRequestConfiguration;
import com.github.ljtfreitas.restify.http.client.jdk.JdkHttpClientRequestFactory;
import com.github.ljtfreitas.restify.http.client.message.Header;
import com.github.ljtfreitas.restify.http.client.message.Headers;
import com.github.ljtfreitas.restify.http.client.message.converter.HttpMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.converter.HttpMessageConverters;
import com.github.ljtfreitas.restify.http.client.message.converter.form.FormURLEncodedMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.converter.form.multipart.MultipartFormMessageWriter;
import com.github.ljtfreitas.restify.http.client.message.converter.json.JsonMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.converter.octet.OctetStreamMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.converter.text.TextMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.converter.wildcard.WildcardMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.converter.xml.XmlMessageConverter;
import com.github.ljtfreitas.restify.http.client.message.response.HttpStatusCode;
import com.github.ljtfreitas.restify.http.client.request.DefaultEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.request.EndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.request.EndpointRequestFactory;
import com.github.ljtfreitas.restify.http.client.request.EndpointRequestWriter;
import com.github.ljtfreitas.restify.http.client.request.EndpointVersion;
import com.github.ljtfreitas.restify.http.client.request.HttpClientRequestFactory;
import com.github.ljtfreitas.restify.http.client.request.async.AsyncEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.request.async.AsyncHttpClientRequestFactory;
import com.github.ljtfreitas.restify.http.client.request.async.DefaultAsyncEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.request.async.interceptor.AsyncEndpointRequestInterceptorChain;
import com.github.ljtfreitas.restify.http.client.request.async.interceptor.AsyncHttpClientRequestInterceptorChain;
import com.github.ljtfreitas.restify.http.client.request.async.interceptor.AsyncInterceptedEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.request.async.interceptor.AsyncInterceptedHttpClientRequestFactory;
import com.github.ljtfreitas.restify.http.client.request.authentication.Authentication;
import com.github.ljtfreitas.restify.http.client.request.interceptor.AcceptVersionHeaderEndpointRequestInterceptor;
import com.github.ljtfreitas.restify.http.client.request.interceptor.EndpointRequestInterceptor;
import com.github.ljtfreitas.restify.http.client.request.interceptor.EndpointRequestInterceptorChain;
import com.github.ljtfreitas.restify.http.client.request.interceptor.HeaderEndpointRequestInterceptor;
import com.github.ljtfreitas.restify.http.client.request.interceptor.HttpClientRequestInterceptor;
import com.github.ljtfreitas.restify.http.client.request.interceptor.HttpClientRequestInterceptorChain;
import com.github.ljtfreitas.restify.http.client.request.interceptor.InterceptedEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.request.interceptor.InterceptedHttpClientRequestFactory;
import com.github.ljtfreitas.restify.http.client.request.interceptor.authentication.AuthenticationEndpoinRequestInterceptor;
import com.github.ljtfreitas.restify.http.client.response.DefaultEndpointResponseErrorFallback;
import com.github.ljtfreitas.restify.http.client.response.EmptyOnNotFoundEndpointResponseErrorFallback;
import com.github.ljtfreitas.restify.http.client.response.EndpointResponseErrorFallback;
import com.github.ljtfreitas.restify.http.client.response.EndpointResponseReader;
import com.github.ljtfreitas.restify.http.client.retry.RetryCondition.EndpointResponseRetryCondition;
import com.github.ljtfreitas.restify.http.client.retry.RetryCondition.HeadersRetryCondition;
import com.github.ljtfreitas.restify.http.client.retry.RetryCondition.StatusCodeRetryCondition;
import com.github.ljtfreitas.restify.http.client.retry.RetryCondition.ThrowableRetryCondition;
import com.github.ljtfreitas.restify.http.client.retry.RetryConfiguration;
import com.github.ljtfreitas.restify.http.client.retry.RetryableEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.client.retry.async.AsyncRetryableEndpointRequestExecutor;
import com.github.ljtfreitas.restify.http.contract.metadata.Contract;
import com.github.ljtfreitas.restify.http.contract.metadata.ContractExpressionResolver;
import com.github.ljtfreitas.restify.http.contract.metadata.ContractReader;
import com.github.ljtfreitas.restify.http.contract.metadata.DefaultContractReader;
import com.github.ljtfreitas.restify.http.contract.metadata.EndpointTarget;
import com.github.ljtfreitas.restify.http.contract.metadata.SimpleContractExpressionResolver;
import com.github.ljtfreitas.restify.spi.Provider;
import com.github.ljtfreitas.restify.util.async.DisposableExecutors;
public class RestifyProxyBuilder {
private final ContractBuilder contractBuilder = new ContractBuilder();
private final EndpointRequestExecutorBuilder endpointRequestExecutorBuilder = new EndpointRequestExecutorBuilder();
private final HttpMessageConvertersBuilder httpMessageConvertersBuilder = new HttpMessageConvertersBuilder();
private final EndpointCallHandlersBuilder endpointCallHandlersBuilder = new EndpointCallHandlersBuilder();
private final EndpointResponseErrorFallbackBuilder endpointResponseErrorFallbackBuilder = new EndpointResponseErrorFallbackBuilder();
private final HttpClientRequestFactoryBuilder httpClientRequestFactoryBuilder = new HttpClientRequestFactoryBuilder();
private final RetryBuilder retryBuilder = new RetryBuilder();
private final AsyncBuilder asyncBuilder = new AsyncBuilder();
private final Provider provider = new Provider();
private ClassLoader classloader = null;
public RestifyProxyBuilder client(HttpClientRequestFactory httpClientRequestFactory) {
this.httpClientRequestFactoryBuilder.httpClientRequestFactory = httpClientRequestFactory;
return this;
}
public HttpClientRequestFactoryBuilder client() {
return httpClientRequestFactoryBuilder;
}
public RestifyProxyBuilder contract(ContractReader contract) {
this.contractBuilder.contract = contract;
return this;
}
public ContractBuilder contract() {
return contractBuilder;
}
public RestifyProxyBuilder executor(EndpointRequestExecutor endpointRequestExecutor) {
this.endpointRequestExecutorBuilder.endpointRequestExecutor = endpointRequestExecutor;
return this;
}
public EndpointRequestExecutorBuilder executor() {
return endpointRequestExecutorBuilder;
}
public RestifyProxyBuilder converters(HttpMessageConverter...converters) {
this.httpMessageConvertersBuilder.add(converters);
return this;
}
public HttpMessageConvertersBuilder converters() {
return this.httpMessageConvertersBuilder;
}
public RestifyProxyBuilder handlers(EndpointCallHandlerProvider providers) {
this.endpointCallHandlersBuilder.add(providers);
return this;
}
public EndpointCallHandlersBuilder handlers() {
return this.endpointCallHandlersBuilder;
}
public RestifyProxyBuilder error(EndpointResponseErrorFallback fallback) {
this.endpointResponseErrorFallbackBuilder.fallback = fallback;
return this;
}
public EndpointResponseErrorFallbackBuilder error() {
return endpointResponseErrorFallbackBuilder;
}
public RetryBuilder retry() {
return retryBuilder;
}
public RestifyProxyBuilder async(Executor executor) {
return this.asyncBuilder.using(executor);
}
public AsyncBuilder async() {
return asyncBuilder;
}
public RestifyProxyBuilder classLoader(ClassLoader classLoader) {
this.classloader = classLoader;
return this;
}
public RestifyProxyBuilderOnTarget target(Class target) {
return new RestifyProxyBuilderOnTarget<>(target, null);
}
public RestifyProxyBuilderOnTarget target(Class target, String endpoint) {
return new RestifyProxyBuilderOnTarget<>(target, endpoint);
}
public RestifyProxyBuilderOnTarget target(Class target, URL endpoint) {
return new RestifyProxyBuilderOnTarget<>(target, endpoint.toString());
}
public RestifyProxyBuilderOnTarget target(Class target, URI endpoint) {
return new RestifyProxyBuilderOnTarget<>(target, endpoint.toString());
}
public class RestifyProxyBuilderOnTarget {
private final Class type;
private final String endpoint;
private RestifyProxyBuilderOnTarget(Class type, String endpoint) {
this.type = type;
this.endpoint = endpoint;
}
public T build() {
RestifyProxyHandler restifyProxyHandler = doBuild();
return new ProxyFactory(restifyProxyHandler, classloader).create(type);
}
private RestifyProxyHandler doBuild() {
EndpointTarget target = new EndpointTarget(type, endpoint);
EndpointMethodExecutor endpointMethodExecutor = new EndpointMethodExecutor(
endpointRequestFactory(),
endpointCallHandlers(),
endpointCallFactory());
Contract contract = contract();
return new RestifyProxyHandler(contract.read(target), endpointMethodExecutor);
}
private EndpointRequestFactory endpointRequestFactory() {
return new EndpointRequestFactory();
}
private EndpointCallHandlers endpointCallHandlers() {
return endpointCallHandlersBuilder.build();
}
private EndpointCallFactory endpointCallFactory() {
EndpointRequestExecutor executor = retryable(intercepted(endpointRequestExecutor()));
return executor instanceof AsyncEndpointRequestExecutor ?
asyncEndpointCallFactory(executor) :
defaultEndpointCallFactory(executor);
}
private EndpointCallFactory asyncEndpointCallFactory(EndpointRequestExecutor executor) {
EndpointCallFactory delegate = defaultEndpointCallFactory(executor);
return new DefaultAsyncEndpointCallFactory((AsyncEndpointRequestExecutor) executor,
asyncBuilder.executor,
delegate);
}
private EndpointCallFactory defaultEndpointCallFactory(EndpointRequestExecutor executor) {
return new DefaultEndpointCallFactory(executor);
}
private EndpointRequestExecutor endpointRequestExecutor() {
return Optional.ofNullable(endpointRequestExecutorBuilder.endpointRequestExecutor)
.orElseGet(() -> endpointRequestExecutor(intercepted(httpClientRequestFactory())));
}
private EndpointRequestExecutor intercepted(EndpointRequestExecutor delegate) {
Collection interceptors = endpointRequestExecutorBuilder.interceptors.all;
if (interceptors.isEmpty()) return delegate;
else return delegate instanceof AsyncEndpointRequestExecutor ?
new AsyncInterceptedEndpointRequestExecutor((AsyncEndpointRequestExecutor) delegate, AsyncEndpointRequestInterceptorChain.of(interceptors, asyncBuilder.executor)) :
new InterceptedEndpointRequestExecutor(delegate, new EndpointRequestInterceptorChain(interceptors));
}
private EndpointRequestExecutor endpointRequestExecutor(HttpClientRequestFactory httpClientRequestFactory) {
HttpMessageConverters httpMessageConverters = httpMessageConvertersBuilder.build();
EndpointRequestWriter writer = new EndpointRequestWriter(httpMessageConverters);
EndpointResponseReader reader = new EndpointResponseReader(httpMessageConverters, endpointResponseErrorFallbackBuilder());
return httpClientRequestFactory instanceof AsyncHttpClientRequestFactory ?
asyncEndpointRequestExecutor((AsyncHttpClientRequestFactory) httpClientRequestFactory, writer, reader) :
endpointRequestExecutor(httpClientRequestFactory, writer, reader);
}
private EndpointRequestExecutor asyncEndpointRequestExecutor(AsyncHttpClientRequestFactory asyncHttpClientRequestFactory,
EndpointRequestWriter writer, EndpointResponseReader reader) {
return new DefaultAsyncEndpointRequestExecutor(asyncBuilder.executor,
asyncHttpClientRequestFactory, writer, reader);
}
private EndpointRequestExecutor endpointRequestExecutor(HttpClientRequestFactory httpClientRequestFactory,
EndpointRequestWriter writer, EndpointResponseReader reader) {
return new DefaultEndpointRequestExecutor(httpClientRequestFactory, writer, reader);
}
private EndpointRequestExecutor retryable(EndpointRequestExecutor delegate) {
RetryConfiguration configuration = retryBuilder.build();
return configuration == null ? delegate :
delegate instanceof AsyncEndpointRequestExecutor ?
new AsyncRetryableEndpointRequestExecutor((AsyncEndpointRequestExecutor) delegate, retryBuilder.async.scheduler, configuration) :
new RetryableEndpointRequestExecutor(delegate, configuration);
}
private EndpointResponseErrorFallback endpointResponseErrorFallbackBuilder() {
return endpointResponseErrorFallbackBuilder.build();
}
private HttpClientRequestFactory httpClientRequestFactory() {
return Optional.ofNullable(httpClientRequestFactoryBuilder.httpClientRequestFactory)
.orElseGet(() -> new JdkHttpClientRequestFactory(httpClientRequestConfiguration()));
}
private HttpClientRequestFactory intercepted(HttpClientRequestFactory delegate) {
Collection interceptors = httpClientRequestFactoryBuilder.interceptors.all;
if (interceptors.isEmpty()) return delegate;
else return (delegate instanceof AsyncHttpClientRequestFactory) ?
new AsyncInterceptedHttpClientRequestFactory((AsyncHttpClientRequestFactory) delegate, AsyncHttpClientRequestInterceptorChain.of(interceptors)) :
new InterceptedHttpClientRequestFactory(delegate, new HttpClientRequestInterceptorChain(interceptors));
}
private HttpClientRequestConfiguration httpClientRequestConfiguration() {
return httpClientRequestFactoryBuilder.configuration.build();
}
private Contract contract() {
return Optional.ofNullable(contractBuilder.contract)
.map(c -> new Contract(c))
.orElseGet(() -> new Contract(new DefaultContractReader(expressionResolver())));
}
private ContractExpressionResolver expressionResolver() {
return Optional.ofNullable(contractBuilder.resolver)
.orElseGet(() -> new SimpleContractExpressionResolver());
}
}
public class ContractBuilder {
private ContractReader contract = null;
private ContractExpressionResolver resolver = null;
public ContractBuilder using(ContractReader contract) {
this.contract = contract;
return this;
}
public ContractBuilder resolver(ContractExpressionResolver resolver) {
this.resolver = resolver;
return this;
}
public RestifyProxyBuilder and() {
return RestifyProxyBuilder.this;
}
}
public class EndpointRequestExecutorBuilder {
private final EndpointRequestInterceptorsBuilder interceptors = new EndpointRequestInterceptorsBuilder();
private EndpointRequestExecutor endpointRequestExecutor = null;
public EndpointRequestExecutorBuilder using(EndpointRequestExecutor endpointRequestExecutor) {
this.endpointRequestExecutor = endpointRequestExecutor;
return this;
}
public EndpointRequestInterceptorsBuilder interceptors() {
return interceptors;
}
public EndpointRequestExecutorBuilder interceptors(EndpointRequestInterceptor... interceptors) {
this.interceptors.add(interceptors);
return this;
}
public RestifyProxyBuilder and() {
return RestifyProxyBuilder.this;
}
public class EndpointRequestInterceptorsBuilder {
private final Collection all = new ArrayList<>();
public EndpointRequestInterceptorsBuilder authentication(Authentication authentication) {
all.add(new AuthenticationEndpoinRequestInterceptor(authentication));
return this;
}
public EndpointRequestInterceptorsBuilder acceptVersion() {
all.add(new AcceptVersionHeaderEndpointRequestInterceptor());
return this;
}
public EndpointRequestInterceptorsBuilder acceptVersion(String version) {
all.add(new AcceptVersionHeaderEndpointRequestInterceptor(EndpointVersion.of(version)));
return this;
}
public EndpointRequestInterceptorsBuilder acceptVersion(EndpointVersion version) {
all.add(new AcceptVersionHeaderEndpointRequestInterceptor(version));
return this;
}
public EndpointRequestInterceptorsBuilder headers(Header... headers) {
this.all.add(new HeaderEndpointRequestInterceptor(headers));
return this;
}
public EndpointRequestInterceptorsBuilder headers(Collection headers) {
this.all.add(new HeaderEndpointRequestInterceptor(headers));
return this;
}
public EndpointRequestInterceptorsBuilder headers(Headers headers) {
this.all.add(new HeaderEndpointRequestInterceptor(headers));
return this;
}
public EndpointRequestInterceptorsBuilder add(EndpointRequestInterceptor... interceptors) {
this.all.addAll(Arrays.asList(interceptors));
return this;
}
public EndpointRequestExecutorBuilder and() {
return EndpointRequestExecutorBuilder.this;
}
}
}
public class HttpMessageConvertersBuilder {
private final Collection converters = new ArrayList<>();
private final DiscoveryComponentConfigurationBuilder discoveryComponentConfiguration =
new DiscoveryComponentConfigurationBuilder<>(this);
public HttpMessageConvertersBuilder wildcard() {
converters.addAll(provider.all(WildcardMessageConverter.class));
return this;
}
public HttpMessageConvertersBuilder octetStream() {
converters.addAll(provider.all(OctetStreamMessageConverter.class));
return this;
}
public HttpMessageConvertersBuilder json() {
provider.single(JsonMessageConverter.class).ifPresent(converters::add);
return this;
}
public HttpMessageConvertersBuilder xml() {
provider.single(XmlMessageConverter.class).ifPresent(converters::add);
return this;
}
public HttpMessageConvertersBuilder text() {
converters.addAll(provider.all(TextMessageConverter.class));
return this;
}
public HttpMessageConvertersBuilder form() {
converters.addAll(provider.all(FormURLEncodedMessageConverter.class));
converters.addAll(provider.all(MultipartFormMessageWriter.class));
return this;
}
public HttpMessageConvertersBuilder all() {
return discoveryComponentConfiguration.enabled ? wildcard().json().xml().text().form().octetStream().auto() : this;
}
private HttpMessageConvertersBuilder auto() {
converters.addAll(provider.all(HttpMessageConverter.class));
return this;
}
public HttpMessageConvertersBuilder add(HttpMessageConverter...converters) {
this.converters.addAll(Arrays.asList(converters));
return this;
}
public DiscoveryComponentConfigurationBuilder discovery() {
return discoveryComponentConfiguration;
}
public RestifyProxyBuilder and() {
return RestifyProxyBuilder.this;
}
private HttpMessageConverters build() {
return converters.isEmpty() ? all().doBuild() : doBuild();
}
private HttpMessageConverters doBuild() {
return new HttpMessageConverters(converters);
}
}
public class EndpointCallHandlersBuilder {
private final AsyncEndpointCallHandlersBuilder async = new AsyncEndpointCallHandlersBuilder();
private final Collection built = new ArrayList<>();
private final Collection providers = new ArrayList<>();
private final DiscoveryComponentConfigurationBuilder discoveryComponentConfiguration =
new DiscoveryComponentConfigurationBuilder<>(this);
private EndpointCallHandlersBuilder() {
this.built.add(OptionalEndpointCallHandlerFactory.instance());
this.built.add(CallableEndpointCallHandlerFactory.instance());
this.built.add(RunnableEndpointCallHandlerFactory.instance());
this.built.add(CollectionEndpointCallHandlerFactory.instance());
this.built.add(EnumerationEndpointCallHandlerAdapter.instance());
this.built.add(IteratorEndpointCallHandlerAdapter.instance());
this.built.add(ListIteratorEndpointCallHandlerAdapter.instance());
this.built.add(IterableEndpointCallHandlerAdapter.instance());
this.built.add(QueueEndpointCallHandlerAdapter.instance());
this.built.add(StreamEndpointCallHandlerAdapter.instance());
this.built.add(EndpointCallObjectHandlerAdapter.instance());
this.built.add(HeadersEndpointCallHandlerAdapter.instance());
this.built.add(StatusCodeEndpointCallHandlerAdapter.instance());
}
public EndpointCallHandlersBuilder add(EndpointCallHandlerProvider provider) {
providers.add(provider);
return this;
}
public EndpointCallHandlersBuilder add(EndpointCallHandlerProvider...providers) {
this.providers.addAll(Arrays.asList(providers));
return this;
}
public DiscoveryComponentConfigurationBuilder discovery() {
return discoveryComponentConfiguration;
}
public RestifyProxyBuilder and() {
return RestifyProxyBuilder.this;
}
private EndpointCallHandlers build() {
Collection all = new ArrayList<>();
all.addAll(providers);
all.addAll(built);
all.addAll(async.all());
if (discoveryComponentConfiguration.enabled) all.addAll(provider.all(EndpointCallHandlerProvider.class));
return new EndpointCallHandlers(all);
}
}
private class AsyncEndpointCallHandlersBuilder {
private Collection all() {
Executor executor = asyncBuilder.executor;
Collection providers = new ArrayList<>();
providers.add(new FutureEndpointCallHandlerAdapter
© 2015 - 2025 Weber Informatics LLC | Privacy Policy