Search in sources :

Example 6 with RestClient

use of com.netflix.niws.client.http.RestClient in project spring-cloud-netflix by spring-cloud.

the class RestClientRibbonConfiguration method ribbonRestClient.

/**
 * Create a Netflix {@link RestClient} integrated with Ribbon if none already exists
 * in the application context. It is not required for Ribbon to work properly and is
 * therefore created lazily if ever another component requires it.
 *
 * @param config             the configuration to use by the underlying Ribbon instance
 * @param loadBalancer       the load balancer to use by the underlying Ribbon instance
 * @param serverIntrospector server introspector to use by the underlying Ribbon instance
 * @param retryHandler       retry handler to use by the underlying Ribbon instance
 * @return a {@link RestClient} instances backed by Ribbon
 */
@Bean
@Lazy
@ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
public RestClient ribbonRestClient(IClientConfig config, ILoadBalancer loadBalancer, ServerIntrospector serverIntrospector, RetryHandler retryHandler) {
    RestClient client = new RibbonClientConfiguration.OverrideRestClient(config, serverIntrospector);
    client.setLoadBalancer(loadBalancer);
    client.setRetryHandler(retryHandler);
    return client;
}
Also used : RestClient(com.netflix.niws.client.http.RestClient) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with RestClient

use of com.netflix.niws.client.http.RestClient in project spring-cloud-netflix by spring-cloud.

the class RibbonClientHttpRequestFactory method createRequest.

@Override
@SuppressWarnings("deprecation")
public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod) throws IOException {
    String serviceId = originalUri.getHost();
    if (serviceId == null) {
        throw new IOException("Invalid hostname in the URI [" + originalUri.toASCIIString() + "]");
    }
    IClientConfig clientConfig = this.clientFactory.getClientConfig(serviceId);
    RestClient client = this.clientFactory.getClient(serviceId, RestClient.class);
    HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name());
    return new RibbonHttpRequest(originalUri, verb, client, clientConfig);
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) IClientConfig(com.netflix.client.config.IClientConfig) RestClient(com.netflix.niws.client.http.RestClient) IOException(java.io.IOException)

Example 8 with RestClient

use of com.netflix.niws.client.http.RestClient in project spring-cloud-netflix by spring-cloud.

the class RestClientRibbonCommandFactory method create.

@Override
@SuppressWarnings("deprecation")
public RestClientRibbonCommand create(RibbonCommandContext context) {
    String serviceId = context.getServiceId();
    FallbackProvider fallbackProvider = getFallbackProvider(serviceId);
    RestClient restClient = this.clientFactory.getClient(serviceId, RestClient.class);
    return new RestClientRibbonCommand(context.getServiceId(), restClient, context, this.zuulProperties, fallbackProvider, clientFactory.getClientConfig(serviceId));
}
Also used : RestClient(com.netflix.niws.client.http.RestClient)

Aggregations

RestClient (com.netflix.niws.client.http.RestClient)8 HttpRequest (com.netflix.client.http.HttpRequest)4 HttpResponse (com.netflix.client.http.HttpResponse)3 URI (java.net.URI)3 Test (org.junit.Test)3 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)2 MockResponse (com.google.mockwebserver.MockResponse)1 MockWebServer (com.google.mockwebserver.MockWebServer)1 IClientConfig (com.netflix.client.config.IClientConfig)1 ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)1 IOException (java.io.IOException)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)1