Example usage for org.apache.http.client.methods HttpUriRequest getURI

List of usage examples for org.apache.http.client.methods HttpUriRequest getURI

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpUriRequest getURI.

Prototype

URI getURI();

Source Link

Document

Returns the URI this request uses, such as <code>http://example.org/path/to/file</code>.

Usage

From source file:com.comcast.cim.rest.client.xhtml.XhtmlHttpClient.java

/**
 * Executes the given HTTP request and returns the next
 * application state.//from   w  w w.  j a  v  a 2s  .c  o m
 * @param req HTTP request to execute
 * @return new application state
 * @throws ClientProtocolException
 * @throws IOException
 */
public XhtmlApplicationState execute(HttpUriRequest req) throws ClientProtocolException, IOException {
    req.setHeader("Accept", ACCEPT_HEADER);
    URL context = new URL(req.getURI().toString());
    XhtmlResponseHandler rh = xhtmlResponseHandlerFactory.get(context);
    XhtmlApplicationState state = httpClient.execute(req, rh);
    return state;
}

From source file:org.apache.hawq.ranger.integration.service.tests.common.RESTClient.java

private String executeRequest(HttpUriRequest request) throws IOException {

    LOG.debug("--> request URI = " + request.getURI());

    request.setHeader("Authorization", AUTH_HEADER);
    request.setHeader("Content-Type", ContentType.APPLICATION_JSON.toString());

    CloseableHttpResponse response = httpClient.execute(request);
    String payload = null;/* w w  w  . j av a 2s  .c o  m*/
    try {
        int responseCode = response.getStatusLine().getStatusCode();
        LOG.debug("<-- response code = " + responseCode);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            payload = EntityUtils.toString(response.getEntity());
        }
        LOG.debug("<-- response payload = " + payload);

        if (responseCode == HttpStatus.SC_NOT_FOUND) {
            throw new ResourceNotFoundException();
        } else if (responseCode >= 300) {
            throw new ClientProtocolException("Unexpected HTTP response code = " + responseCode);
        }
    } finally {
        response.close();
    }

    return payload;
}

From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java

public void testDefaultRedirection() throws Exception {
    final String newLocation = "/new-location";

    HttpContext context = HttpClientContext.create();
    HttpUriRequest request = new HttpOptions(TestConstants.roboHydra.resolve("redirect/301?to=" + newLocation));
    HttpResponse response = httpClient.execute(request, context);
    assertTrue(strategy.isRedirected(request, response, context));

    HttpUriRequest redirected = strategy.getRedirect(request, response, context);
    assertEquals(TestConstants.roboHydra.resolve(newLocation), redirected.getURI());
}

From source file:at.bitfire.davdroid.webdav.DavRedirectStrategyTest.java

public void testRelativeLocation() throws Exception {
    HttpContext context = HttpClientContext.create();
    HttpUriRequest request = new HttpOptions(TestConstants.roboHydra.resolve("redirect/relative"));
    HttpResponse response = httpClient.execute(request, context);
    assertTrue(strategy.isRedirected(request, response, context));

    HttpUriRequest redirected = strategy.getRedirect(request, response, context);
    assertEquals(TestConstants.roboHydra.resolve("/new/location"), redirected.getURI());
}

From source file:org.fcrepo.integration.generator.AbstractResourceIT.java

protected int getStatus(final HttpUriRequest method) throws ClientProtocolException, IOException {
    logger.debug("Executing: " + method.getMethod() + " to " + method.getURI());
    return client.execute(method).getStatusLine().getStatusCode();
}

From source file:org.onehippo.cms7.brokenlinks.TestHttpClient.java

@Override
public HttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException {
    final URI uri = request.getURI();
    final BasicStatusLine statusline;
    if (!"good".equals(uri.getHost())) {
        statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not Found");
    } else {//from  w  w w  .  ja va 2  s  .co  m
        statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
    }
    return new BasicHttpResponse(statusline);
}

From source file:org.apache.hadoop.gateway.dispatch.AppCookieManager.java

protected HttpRequest createKerberosAuthenticationRequest(HttpUriRequest userRequest) {
    HttpRequest authRequest = new HttpOptions(userRequest.getURI().getPath());
    return authRequest;
}

From source file:com.gistlabs.mechanize.cache.HttpCacheFilter.java

public HttpResponse executeOther(final HttpUriRequest request, final HttpContext context,
        final MechanizeFilter chain) {
    String uri = request.getURI().toString();
    invalidate(uri, request);//from w  w w . j ava  2  s. c  om
    return chain.execute(request, context);
}

From source file:org.fcrepo.auth.integration.AbstractResourceIT.java

protected HttpResponse execute(final HttpUriRequest method) throws IOException {
    logger.debug("Executing: " + method.getMethod() + " to " + method.getURI());
    return client.execute(method);
}