本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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())));
}
示例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())));
}
示例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);
}
}
示例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);
}
示例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"));
}
示例13: getPayload
import com.netflix.client.ClientException; //导入依赖的package包/类
@Override
public Object getPayload() throws ClientException {
if (!hasPayload()) {
return null;
}
return this.body.byteStream();
}
示例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);
}
}
示例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());
}