当前位置: 首页>>代码示例>>Java>>正文


Java ClientException类代码示例

本文整理汇总了Java中com.netflix.client.ClientException的典型用法代码示例。如果您正苦于以下问题:Java ClientException类的具体用法?Java ClientException怎么用?Java ClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClientException类属于com.netflix.client包,在下文中一共展示了ClientException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleException

import com.netflix.client.ClientException; //导入依赖的package包/类
protected ClientHttpResponse handleException(Map<String, Object> info,
		HystrixRuntimeException ex) throws ZuulException {
	int statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
	Throwable cause = ex;
	String message = ex.getFailureType().toString();

	ClientException clientException = findClientException(ex);
	if (clientException == null) {
		clientException = findClientException(ex.getFallbackException());
	}

	if (clientException != null) {
		if (clientException
				.getErrorType() == ClientException.ErrorType.SERVER_THROTTLED) {
			statusCode = HttpStatus.SERVICE_UNAVAILABLE.value();
		}
		cause = clientException;
		message = clientException.getErrorType().toString();
	}
	info.put("status", String.valueOf(statusCode));
	throw new ZuulException(cause, "Forwarding error", statusCode, message);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:RibbonRoutingFilter.java

示例2: execute

import com.netflix.client.ClientException; //导入依赖的package包/类
@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);
		FeignLoadBalancer.RibbonRequest ribbonRequest = new FeignLoadBalancer.RibbonRequest(
				this.delegate, request, uriWithoutHost);

		IClientConfig requestConfig = getClientConfig(options, clientName);
		return lbClient(clientName).executeWithLoadBalancer(ribbonRequest,
				requestConfig).toResponse();
	}
	catch (ClientException e) {
		IOException io = findIOException(e);
		if (io != null) {
			throw io;
		}
		throw new RuntimeException(e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:22,代码来源:LoadBalancerFeignClient.java

示例3: testThrottledWithRetryNextServer

import com.netflix.client.ClientException; //导入依赖的package包/类
@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);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:17,代码来源:RetryTest.java

示例4: deriveHostAndPortFromVipAddress

import com.netflix.client.ClientException; //导入依赖的package包/类
/**
 * Derive the host and port from virtual address if virtual address is indeed contains the actual host 
 * and port of the server. This is the final resort to compute the final URI in {@link #getServerFromLoadBalancer(java.net.URI, Object)}
 * if there is no load balancer available and the request URI is incomplete. Sub classes can override this method
 * to be more accurate or throws ClientException if it does not want to support virtual address to be the
 * same as physical server address.
 * <p>
 *  The virtual address is used by certain load balancers to filter the servers of the same function 
 *  to form the server pool. 
 *  
 */
protected  Pair<String, Integer> deriveHostAndPortFromVipAddress(String vipAddress) 
        throws URISyntaxException, ClientException {
    Pair<String, Integer> hostAndPort = new Pair<String, Integer>(null, -1);
    URI uri = new URI(vipAddress);
    String scheme = uri.getScheme();
    if (scheme == null) {
        uri = new URI("http://" + vipAddress);
    }
    String host = uri.getHost();
    if (host == null) {
        throw new ClientException("Unable to derive host/port from vip address " + vipAddress);
    }
    int port = uri.getPort();
    if (port < 0) {
        port = getDefaultPortFromScheme(scheme);
    }
    if (port < 0) {
        throw new ClientException("Unable to derive host/port from vip address " + vipAddress);
    }
    hostAndPort.setFirst(host);
    hostAndPort.setSecond(port);
    return hostAndPort;
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:35,代码来源:LoadBalancerContext.java

示例5: getFilterImpl

import com.netflix.client.ClientException; //导入依赖的package包/类
/**
 * 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{
    try {
        String niwsServerListFilterClassName = niwsClientConfig
                .getProperty(
                        CommonClientConfigKey.NIWSServerListFilterClassName,
                        ZoneAffinityServerListFilter.class.getName())
                .toString();

        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:"
                        + niwsClientConfig
                                .getProperty(CommonClientConfigKey.NIWSServerListFilterClassName), e);
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:26,代码来源:AbstractServerList.java

示例6: execute

import com.netflix.client.ClientException; //导入依赖的package包/类
@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),
            (configOverride.get(CommonClientConfigKey.ReadTimeout, readTimeout)));
  } else {
    options = new Request.Options(connectTimeout, readTimeout);
  }
  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);
}
 
开发者ID:OpenFeign,项目名称:feign,代码行数:20,代码来源:LBClient.java

示例7: execute

import com.netflix.client.ClientException; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:16,代码来源:RibbonClient.java

示例8: propagatesFirstNestedIOE

import com.netflix.client.ClientException; //导入依赖的package包/类
@Test
public void propagatesFirstNestedIOE() throws IOException {
  thrown.expect(IOException.class);
  thrown.expectCause(isA(IOException.class));

  RibbonClient.propagateFirstIOException(new ClientException(new IOException(new IOException())));
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:8,代码来源:PropagateFirstIOExceptionTest.java

示例9: propagatesDoubleNestedIOE

import com.netflix.client.ClientException; //导入依赖的package包/类
/**
 * 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())));
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:12,代码来源:PropagateFirstIOExceptionTest.java

示例10: execute

import com.netflix.client.ClientException; //导入依赖的package包/类
@Override
public HttpResponseMessage execute() throws RestifyHttpException {
	try {
		RibbonResponse response = ribbonLoadBalancedClient.executeWithLoadBalancer(new RibbonRequest(this));

		return response.unwrap();

	} catch (ClientException e) {
		throw new RestifyHttpException("Error on HTTP request: [" + endpointRequest.method() + " " +
				endpointRequest.endpoint() + "]", e);
	}
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:13,代码来源:RibbonHttpClientRequest.java

示例11: isRetriableException

import com.netflix.client.ClientException; //导入依赖的package包/类
/**
 * Test if an exception is retriable for the load balancer
 *
 * @param e the original exception
 * @param sameServer if true, the method is trying to determine if retry can be
 *        done on the same server. Otherwise, it is testing whether retry can be
 *        done on a different server
 */
@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);
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:19,代码来源:HttpClientLoadBalancerErrorHandler.java

示例12: testGetCachedUser

import com.netflix.client.ClientException; //导入依赖的package包/类
@Test
public void testGetCachedUser() throws JsonParseException,
        JsonMappingException, IOException, ClientException {
    LOGGER.info("Starting testGetCachedUser");
    FakeUser user = fakeClient3.getCachedUser("bdoe");
    Assert.assertThat(user.getName(), IsEqual.equalTo("Bob Doe"));
    Assert.assertThat(
            cache.get("userCache:/user/bdoe")
                    .map(t -> {
                        try {
                            return new ObjectMapper().readValue(
                                    new ByteArrayInputStream(t
                                            .getCachedBytes()),
                                    FakeUser.class).getName();
                        } catch (Exception e) {
                            throw new IllegalStateException(e);
                        }
                    }).get(), IsEqual.equalTo("Bob Doe"));

    user = fakeClient3.getCachedUser("bdoe");
    Assert.assertThat(user.getName(), IsEqual.equalTo("Bob Doe"));

    HttpResponse response = fakeClient3.getCachedUserResponse("bdoe");
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(200));

    user = new ObjectMapper().readValue(response.getInputStream(),
            FakeUser.class);
    Assert.assertThat(user.getName(), IsEqual.equalTo("Bob Doe"));
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:30,代码来源:RestAdapterTest.java

示例13: getPayload

import com.netflix.client.ClientException; //导入依赖的package包/类
@Override
public Object getPayload() throws ClientException {
	if (!hasPayload()) {
		return null;
	}
	return this.body.byteStream();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:8,代码来源:OkHttpRibbonResponse.java

示例14: getPayload

import com.netflix.client.ClientException; //导入依赖的package包/类
@Override
public Object getPayload() throws ClientException {
	try {
		if (!hasPayload()) {
			return null;
		}
		return this.httpResponse.getEntity().getContent();
	}
	catch (final IOException e) {
		throw new ClientException(e.getMessage(), e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:13,代码来源:RibbonApacheHttpResponse.java

示例15: findClientException

import com.netflix.client.ClientException; //导入依赖的package包/类
protected ClientException findClientException(Throwable t) {
	if (t == null) {
		return null;
	}
	if (t instanceof ClientException) {
		return (ClientException) t;
	}
	return findClientException(t.getCause());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:10,代码来源:RibbonRoutingFilter.java


注:本文中的com.netflix.client.ClientException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。