com.netflix.client.ClientException Java Examples

The following examples show how to use com.netflix.client.ClientException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LBClient.java    From feign with Apache License 2.0 6 votes vote down vote up
@Override
public RibbonResponse execute(RibbonRequest request, IClientConfig configOverride)
    throws IOException, ClientException {
  Request.Options options;
  if (configOverride != null) {
    options =
        new Request.Options(
            configOverride.get(CommonClientConfigKey.ConnectTimeout, connectTimeout),
            TimeUnit.MILLISECONDS,
            (configOverride.get(CommonClientConfigKey.ReadTimeout, readTimeout)),
            TimeUnit.MILLISECONDS,
            configOverride.get(CommonClientConfigKey.FollowRedirects, followRedirects));
  } else {
    options = new Request.Options(connectTimeout, TimeUnit.MILLISECONDS, readTimeout,
        TimeUnit.MILLISECONDS, true);
  }
  Response response = request.client().execute(request.toRequest(), options);
  if (retryableStatusCodes.contains(response.status())) {
    response.close();
    throw new ClientException(ClientException.ErrorType.SERVER_THROTTLED);
  }
  return new RibbonResponse(request.getUri(), response);
}
 
Example #2
Source File: RetryTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void testThrottledWithRetryNextServer() throws Exception {
    int connectionCount = connectionPoolManager.getConnectionsInPool();
    URI localUrl = new URI("/status?code=503");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
    System.out.println("Initial connections count " + connectionCount);
    System.out.println("Final connections count " + connectionPoolManager.getConnectionsInPool());
    // should be no connection leak        
    assertTrue(connectionPoolManager.getConnectionsInPool() <= connectionCount + 1);
}
 
Example #3
Source File: RestClientFactory.java    From s2g-zuul with MIT License 6 votes vote down vote up
public static  RestClient getRestClient(String serviceName,IClientConfig clientConfig) throws ClientException{
	RestClient oldClient = restClientMap.get(serviceName);
	
	if(oldClient == null){			
		synchronized (RestClient.class) {
			oldClient = restClientMap.get(serviceName);
			if(oldClient == null){
				RestClient client =  newRestClient(serviceName,clientConfig);
				oldClient = restClientMap.putIfAbsent(serviceName, client);
				
				if(oldClient != null){
					oldClient.shutdown();
				}					
				oldClient = client;
			}				
		}			
	}
	
	return oldClient;
}
 
Example #4
Source File: AbstractServerList.java    From ribbon with Apache License 2.0 6 votes vote down vote up
/**
 * Get a ServerListFilter instance. It uses {@link ClientFactory#instantiateInstanceWithClientConfig(String, IClientConfig)}
 * which in turn uses reflection to initialize the filter instance. 
 * The filter class name is determined by the value of {@link CommonClientConfigKey#NIWSServerListFilterClassName}
 * in the {@link IClientConfig}. The default implementation is {@link ZoneAffinityServerListFilter}.
 */
public AbstractServerListFilter<T> getFilterImpl(IClientConfig niwsClientConfig) throws ClientException {
    String niwsServerListFilterClassName = null;
    try {
        niwsServerListFilterClassName = niwsClientConfig.get(
                        CommonClientConfigKey.NIWSServerListFilterClassName,
                        ZoneAffinityServerListFilter.class.getName());

        AbstractServerListFilter<T> abstractNIWSServerListFilter = 
                (AbstractServerListFilter<T>) ClientFactory.instantiateInstanceWithClientConfig(niwsServerListFilterClassName, niwsClientConfig);
        return abstractNIWSServerListFilter;
    } catch (Throwable e) {
        throw new ClientException(
                ClientException.ErrorType.CONFIGURATION,
                "Unable to get an instance of CommonClientConfigKey.NIWSServerListFilterClassName. Configured class:"
                        + niwsServerListFilterClassName, e);
    }
}
 
Example #5
Source File: NettyHttpLoadBalancerErrorHandler.java    From ribbon with Apache License 2.0 5 votes vote down vote up
/**
 * @return true if the Throwable has one of the following exception type as a cause: 
 * {@link SocketException}, {@link SocketTimeoutException}
 */
@Override
public boolean isCircuitTrippingException(Throwable e) {
    if (e instanceof UnexpectedHttpResponseException) {
        return ((UnexpectedHttpResponseException) e).getStatusCode() == 503;
    } else if (e instanceof ClientException) {
        return ((ClientException) e).getErrorType() == ClientException.ErrorType.SERVER_THROTTLED;
    }
    return super.isCircuitTrippingException(e);
}
 
Example #6
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrottled() throws Exception {
    URI localUrl = new URI("/status?code=503");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0));
        fail("Exception expected");
    } catch (ClientException e) {
        assertNotNull(e);
    }
    assertEquals(1, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());        
}
 
Example #7
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrottledWithRetrySameServer() throws Exception {
    URI localUrl = new URI("/status?code=503");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, 
                DefaultClientConfigImpl
                .getEmptyConfig()
                .set(CommonClientConfigKey.MaxAutoRetries, 1)
                .set(CommonClientConfigKey.MaxAutoRetriesNextServer, 0));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    assertEquals(2, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());        
}
 
Example #8
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadTimeout() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
 
Example #9
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadTimeoutWithRetriesNextServe() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    assertEquals(3, lb.getLoadBalancerStats().getSingleServerStat(localServer).getSuccessiveConnectionFailureCount());
}
 
Example #10
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void postReadTimeout() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer); 
    assertEquals(1, stats.getSuccessiveConnectionFailureCount());
}
 
Example #11
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetriesOnPost() throws Exception {
    URI localUrl = new URI("/noresponse");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
    try {
        client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer); 
    assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
 
Example #12
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetriesOnPostWithConnectException() throws Exception {
    URI localUrl = new URI("/status?code=503");
    lb.setServersList(Lists.newArrayList(localServer));
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).verb(Verb.POST).setRetriable(true).build();
    try {
        HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        fail("Exception expected");
    } catch (ClientException e) { // NOPMD
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(localServer); 
    assertEquals(3, stats.getSuccessiveConnectionFailureCount());
}
 
Example #13
Source File: RetryTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuccessfulRetries() throws Exception {
    lb.setServersList(Lists.newArrayList(new Server("localhost:12987"), new Server("localhost:12987"), localServer));
    URI localUrl = new URI("/ok");
    HttpRequest request = HttpRequest.newBuilder().uri(localUrl).queryParams("name", "ribbon").build();
    try {
        HttpResponse response = client.executeWithLoadBalancer(request, DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.MaxAutoRetriesNextServer, 2));
        assertEquals(200, response.getStatus());
    } catch (ClientException e) { 
        fail("Unexpected exception");
    }
    ServerStats stats = lb.getLoadBalancerStats().getSingleServerStat(new Server("localhost:12987")); 
    assertEquals(1, stats.getSuccessiveConnectionFailureCount());
}
 
Example #14
Source File: ExceptionHandlerAdvice.java    From cloud-service with MIT License 5 votes vote down vote up
@ExceptionHandler({ClientException.class, Throwable.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Map<String, Object> serverException(Throwable throwable) {
	log.error("服务端异常", throwable);
	Map<String, Object> data = new HashMap<>();
	data.put("code", HttpStatus.INTERNAL_SERVER_ERROR.value());
	data.put("message", "服务端异常,请联系管理员");

	return data;
}
 
Example #15
Source File: NettyHttpLoadBalancerErrorHandler.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetriableException(Throwable e, boolean sameServer) {
    if (e instanceof ClientException) {
        ClientException ce = (ClientException) e;
        if (ce.getErrorType() == ClientException.ErrorType.SERVER_THROTTLED) {
            return !sameServer && retryEnabled;
        }
    }
    return super.isRetriableException(e, sameServer);
}
 
Example #16
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testObservableWithRetrySameServer() throws Exception {
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    Server badServer = new Server("localhost:12345");
    Server goodServer = new Server("localhost:" + port);
    List<Server> servers = Lists.newArrayList(badServer, badServer, goodServer);
    
    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder()
            .withRule(new AvailabilityFilteringRule())
            .withPing(new DummyPing())
            .buildFixedServerListLoadBalancer(servers);
    
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config,
            new NettyHttpLoadBalancerErrorHandler(1, 0, true));

    Observable<Person> observableWithRetries = getPersonObservable(lbObservables.submit(request));
    ObserverWithLatch<Person> observer = new ObserverWithLatch<Person>();
    observableWithRetries.subscribe(observer);
    observer.await();
    assertNull(observer.obj);
    assertTrue(observer.error instanceof ClientException);

    ServerStats stats = lbObservables.getServerStats(badServer);
    
    // two requests to bad server because retry same server is set to 1
    assertEquals(2, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    
    stats = lbObservables.getServerStats(goodServer);
    assertEquals(0, stats.getTotalRequestsCount());
}
 
Example #17
Source File: NettyClientTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testObservableWithMultipleServersFailed() throws Exception {        
    IClientConfig config = IClientConfig.Builder.newBuilder()
            .withDefaultValues()
            .withRetryOnAllOperations(true)
            .withMaxAutoRetries(1)
            .withMaxAutoRetriesNextServer(3)
            .withConnectTimeout(100)
            .build();
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    BaseLoadBalancer lb = new BaseLoadBalancer(new DummyPing(), new AvailabilityFilteringRule());        
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config);
    Server badServer = new Server("localhost:12345");
    Server badServer1 = new Server("localhost:12346");
    Server badServer2 = new Server("localhost:12347");

    List<Server> servers = Lists.newArrayList(badServer, badServer1, badServer2);
    lb.setServersList(servers);
    Observable<Person> observableWithRetries = getPersonObservable(lbObservables.submit(request));
    ObserverWithLatch<Person> observer = new ObserverWithLatch<Person>();
    observableWithRetries.subscribe(observer);
    observer.await();
    assertNull(observer.obj);
    observer.error.printStackTrace();
    assertTrue(observer.error instanceof ClientException);
    
    ServerStats stats = lbObservables.getServerStats(badServer);
    // two requests to bad server because retry same server is set to 1
    assertEquals(2, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    assertEquals(2, stats.getSuccessiveConnectionFailureCount());
}
 
Example #18
Source File: ListenerTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedExecution() {
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues()
            .withProperty(CommonClientConfigKey.ConnectTimeout, "100")
            .withProperty(CommonClientConfigKey.MaxAutoRetries, 1)
            .withProperty(CommonClientConfigKey.MaxAutoRetriesNextServer, 1);

    System.out.println(config);

    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    Server badServer  = new Server("localhost:12345");
    Server badServer2 = new Server("localhost:34567");
    List<Server> servers = Lists.newArrayList(badServer, badServer2);

    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder()
            .withRule(new AvailabilityFilteringRule())
            .withPing(new DummyPing())
            .buildFixedServerListLoadBalancer(servers);
    
    IClientConfig overrideConfig = DefaultClientConfigImpl.getEmptyConfig();
    TestExecutionListener<ByteBuf, ByteBuf> listener = new TestExecutionListener<ByteBuf, ByteBuf>(request, overrideConfig);
    List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = Lists.<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>>newArrayList(listener);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(config), listeners);
    try {
        client.submit(request, null, overrideConfig).toBlocking().last();
        fail("Exception expected");
    } catch(Exception e) {
        assertNotNull(e);
    }
    assertEquals(1, listener.executionStartCounter.get());
    assertEquals(4, listener.startWithServerCounter.get());
    assertEquals(4, listener.exceptionWithServerCounter.get());
    assertEquals(1, listener.executionFailedCounter.get());
    assertTrue(listener.isContextChecked());
    assertTrue(listener.isCheckExecutionInfo());
    assertNotNull(listener.getFinalThrowable());
    listener.getFinalThrowable().printStackTrace();
    assertTrue(listener.getFinalThrowable() instanceof ClientException);
    assertEquals(100, listener.getContext().getClientProperty(CommonClientConfigKey.ConnectTimeout).intValue());
}
 
Example #19
Source File: ListenerTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedExecutionForAbsoluteURI() {
    IClientConfig config = DefaultClientConfigImpl
            .getClientConfigWithDefaultValues()
            .withProperty(CommonClientConfigKey.ConnectTimeout, "100")
            .withProperty(CommonClientConfigKey.MaxAutoRetries, 1)
            .withProperty(CommonClientConfigKey.MaxAutoRetriesNextServer, 1);
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("http://xyz.unknowhost.xyz/testAsync/person");
    Server badServer = new Server("localhost:12345");
    Server badServer2 = new Server("localhost:34567");
    List<Server> servers = Lists.newArrayList(badServer, badServer2);

    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder()
            .withRule(new AvailabilityFilteringRule())
            .withPing(new DummyPing())
            .buildFixedServerListLoadBalancer(servers);
    IClientConfig overrideConfig = DefaultClientConfigImpl.getEmptyConfig();
    TestExecutionListener<ByteBuf, ByteBuf> listener = new TestExecutionListener<ByteBuf, ByteBuf>(request, overrideConfig);
    List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = Lists.<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>>newArrayList(listener);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(config), listeners);
    try {
        client.submit(request, null, overrideConfig).toBlocking().last();
        fail("Exception expected");
    } catch(Exception e) {
        assertNotNull(e);
    }
    assertEquals(1, listener.executionStartCounter.get());
    assertEquals(2, listener.startWithServerCounter.get());
    assertEquals(2, listener.exceptionWithServerCounter.get());
    assertEquals(1, listener.executionFailedCounter.get());
    assertTrue(listener.isContextChecked());
    assertTrue(listener.isCheckExecutionInfo());
    assertTrue(listener.getFinalThrowable() instanceof ClientException);
}
 
Example #20
Source File: RibbonClient.java    From feign with Apache License 2.0 5 votes vote down vote up
@Override
public Response execute(Request request, Request.Options options) throws IOException {
  try {
    URI asUri = URI.create(request.url());
    String clientName = asUri.getHost();
    URI uriWithoutHost = cleanUrl(request.url(), clientName);
    LBClient.RibbonRequest ribbonRequest =
        new LBClient.RibbonRequest(delegate, request, uriWithoutHost);
    return lbClient(clientName).executeWithLoadBalancer(ribbonRequest,
        new FeignOptionsClientConfig(options)).toResponse();
  } catch (ClientException e) {
    propagateFirstIOException(e);
    throw new RuntimeException(e);
  }
}
 
Example #21
Source File: PropagateFirstIOExceptionTest.java    From feign with Apache License 2.0 5 votes vote down vote up
@Test
public void propagatesFirstNestedIOE() throws IOException {
  thrown.expect(IOException.class);
  thrown.expectCause(isA(IOException.class));

  RibbonClient.propagateFirstIOException(new ClientException(new IOException(new IOException())));
}
 
Example #22
Source File: PropagateFirstIOExceptionTest.java    From feign with Apache License 2.0 5 votes vote down vote up
/**
 * Happened in practice; a blocking observable wrapped the connect exception in a runtime
 * exception
 */
@Test
public void propagatesDoubleNestedIOE() throws IOException {
  thrown.expect(ConnectException.class);

  RibbonClient.propagateFirstIOException(
      new ClientException(new RuntimeException(new ConnectException())));
}
 
Example #23
Source File: HttpClientLoadBalancerErrorHandler.java    From ribbon with Apache License 2.0 5 votes vote down vote up
/**
 * @return true if the Throwable has one of the following exception type as a cause: 
 * {@link SocketException}, {@link SocketTimeoutException}
 */
@Override
public boolean isCircuitTrippingException(Throwable e) {
    if (e instanceof ClientException) {
        return ((ClientException) e).getErrorType() == ClientException.ErrorType.SERVER_THROTTLED;
    }

    return super.isCircuitTrippingException(e);
}
 
Example #24
Source File: GlobalDefaultExceptionHandler.java    From unified-dispose-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * 二次深度检查错误类型
 */
private Result ifDepthExceptionType(Throwable throwable) throws Throwable {
    Throwable cause = throwable.getCause();
    if (cause instanceof ClientException) {
        return handlerClientException((ClientException) cause);
    }
    if (cause instanceof FeignException) {
        return handlerFeignException((FeignException) cause);
    }
    outPutError(Exception.class, CommonErrorCode.EXCEPTION, throwable);
    return Result.ofFail(CommonErrorCode.EXCEPTION);
}
 
Example #25
Source File: GlobalDefaultExceptionHandler.java    From unified-dispose-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * ClientException 类捕获
 */
@ExceptionHandler(value = ClientException.class)
public Result handlerClientException(ClientException e) throws Throwable {
    errorDispose(e);
    outPutError(ClientException.class, CommonErrorCode.RPC_ERROR, e);
    return Result.ofFail(CommonErrorCode.RPC_ERROR);
}
 
Example #26
Source File: HttpClientResponse.java    From s2g-zuul with MIT License 5 votes vote down vote up
public <T> T getEntity(Class<T> c) throws Exception {
    T t = null;
    try {
        t = this.bcr.getEntity(c);
    } catch (UniformInterfaceException e) {
        throw new ClientException(ClientException.ErrorType.GENERAL, e.getMessage(), e.getCause());
    } 
    return t;
}
 
Example #27
Source File: HttpClientResponse.java    From s2g-zuul with MIT License 5 votes vote down vote up
@Override
public Object getPayload() throws ClientException {
    if (hasEntity()) {
        return getRawEntity();
    } else {
        return null;
    }
}
 
Example #28
Source File: RestClientFactory.java    From s2g-zuul with MIT License 5 votes vote down vote up
private static RestClient newRestClient(String restClientName,IClientConfig clientConfig) throws ClientException{
	RestClient restClient = new RestClient(clientConfig);
	ILoadBalancer loadBalancer = null;
	boolean initializeNFLoadBalancer = Boolean.parseBoolean(clientConfig.getProperty(
			CommonClientConfigKey.InitializeNFLoadBalancer, DefaultClientConfigImpl.DEFAULT_ENABLE_LOADBALANCER).toString());
	if (initializeNFLoadBalancer) {
		loadBalancer  = newLoadBalancerFromConfig(restClientName, clientConfig);
	}
	if (restClient instanceof AbstractLoadBalancerAwareClient) {
		((AbstractLoadBalancerAwareClient) restClient).setLoadBalancer(loadBalancer);
	}
	return restClient;
}
 
Example #29
Source File: RestClient.java    From s2g-zuul with MIT License 5 votes vote down vote up
@Override
protected boolean isRetriableException(Throwable e) {
    if (e instanceof ClientException
            && ((ClientException)e).getErrorType() == ClientException.ErrorType.SERVER_THROTTLED){
        return false;
    }
    boolean shouldRetry = isConnectException(e) || isSocketException(e);
    return shouldRetry;
}
 
Example #30
Source File: RestClient.java    From s2g-zuul with MIT License 5 votes vote down vote up
@Override
protected boolean isCircuitBreakerException(Throwable e) {
    if (e instanceof ClientException) {
        ClientException clientException = (ClientException) e;
        if (clientException.getErrorType() == ClientException.ErrorType.SERVER_THROTTLED) {
            return true;
        }
    }
    return isConnectException(e) || isSocketException(e);
}