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);
}
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()));
}
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;
}
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;
}
Aggregations