Java 类org.springframework.http.client.AsyncClientHttpRequestFactory 实例源码

项目:Zipkin    文件:TraceWebAsyncClientAutoConfiguration.java   
@Bean
@Primary
@ConditionalOnProperty(value = "spring.sleuth.web.async.client.factory.enabled", matchIfMissing = true)
public TraceAsyncClientHttpRequestFactoryWrapper traceAsyncClientHttpRequestFactory() {
    ClientHttpRequestFactory clientFactory = this.clientHttpRequestFactory;
    AsyncClientHttpRequestFactory asyncClientFactory = this.asyncClientHttpRequestFactory;
    if (clientFactory == null) {
        clientFactory = defaultClientHttpRequestFactory(this.tracer);
    }
    if (asyncClientFactory == null) {
        asyncClientFactory = clientFactory instanceof AsyncClientHttpRequestFactory ?
                (AsyncClientHttpRequestFactory) clientFactory : defaultClientHttpRequestFactory(this.tracer);
    }
    return new TraceAsyncClientHttpRequestFactoryWrapper(this.tracer, this.spanInjector,
            asyncClientFactory, clientFactory, this.httpTraceKeysInjector);
}
项目:fiware-ngsi-api    文件:HttpConfiguration.java   
@Bean
@Resource(name = "jsonV1Converter")
public AsyncRestTemplate asyncRestTemplate(AsyncClientHttpRequestFactory asyncClientHttpRequestFactory,
        MappingJackson2HttpMessageConverter jsonConverter) {
    AsyncRestTemplate restTemplate = new AsyncRestTemplate(asyncClientHttpRequestFactory);

    // Replace the default json converter by our converter
    // Remove
    for(HttpMessageConverter httpMessageConverter : restTemplate.getMessageConverters()) {
        if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) {
            restTemplate.getMessageConverters().remove(httpMessageConverter);
            break;
        }
    }
    // Add
    restTemplate.getMessageConverters().add(jsonConverter);

    return restTemplate;
}
项目:riptide    文件:HttpFactory.java   
@SuppressWarnings("unused")
public static Http create(
        final String baseUrl,
        final UrlResolution urlResolution,
        final AsyncClientHttpRequestFactory requestFactory,
        final List<HttpMessageConverter<?>> converters,
        final List<Plugin> plugins) {

    return Http.builder()
            .baseUrl(baseUrl)
            .urlResolution(urlResolution)
            .requestFactory(requestFactory)
            .converters(converters)
            .plugins(plugins)
            .build();
}
项目:riptide    文件:DefaultRiptideRegistrar.java   
private String registerAsyncClientHttpRequestFactory(final String id, final Client client) {
    return registry.registerIfAbsent(id, AsyncClientHttpRequestFactory.class, () -> {
        log.debug("Client [{}]: Registering RestAsyncClientHttpRequestFactory", id);

        final BeanDefinitionBuilder factory =
                genericBeanDefinition(RestAsyncClientHttpRequestFactory.class);

        factory.addConstructorArgReference(registerHttpClient(id, client));
        factory.addConstructorArgValue(genericBeanDefinition(ConcurrentTaskExecutor.class)
                // we allow users to use their own ExecutorService, but they don't have to configure tracing
                .addConstructorArgValue(registerExecutor(id, client))
                .getBeanDefinition());

        return factory;
    });
}
项目:lams    文件:AsyncRestTemplate.java   
/**
 * Create a new instance of the {@code AsyncRestTemplate} using the given
 * {@link AsyncClientHttpRequestFactory} and synchronous {@link RestTemplate}.
 * @param requestFactory the asynchronous request factory to use
 * @param restTemplate the synchronous template to use
 */
public AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory,
        RestTemplate restTemplate) {
    Assert.notNull(restTemplate, "'restTemplate' must not be null");
    this.syncTemplate = restTemplate;
    setAsyncRequestFactory(requestFactory);
}
项目:put-it-to-rest    文件:RestFactory.java   
@SuppressWarnings("unused")
public static Rest create(final AsyncClientHttpRequestFactory requestFactory,
        final List<HttpMessageConverter<?>> converters, final String baseUrl, final Plugins plugins) {
    return Rest.builder()
            .requestFactory(requestFactory)
            .converters(converters)
            .baseUrl(baseUrl)
            .plugins(plugins.resolvePlugins())
            .build();
}
项目:put-it-to-rest    文件:RestClientPostProcessor.java   
private String registerAsyncClientHttpRequestFactory(final String id, final Defaults defaults,
        final Client client) {
    return registry.register(id, AsyncClientHttpRequestFactory.class, () -> {
        LOG.debug("Client [{}]: Registering RestAsyncClientHttpRequestFactory", id);

        final BeanDefinitionBuilder factory =
                genericBeanDefinition(RestAsyncClientHttpRequestFactory.class);

        factory.addConstructorArgReference(registerHttpClient(id, defaults, client));
        factory.addConstructorArgReference(registerAsyncListenableTaskExecutor(id));

        return factory;
    });
}
项目:Zipkin    文件:TraceAsyncClientHttpRequestFactoryWrapper.java   
/**
 * According to the JavaDocs all Spring {@link AsyncClientHttpRequestFactory} implement
 * the {@link ClientHttpRequestFactory} interface.
 *
 * In case that it's not true we're setting the {@link SimpleClientHttpRequestFactory}
 * as a default for sync request processing.
 *
 * @see org.springframework.web.client.AsyncRestTemplate#AsyncRestTemplate(AsyncClientHttpRequestFactory)
 */
public TraceAsyncClientHttpRequestFactoryWrapper(Tracer tracer,
        SpanInjector<HttpRequest> spanInjector,
        AsyncClientHttpRequestFactory asyncDelegate,
        HttpTraceKeysInjector httpTraceKeysInjector) {
    super(tracer, spanInjector, httpTraceKeysInjector);
    this.asyncDelegate = asyncDelegate;
    this.syncDelegate = asyncDelegate instanceof ClientHttpRequestFactory ?
            (ClientHttpRequestFactory) asyncDelegate : defaultClientHttpRequestFactory();
}
项目:Zipkin    文件:TraceAsyncClientHttpRequestFactoryWrapper.java   
public TraceAsyncClientHttpRequestFactoryWrapper(Tracer tracer,
        SpanInjector<HttpRequest> spanInjector,
        AsyncClientHttpRequestFactory asyncDelegate,
        ClientHttpRequestFactory syncDelegate,
        HttpTraceKeysInjector httpTraceKeysInjector) {
    super(tracer, spanInjector, httpTraceKeysInjector);
    this.asyncDelegate = asyncDelegate;
    this.syncDelegate = syncDelegate;
}
项目:riptide    文件:Requester.java   
Requester(final AsyncClientHttpRequestFactory requestFactory, final MessageWorker worker,
        final RequestArguments arguments, final List<Plugin> plugins) {
    this.requestFactory = requestFactory;
    this.worker = worker;
    this.arguments = arguments;
    this.plugin = Plugin.compound(plugins);
}
项目:riptide    文件:DefaultHttp.java   
DefaultHttp(final AsyncClientHttpRequestFactory requestFactory, final List<HttpMessageConverter<?>> converters,
        final Supplier<URI> baseUrlProvider, final UrlResolution resolution, final List<Plugin> plugins) {
    this.requestFactory = checkNotNull(requestFactory, "request factory");
    this.worker = new MessageWorker(converters);
    this.baseUrlProvider = checkNotNull(baseUrlProvider, "base url provider");
    this.arguments = RequestArguments.create().withUrlResolution(resolution);
    this.plugins = plugins;
}
项目:riptide    文件:HandlesIOExceptionTest.java   
@Test
public void shouldHandleExceptionDuringRequestCreation() throws URISyntaxException {
    exception.expect(UncheckedIOException.class);
    exception.expectCause(instanceOf(IOException.class));
    exception.expectMessage("Could not create request");

    final AsyncClientHttpRequestFactory factory = (uri, httpMethod) -> {
        throw new IOException("Could not create request");
    };

    Http.builder().requestFactory(factory).defaultConverters().build()
            .get("http://localhost/")
            .dispatch(series(),
                    on(SUCCESSFUL).call(pass()));
}
项目:riptide    文件:RestTest.java   
@Test
public void shouldCreateBuilder() {
    final Rest rest = Rest.builder()
            .requestFactory(mock(AsyncClientHttpRequestFactory.class))
            .build();

    assertThat(rest, is(notNullValue()));
}
项目:riptide    文件:TestRiptideRegistrar.java   
private void registerAsyncClientHttpRequestFactory(final String id) {
    registry.registerIfAbsent(id, AsyncClientHttpRequestFactory.class, () -> {
        log.debug("Client [{}]: Registering mocked AsyncClientHttpRequestFactory", id);
        final BeanDefinitionBuilder factory = genericBeanDefinition(AsyncClientHttpRequestFactory.class);
        factory.addDependsOn(RiptideTestAutoConfiguration.SERVER_BEAN_NAME);
        factory.setFactoryMethodOnBean("getAsyncRequestFactory", RiptideTestAutoConfiguration.TEMPLATE_BEAN_NAME);
        return factory;
    });
}
项目:riptide    文件:ManualConfiguration.java   
@Bean
public Http exampleHttp(final AsyncClientHttpRequestFactory requestFactory,
        final ClientHttpMessageConverters converters, final GaugeService gaugeService,
        final ScheduledExecutorService scheduler) {
    return Http.builder()
            .baseUrl("https://www.example.com")
            .urlResolution(UrlResolution.RFC)
            .requestFactory(requestFactory)
            .converters(converters.getConverters())
            .plugin(new MetricsPlugin(gaugeService, new ZMONMetricsNameGenerator()))
            .plugin(new TransientFaultPlugin(
                    FaultClassifier.create(ImmutableList.<Predicate<Throwable>>builder()
                            .addAll(FaultClassifier.defaults())
                            .add(ConnectionClosedException.class::isInstance)
                            .add(NoHttpResponseException.class::isInstance)
                            .build())))
            .plugin(new FailsafePlugin(scheduler)
                    .withRetryPolicy(new RetryPolicy()
                            .retryOn(TransientFaultException.class)
                            .withBackoff(50, 2000, MILLISECONDS)
                            .withMaxRetries(10)
                            .withMaxDuration(2, SECONDS)
                            .withJitter(0.2))
                    .withCircuitBreaker(new CircuitBreaker()
                            .withFailureThreshold(5, 5)
                            .withDelay(30, SECONDS)
                            .withSuccessThreshold(3, 5)
                            .withTimeout(3, SECONDS)))
            .plugin(new BackupRequestPlugin(scheduler, 10, MILLISECONDS))
            .plugin(new TimeoutPlugin(scheduler, 3, SECONDS))
            .plugin(new OriginalStackTracePlugin())
            .plugin(new CustomPlugin())
            .build();
}
项目:riptide    文件:ManualConfiguration.java   
@Bean
public AsyncRestTemplate exampleAsyncRestTemplate(final AsyncClientHttpRequestFactory requestFactory,
        final ClientHttpMessageConverters converters) {
    final AsyncRestTemplate template = new AsyncRestTemplate();

    final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
    handler.setBaseUrl("https://www.example.com");
    template.setUriTemplateHandler(handler);
    template.setAsyncRequestFactory(requestFactory);
    template.setMessageConverters(converters.getConverters());

    return template;
}
项目:spring-cloud-sleuth    文件:TraceWebAsyncClientAutoConfiguration.java   
private TraceAsyncClientHttpRequestFactoryWrapper traceAsyncClientHttpRequestFactory() {
    ClientHttpRequestFactory clientFactory = this.clientHttpRequestFactory;
    AsyncClientHttpRequestFactory asyncClientFactory = this.asyncClientHttpRequestFactory;
    if (clientFactory == null) {
        clientFactory = defaultClientHttpRequestFactory(this.tracer);
    }
    if (asyncClientFactory == null) {
        asyncClientFactory = clientFactory instanceof AsyncClientHttpRequestFactory ?
                (AsyncClientHttpRequestFactory) clientFactory : defaultClientHttpRequestFactory(this.tracer);
    }
    return new TraceAsyncClientHttpRequestFactoryWrapper(this.tracer, this.spanInjector,
            asyncClientFactory, clientFactory, this.httpTraceKeysInjector);
}
项目:spring-cloud-sleuth    文件:TraceAsyncClientHttpRequestFactoryWrapper.java   
/**
 * According to the JavaDocs all Spring {@link AsyncClientHttpRequestFactory} implement
 * the {@link ClientHttpRequestFactory} interface.
 *
 * In case that it's not true we're setting the {@link SimpleClientHttpRequestFactory}
 * as a default for sync request processing.
 *
 * @see org.springframework.web.client.AsyncRestTemplate#AsyncRestTemplate(AsyncClientHttpRequestFactory)
 */
public TraceAsyncClientHttpRequestFactoryWrapper(Tracer tracer,
        HttpSpanInjector spanInjector,
        AsyncClientHttpRequestFactory asyncDelegate,
        HttpTraceKeysInjector httpTraceKeysInjector) {
    super(tracer, spanInjector, httpTraceKeysInjector);
    this.asyncDelegate = asyncDelegate;
    this.syncDelegate = asyncDelegate instanceof ClientHttpRequestFactory ?
            (ClientHttpRequestFactory) asyncDelegate : defaultClientHttpRequestFactory();
}
项目:spring-cloud-sleuth    文件:TraceAsyncClientHttpRequestFactoryWrapper.java   
public TraceAsyncClientHttpRequestFactoryWrapper(Tracer tracer,
        HttpSpanInjector spanInjector,
        AsyncClientHttpRequestFactory asyncDelegate,
        ClientHttpRequestFactory syncDelegate,
        HttpTraceKeysInjector httpTraceKeysInjector) {
    super(tracer, spanInjector, httpTraceKeysInjector);
    this.asyncDelegate = asyncDelegate;
    this.syncDelegate = syncDelegate;
}
项目:spring-cloud-sleuth    文件:TraceWebAsyncClientAutoConfigurationTests.java   
@Test
public void should_inject_to_async_rest_template_custom_client_http_request_factory() {
    then(this.asyncRestTemplate.getAsyncRequestFactory()).isInstanceOf(TraceAsyncClientHttpRequestFactoryWrapper.class);
    TraceAsyncClientHttpRequestFactoryWrapper wrapper = (TraceAsyncClientHttpRequestFactoryWrapper) this.asyncRestTemplate.getAsyncRequestFactory();
    then(wrapper.syncDelegate).isInstanceOf(SimpleClientHttpRequestFactory.class);
    then(wrapper.asyncDelegate).isInstanceOf(AsyncClientHttpRequestFactory.class);
    then(this.asyncRestTemplate).isInstanceOf(TraceAsyncRestTemplate.class);
}
项目:lams    文件:AsyncHttpAccessor.java   
/**
 * Set the request factory that this accessor uses for obtaining {@link
 * org.springframework.http.client.ClientHttpRequest HttpRequests}.
 */
public void setAsyncRequestFactory(AsyncClientHttpRequestFactory asyncRequestFactory) {
    Assert.notNull(asyncRequestFactory, "'asyncRequestFactory' must not be null");
    this.asyncRequestFactory = asyncRequestFactory;
}
项目:spring4-understanding    文件:AsyncHttpAccessor.java   
/**
 * Set the request factory that this accessor uses for obtaining {@link
 * org.springframework.http.client.ClientHttpRequest HttpRequests}.
 */
public void setAsyncRequestFactory(AsyncClientHttpRequestFactory asyncRequestFactory) {
    Assert.notNull(asyncRequestFactory, "'asyncRequestFactory' must not be null");
    this.asyncRequestFactory = asyncRequestFactory;
}
项目:put-it-to-rest    文件:PluginTest.java   
@Bean
@DependsOn("server")
public AsyncClientHttpRequestFactory exampleAsyncClientHttpRequestFactory(final AsyncRestTemplate template) {
    return template.getAsyncRequestFactory();
}
项目:put-it-to-rest    文件:PluginTest.java   
@Bean
@DependsOn("server")
public AsyncClientHttpRequestFactory fooAsyncClientHttpRequestFactory(final AsyncRestTemplate template) {
    return template.getAsyncRequestFactory();
}
项目:put-it-to-rest    文件:AsyncClientHttpRequestFactoryOverrideTest.java   
@Bean
@Qualifier("example")
public AsyncClientHttpRequestFactory exampleAsyncClientHttpRequestFactory() {
    return mock(AsyncClientHttpRequestFactory.class,
            withSettings().extraInterfaces(ClientHttpRequestFactory.class));
}
项目:Zipkin    文件:TraceAsyncRestTemplate.java   
public TraceAsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory,
        Tracer tracer) {
    super(asyncRequestFactory);
    this.tracer = tracer;
}
项目:Zipkin    文件:TraceAsyncRestTemplate.java   
public TraceAsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory,
        ClientHttpRequestFactory syncRequestFactory, Tracer tracer) {
    super(asyncRequestFactory, syncRequestFactory);
    this.tracer = tracer;
}
项目:Zipkin    文件:TraceAsyncRestTemplate.java   
public TraceAsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory,
        RestTemplate restTemplate, Tracer tracer) {
    super(requestFactory, restTemplate);
    this.tracer = tracer;
}
项目:fiware-ngsi-api    文件:HttpConfiguration.java   
@Bean
public AsyncClientHttpRequestFactory clientHttpRequestFactory(CloseableHttpAsyncClient closeableHttpAsyncClient) {
    return new HttpComponentsAsyncClientHttpRequestFactory(closeableHttpAsyncClient);
}
项目:riptide    文件:RestBuilderTest.java   
@Test
public void shouldConfigure() {
    final HttpBuilder builder = spy(HttpBuilder.class);

    final RestConfigurer unit = RestBuilder.simpleRequestFactory(newDirectExecutorService());

    unit.configure(builder);

    final ArgumentCaptor<AsyncClientHttpRequestFactory> captor =
            ArgumentCaptor.forClass(AsyncClientHttpRequestFactory.class);

    verify(builder).requestFactory(captor.capture());
    final AsyncClientHttpRequestFactory factory = captor.getValue();

    assertThat(factory, is(instanceOf(SimpleClientHttpRequestFactory.class)));
}
项目:riptide    文件:AsyncClientHttpRequestFactoryOverrideTest.java   
@Bean
@Qualifier("example")
public AsyncClientHttpRequestFactory exampleAsyncClientHttpRequestFactory() {
    return mock(AsyncClientHttpRequestFactory.class,
            withSettings().extraInterfaces(ClientHttpRequestFactory.class));
}
项目:riptide    文件:InterceptorTest.java   
@Bean
@DependsOn("server")
public AsyncClientHttpRequestFactory githubAsyncClientHttpRequestFactory(final AsyncRestTemplate template) {
    return template.getAsyncRequestFactory();
}
项目:riptide    文件:UrlResolutionTest.java   
@Bean
@DependsOn("server")
public AsyncClientHttpRequestFactory exampleAsyncClientHttpRequestFactory(final AsyncRestTemplate template) {
    return template.getAsyncRequestFactory();
}
项目:myfeed    文件:AsyncRest.java   
public AsyncRest(AsyncClientHttpRequestFactory asyncRequestFactory) {
    super(asyncRequestFactory);
}
项目:myfeed    文件:AsyncRest.java   
public AsyncRest(AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory) {
    super(asyncRequestFactory, syncRequestFactory);
}
项目:myfeed    文件:AsyncRest.java   
public AsyncRest(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate) {
    super(requestFactory, restTemplate);
}
项目:spring-cloud-sleuth    文件:TraceAsyncRestTemplate.java   
public TraceAsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory,
        Tracer tracer, ErrorParser errorParser) {
    super(asyncRequestFactory);
    this.tracer = tracer;
    this.errorParser = errorParser;
}
项目:spring-cloud-sleuth    文件:TraceAsyncRestTemplate.java   
public TraceAsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory,
        ClientHttpRequestFactory syncRequestFactory, Tracer tracer, ErrorParser errorParser) {
    super(asyncRequestFactory, syncRequestFactory);
    this.tracer = tracer;
    this.errorParser = errorParser;
}
项目:spring-cloud-sleuth    文件:TraceAsyncRestTemplate.java   
public TraceAsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory,
        RestTemplate restTemplate, Tracer tracer, ErrorParser errorParser) {
    super(requestFactory, restTemplate);
    this.tracer = tracer;
    this.errorParser = errorParser;
}
项目:spring-cloud-sleuth    文件:TraceWebAsyncClientAutoConfigurationTests.java   
@Bean
AsyncClientHttpRequestFactory myAsyncClientFactory() {
    return new MyAsyncClientHttpRequestFactory();
}