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:org.fcrepo.auth.oauth.integration.api.AbstractOAuthResourceIT.java

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

From source file:io.wcm.caravan.io.http.impl.RequestUtilTest.java

@Test
public void testBuildHttpRequest_Post() throws ParseException, IOException {
    RequestTemplate template = new RequestTemplate().method("post").append("/path").body("string body");
    HttpUriRequest request = RequestUtil.buildHttpRequest("http://host", template.request());

    assertEquals("http://host/path", request.getURI().toString());
    assertEquals(HttpPost.METHOD_NAME, request.getMethod());

    HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
    assertEquals("string body", EntityUtils.toString(entityRequest.getEntity()));
}

From source file:io.wcm.caravan.io.http.impl.RequestUtilTest.java

@Test
public void testBuildHttpRequest_Put() throws IOException {
    byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
    RequestTemplate template = new RequestTemplate().method("put").append("/path").body(data, null);
    HttpUriRequest request = RequestUtil.buildHttpRequest("http://host", template.request());

    assertEquals("http://host/path", request.getURI().toString());
    assertEquals(HttpPut.METHOD_NAME, request.getMethod());

    HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
    assertArrayEquals(data, EntityUtils.toByteArray(entityRequest.getEntity()));
}

From source file:io.wcm.caravan.io.http.impl.RequestUtilTest.java

@Test
public void testBuildHttpRequest_Get() {
    RequestTemplate template = new RequestTemplate().method("get").append("/path").header("header1", "value1")
            .header("header2", "value2", "value3");
    HttpUriRequest request = RequestUtil.buildHttpRequest("http://host", template.request());

    assertEquals("http://host/path", request.getURI().toString());
    assertEquals(HttpGet.METHOD_NAME, request.getMethod());

    Map<String, Collection<String>> expected = ImmutableMap.<String, Collection<String>>of("header1",
            ImmutableList.of("value1"), "header2", ImmutableList.of("value2", "value3"));
    assertEquals(expected, RequestUtil.toHeadersMap(request.getAllHeaders()));
}

From source file:com.subgraph.vega.impl.scanner.forms.FormProcessor.java

private void processFormElement(IInjectionModuleContext ctx, HttpUriRequest request, Element form) {
    final FormProcessingState fps = new FormProcessingState(request.getURI(), form.getAttribute("action"),
            form.getAttribute("method"), config.getFormCredentials());
    if (!fps.isValid())
        return;/*  ww w .  j  ava 2  s.  c  o  m*/

    NodeList es = form.getElementsByTagName("*");
    for (int i = 0; i < es.getLength(); i++) {
        Node n = es.item(i);
        if (n instanceof Element)
            processSingleFormElement(fps, (Element) n);

    }
    if (fps.getFileFieldFlag()) {
        ctx.debug("Cannot process form because file input handling not implemented");
        return;
    }
    ctx.debug("Processed form: " + fps);
    submitNewForm(fps);

}

From source file:org.apache.olingo.client.core.communication.request.AbstractRequest.java

protected void checkRequest(final ODataClient odataClient, final HttpUriRequest request) {
    // If using and Edm enabled client, checks that the cached service root matches the request URI
    if (odataClient instanceof EdmEnabledODataClient && !request.getURI().toASCIIString()
            .startsWith(((EdmEnabledODataClient) odataClient).getServiceRoot())) {

        throw new IllegalArgumentException(String.format(
                "The current request URI %s does not match the configured service root %s",
                request.getURI().toASCIIString(), ((EdmEnabledODataClient) odataClient).getServiceRoot()));
    }/*ww w  . j a  v  a  2s  .  c  o  m*/
}

From source file:org.fcrepo.indexer.RdfRetriever.java

@Override
public Model get() {
    final HttpUriRequest request = new HttpGet(identifier);
    request.addHeader("Accept", RDF_SERIALIZATION);
    LOGGER.debug("Retrieving RDF content from: {}...", request.getURI());
    try {//from   w ww . j a  v  a  2  s. com
        final HttpResponse response = httpClient.execute(request);
        if (response.getStatusLine().getStatusCode() == SC_OK) {
            try (Reader r = new InputStreamReader(response.getEntity().getContent(), "UTF8")) {
                return createDefaultModel().read(r, "", "N3");
            }
        } else {
            throw new HttpException(response.getStatusLine().toString());
        }
    } catch (IOException | HttpException e) {
        throw propagate(e);
    }
}

From source file:org.apache.ambari.server.controller.internal.AppCookieManager.java

/**
 * Returns hadoop.auth cookie, doing needed SPNego authentication
 * //from  w w w .jav  a  2  s  . c  o m
 * @param endpoint
 *          the URL of the Hadoop service
 * @param refresh
 *          flag indicating wehther to refresh the cookie, if
 *          <code>true</code>, we do a new SPNego authentication and refresh
 *          the cookie even if the cookie already exists in local cache
 * @return hadoop.auth cookie value
 * @throws IOException
 *           in case of problem getting hadoop.auth cookie
 */
public String getAppCookie(String endpoint, boolean refresh) throws IOException {

    HttpUriRequest outboundRequest = new HttpGet(endpoint);
    URI uri = outboundRequest.getURI();
    String scheme = uri.getScheme();
    String host = uri.getHost();
    int port = uri.getPort();
    String path = uri.getPath();
    if (!refresh) {
        String appCookie = endpointCookieMap.get(endpoint);
        if (appCookie != null) {
            return appCookie;
        }
    }

    clearAppCookie(endpoint);

    DefaultHttpClient client = new DefaultHttpClient();
    SPNegoSchemeFactory spNegoSF = new SPNegoSchemeFactory(/* stripPort */true);
    // spNegoSF.setSpengoGenerator(new BouncySpnegoTokenGenerator());
    client.getAuthSchemes().register(AuthPolicy.SPNEGO, spNegoSF);
    client.getCredentialsProvider().setCredentials(new AuthScope(/* host */null, /* port */-1, /* realm */null),
            EMPTY_JAAS_CREDENTIALS);

    String hadoopAuthCookie = null;
    HttpResponse httpResponse = null;
    try {
        HttpHost httpHost = new HttpHost(host, port, scheme);
        HttpRequest httpRequest = new HttpOptions(path);
        httpResponse = client.execute(httpHost, httpRequest);
        Header[] headers = httpResponse.getHeaders(SET_COOKIE);
        hadoopAuthCookie = getHadoopAuthCookieValue(headers);
        if (hadoopAuthCookie == null) {
            LOG.error("SPNego authentication failed, can not get hadoop.auth cookie for URL: " + endpoint);
            throw new IOException("SPNego authentication failed, can not get hadoop.auth cookie");
        }
    } finally {
        if (httpResponse != null) {
            HttpEntity entity = httpResponse.getEntity();
            if (entity != null) {
                entity.getContent().close();
            }
        }

    }

    hadoopAuthCookie = HADOOP_AUTH_EQ + quote(hadoopAuthCookie);
    setAppCookie(endpoint, hadoopAuthCookie);
    if (LOG.isInfoEnabled()) {
        LOG.info("Successful SPNego authentication to URL:" + uri.toString());
    }
    return hadoopAuthCookie;
}

From source file:net.netheos.pcsapi.oauth.PasswordSessionManager.java

@Override
public CResponse execute(HttpUriRequest request) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("{}: {}", request.getMethod(), PcsUtils.shortenUrl(request.getURI()));
    }//w  ww. j  ava2s .c  o  m

    try {
        URI uri = request.getURI();
        HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
        HttpContext context = getHttpContext(host);

        HttpResponse httpResponse = httpClient.execute(host, request, context);
        return new CResponse(request, httpResponse);

    } catch (IOException ex) {
        // a low level error should be retried :
        throw new CRetriableException(ex);
    }
}

From source file:com.cloud.utils.rest.HttpUriRequestBuilderTest.java

@Test
public void testBuildSimpleRequest() throws Exception {
    final HttpUriRequest request = HttpUriRequestBuilder.create().method(HttpMethods.GET).path("/path").build();

    assertThat(request, notNullValue());
    assertThat(request.getURI().getPath(), equalTo("/path"));
    assertThat(request.getURI().getScheme(), nullValue());
    assertThat(request.getURI().getQuery(), nullValue());
    assertThat(request.getURI().getHost(), nullValue());
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
}