public Uri getUri() { return response.getUri(); }
public Uri getUri() { return response.getUri(); }
public Uri getUri() { return response.getUri(); }
public UriComponents getUri() { return response.getUri(); }
/** * Return the request {@link java.net.URI}. Note that if the request got redirected, the value of the * {@link java.net.URI} will be the last valid redirect url. * * @return the request {@link java.net.URI}. */ public URI getUri() { try { return ahcResponse.getUri(); } catch (MalformedURLException e) { throw new RuntimeException(e); } } }
@Override public URI getUri() throws URISyntaxException { return ningResponse.getUri().toJavaNetURI(); }
@Override public String getUrl() { return ningResponse.getUri().toUrl(); }
@Override public String onCompleted(Response response) throws Exception { return response.getUri().toString(); }
@Override public String onCompleted(Response response) throws Exception { return response.getUri().toString(); }
@Override public String onCompleted(Response response) throws Exception { return response.getUri().toString(); }
/** * Send an HTTP message to a worker, producing helpful logging if there was a problem * * @param uriRequest The request to make * @param expectedStatus The expected return status * @return true if the method was successfully delivered & the worker gave the expected response */ private boolean tellWorker(AsyncHttpClient.BoundRequestBuilder uriRequest, Response.Status expectedStatus) { try { com.ning.http.client.Response response = uriRequest.execute().get(); if (response.getStatusCode() != expectedStatus.getStatusCode()) { logger.warn( "Problem telling worker <" + metadata.getWorkerId() + "> " + "(" + response.getUri() + "), " + "reason [" + response.getStatusCode() + ": " + response.getStatusText() + "]"); return false; } return true; } catch (IOException | ExecutionException e) { logger.warn("Unable to communicated with worker " + metadata.toString()); return false; } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.info("Interrupted"); throw new RuntimeException(e); } }
/** * Send an HTTP message to a worker and get the result * * Note: expects the worker to respond with OK (200) status code. * * @param uriRequest The request to make * @return An InputStream of the response content */ private InputStream askWorker(AsyncHttpClient.BoundRequestBuilder uriRequest) { try { com.ning.http.client.Response response = uriRequest.execute().get(); if (response.getStatusCode() != Response.Status.OK.getStatusCode()) { logger.warn( "Problem asking worker <" + metadata.getWorkerId() + "> " + "(" + response.getUri() + "), " + "reason [" + response.getStatusCode() + ": " + response.getStatusText() + "]"); } return response.getResponseBodyAsStream(); } catch (IOException | ExecutionException e) { logger.warn("Unable to communicated with worker " + metadata.toString()); throw new RuntimeException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.info("Interrupted"); throw new RuntimeException(e); } } }
LOG.debug("Request url={}, id={}", response.getUri()); throw new IOException("Got invalid response code " + rc + " from " + url + ": " + response.getStatusText());
@Test(groups = { "online", "default_provider" }) public void redirected302Test() throws Throwable { isSet.getAndSet(false); try (AsyncHttpClient client = getAsyncHttpClient(null)) { // once Response response = client.prepareGet(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "http://www.stackoverflow.com/").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); String anyWebPage = "https://(www.)?stackoverflow.com[^:]*:443"; String baseUrl = getBaseUrl(response.getUri()); assertTrue(baseUrl.matches(anyWebPage), "response baseUrl \'" + baseUrl +"\' does not show redirection to " + anyWebPage); } }
@Test(groups = { "online", "default_provider" }) public void redirected302Test() throws Throwable { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build(); try (AsyncHttpClient client = getAsyncHttpClient(cg)) { // once Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); String baseUrl = getBaseUrl(response.getUri()); assertTrue(baseUrl.startsWith("http://www.google."), "response does not show redirection to a google subdomain, got " + baseUrl); } }
@Test(groups = { "standalone", "default_provider" }) public void absolutePathRedirectTest() throws Throwable { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build(); try (AsyncHttpClient client = getAsyncHttpClient(cg)) { String redirectTarget = "/bar/test"; String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString(); Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); log.debug("{} was redirected to {}", redirectTarget, destinationUrl); } }
@Test(groups = { "standalone", "default_provider" }) public void relativePathRedirectTest() throws Throwable { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build(); try (AsyncHttpClient client = getAsyncHttpClient(cg)) { String redirectTarget = "bar/test1"; String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString(); Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); log.debug("{} was redirected to {}", redirectTarget, destinationUrl); } } }
@Test(groups = { "standalone", "default_provider" }) public void relativeLocationUrl() throws Throwable { isSet.getAndSet(false); try (AsyncHttpClient client = getAsyncHttpClient(null)) { Response response = client.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), getTargetUrl()); } } }
@Test(groups = { "standalone", "default_provider" }) public void relativeLocationUrl() throws Throwable { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder()// .setMaxRedirects(5)// .setFollowRedirect(true)// .setAcceptAnyCertificate(true)// .build(); try (AsyncHttpClient client = getAsyncHttpClient(cg)) { Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), getTargetUrl()); } } }
res = response.get(); assertNotNull(res.getResponseBody()); assertEquals(BASE_URL + "/overthere", BASE_URL + "/overthere", res.getUri().toString());