/** * Finds the {@link Discoverable} for the given {@link HttpRequest} to route to. */ private Discoverable getDiscoverable(HttpRequest httpRequest) { EndpointStrategy strategy = serviceLookup.getDiscoverable(httpRequest); if (strategy == null) { throw new HandlerException(HttpResponseStatus.SERVICE_UNAVAILABLE, "No endpoint strategy found for request " + getRequestLine(httpRequest)); } // Do a non-blocking pick first. If the service has been discovered before, this should return an endpoint // immediately. Discoverable discoverable = strategy.pick(); if (discoverable != null) { return discoverable; } // Do a blocking pick for up to 1 second. It is for the case where a service is being discovered for the first time, // in which population of the cache might take time. discoverable = strategy.pick(1, TimeUnit.SECONDS); if (discoverable == null) { throw new HandlerException(HttpResponseStatus.SERVICE_UNAVAILABLE, "No discoverable found for request " + getRequestLine(httpRequest)); } return discoverable; }
private void verifyResponse(HttpResponse httpResponse) throws ConflictException { if (httpResponse.getResponseCode() == 409) { throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } if (httpResponse.getResponseCode() != 200) { throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()), httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } } }
private void verifyResponse(HttpResponse httpResponse) throws ConflictException { if (httpResponse.getResponseCode() == 409) { throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } if (httpResponse.getResponseCode() != 200) { throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()), httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } } }
break; default: throw new HandlerException(HttpResponseStatus.NOT_FOUND, "Invalid admin operation: " + method);
break; default: throw new HandlerException(HttpResponseStatus.NOT_FOUND, "Invalid admin operation: " + method);