Search in sources :

Example 1 with DefaultEndpoint

use of com.netflix.discovery.shared.resolver.DefaultEndpoint in project eureka by Netflix.

the class RedirectingEurekaHttpClient method executeOnNewServer.

private <R> EurekaHttpResponse<R> executeOnNewServer(RequestExecutor<R> requestExecutor, AtomicReference<EurekaHttpClient> currentHttpClientRef) {
    URI targetUrl = null;
    for (int followRedirectCount = 0; followRedirectCount < MAX_FOLLOWED_REDIRECTS; followRedirectCount++) {
        EurekaHttpResponse<R> httpResponse = requestExecutor.execute(currentHttpClientRef.get());
        if (httpResponse.getStatusCode() != 302) {
            if (followRedirectCount == 0) {
                logger.debug("Pinning to endpoint {}", targetUrl);
            } else {
                logger.info("Pinning to endpoint {}, after {} redirect(s)", targetUrl, followRedirectCount);
            }
            return httpResponse;
        }
        targetUrl = getRedirectBaseUri(httpResponse.getLocation());
        if (targetUrl == null) {
            throw new TransportException("Invalid redirect URL " + httpResponse.getLocation());
        }
        currentHttpClientRef.getAndSet(null).shutdown();
        currentHttpClientRef.set(factory.newClient(new DefaultEndpoint(targetUrl.toString())));
    }
    String message = "Follow redirect limit crossed for URI " + serviceEndpoint.getServiceUrl();
    logger.warn(message);
    throw new TransportException(message);
}
Also used : DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint) URI(java.net.URI) TransportException(com.netflix.discovery.shared.transport.TransportException) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint)

Example 2 with DefaultEndpoint

use of com.netflix.discovery.shared.resolver.DefaultEndpoint in project eureka by Netflix.

the class EurekaHttpClientsTest method setUp.

@Before
public void setUp() throws IOException {
    clientConfig = mock(EurekaClientConfig.class);
    transportConfig = mock(EurekaTransportConfig.class);
    when(clientConfig.getEurekaServerTotalConnectionsPerHost()).thenReturn(10);
    when(clientConfig.getEurekaServerTotalConnections()).thenReturn(10);
    when(transportConfig.getSessionedClientReconnectIntervalSeconds()).thenReturn(10);
    writeServer = new SimpleEurekaHttpServer(writeRequestHandler);
    clusterResolver = new StaticClusterResolver<EurekaEndpoint>("regionA", new DefaultEndpoint("localhost", writeServer.getServerPort(), false, "/v2/"));
    readServer = new SimpleEurekaHttpServer(readRequestHandler);
    readServerURI = "http://localhost:" + readServer.getServerPort();
    clientFactory = EurekaHttpClients.canonicalClientFactory("test", transportConfig, clusterResolver, new Jersey1TransportClientFactories().newTransportClientFactory(clientConfig, Collections.<ClientFilter>emptyList(), applicationInfoManager.getInfo()));
}
Also used : Jersey1TransportClientFactories(com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) Before(org.junit.Before)

Example 3 with DefaultEndpoint

use of com.netflix.discovery.shared.resolver.DefaultEndpoint in project eureka by Netflix.

the class AbstractJersey2EurekaHttpClientTest method getEurekaHttpClient.

@Override
protected EurekaHttpClient getEurekaHttpClient(URI serviceURI) {
    Jersey2ApplicationClientFactoryBuilder factoryBuilder = Jersey2ApplicationClientFactory.newBuilder();
    if (serviceURI.getUserInfo() != null) {
        factoryBuilder.withFeature(HttpAuthenticationFeature.basicBuilder().build());
    }
    TransportClientFactory clientFactory = factoryBuilder.build();
    jersey2HttpClient = (AbstractJersey2EurekaHttpClient) clientFactory.newClient(new DefaultEndpoint(serviceURI.toString()));
    return jersey2HttpClient;
}
Also used : DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint) Jersey2ApplicationClientFactoryBuilder(com.netflix.discovery.shared.transport.jersey2.Jersey2ApplicationClientFactory.Jersey2ApplicationClientFactoryBuilder) TransportClientFactory(com.netflix.discovery.shared.transport.TransportClientFactory)

Example 4 with DefaultEndpoint

use of com.netflix.discovery.shared.resolver.DefaultEndpoint in project eureka by Netflix.

the class JerseyApplicationClientTest method getEurekaHttpClient.

@Override
protected EurekaHttpClient getEurekaHttpClient(URI serviceURI) {
    Preconditions.checkState(jerseyHttpClient == null, "EurekaHttpClient has been already created");
    TransportClientFactory clientFactory = JerseyEurekaHttpClientFactory.newBuilder().withClientName("compatibilityTestClient").build();
    jerseyHttpClient = (JerseyApplicationClient) clientFactory.newClient(new DefaultEndpoint(serviceURI.toString()));
    return jerseyHttpClient;
}
Also used : DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint) TransportClientFactory(com.netflix.discovery.shared.transport.TransportClientFactory)

Aggregations

DefaultEndpoint (com.netflix.discovery.shared.resolver.DefaultEndpoint)4 EurekaEndpoint (com.netflix.discovery.shared.resolver.EurekaEndpoint)2 TransportClientFactory (com.netflix.discovery.shared.transport.TransportClientFactory)2 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 TransportException (com.netflix.discovery.shared.transport.TransportException)1 Jersey1TransportClientFactories (com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories)1 Jersey2ApplicationClientFactoryBuilder (com.netflix.discovery.shared.transport.jersey2.Jersey2ApplicationClientFactory.Jersey2ApplicationClientFactoryBuilder)1 URI (java.net.URI)1 Before (org.junit.Before)1