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.corebase.android.framework.http.client.MyHttpRequest.java

public MyHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriRequest request,
        CacheParams cacheParams) {// w w w. j av a 2  s  . com
    this.client = client;
    this.context = context;
    this.request = request;
    this.cacheParams = cacheParams;
    this.url = request.getURI().toString();
}

From source file:com.comcast.cdn.traffic_control.traffic_router.neustar.data.HttpClient.java

public CloseableHttpResponse execute(HttpUriRequest request) {
    try {//from   w  w w  .  j a v a  2 s. c om
        httpClient = HttpClientBuilder.create().build();
        return httpClient.execute(request);
    } catch (IOException e) {
        LOGGER.warn("Failed to execute http request " + request.getMethod() + " " + request.getURI() + ": "
                + e.getMessage());
        try {
            httpClient.close();
        } catch (IOException e1) {
            LOGGER.warn("After exception, Failed to close Http Client " + e1.getMessage());
        }
        return null;
    }
}

From source file:cn.wanghaomiao.seimi.core.SeimiProcessor.java

private String getRealUrl(HttpContext httpContext) {
    Object target = httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
    Object reqUri = httpContext.getAttribute(HttpCoreContext.HTTP_REQUEST);
    if (target == null || reqUri == null) {
        return null;
    }//from   w w  w .j a  va2s. c o m
    HttpHost t = (HttpHost) target;
    HttpUriRequest r = (HttpUriRequest) reqUri;
    return r.getURI().isAbsolute() ? r.getURI().toString() : t.toString() + r.getURI().toString();
}

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

@Test
public void testJiraKnox58() throws URISyntaxException, IOException {

    URI uri = new URI("http://unreachable-host");
    BasicHttpParams params = new BasicHttpParams();

    HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpUriRequest.class);
    EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes();
    EasyMock.expect(outboundRequest.getURI()).andReturn(uri).anyTimes();
    EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes();

    HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class);

    HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class);
    EasyMock.expect(outboundResponse.getOutputStream()).andAnswer(new IAnswer<ServletOutputStream>() {
        @Override//from w ww  .  j  a va 2s .c o m
        public ServletOutputStream answer() throws Throwable {
            return new ServletOutputStream() {
                @Override
                public void write(int b) throws IOException {
                    throw new IOException("unreachable-host");
                }
            };
        }
    });

    EasyMock.replay(outboundRequest, inboundRequest, outboundResponse);

    HttpClientDispatch dispatch = new HttpClientDispatch();
    try {
        dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse);
        fail("Should have thrown IOException");
    } catch (IOException e) {
        assertThat(e.getMessage(), not(containsString("unreachable-host")));
        assertThat(e, not(instanceOf(UnknownHostException.class)));
        assertThat("Message needs meaningful content.", e.getMessage().trim().length(), greaterThan(12));
    }
}

From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java

@Test
public void version() {

    HttpUriRequest request = builder.createRequest("version", null);

    assertCommonParts(request);//from w ww.  java 2  s.c o  m
    assertEquals("GET", request.getMethod());
    assertEquals("/dcc/version", request.getURI().getPath());

}

From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java

@Test
public void clean() {

    HttpUriRequest request = builder.createRequest("clean", "depId");

    assertCommonParts(request);/*w w w  . j a v a 2  s .  co  m*/
    assertEquals("PUT", request.getMethod());
    assertEquals("/dcc/depId/clean", request.getURI().getPath());
}

From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java

@Test
public void state() {

    HttpUriRequest request = builder.createRequest("state", "depId");

    assertCommonParts(request);/*from   w w  w .java 2  s  .  co m*/
    assertEquals("GET", request.getMethod());
    assertEquals("/dcc/depId/state", request.getURI().getPath());

}

From source file:org.metaeffekt.dcc.agent.DccRequestBuilderTest.java

@Test
public void logs() {

    HttpUriRequest request = builder.createRequest("logs/logId", null);

    assertCommonParts(request);/*from w  w  w. ja  va 2  s .c o  m*/
    assertEquals("GET", request.getMethod());
    assertEquals("/dcc/logs/logId", request.getURI().getPath());

}

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

private boolean checkUri(final HttpUriRequest actual) {
    if (wanted instanceof HttpUriRequest) {
        final String wantedQuery = ((HttpUriRequest) wanted).getURI().getQuery();
        final String actualQuery = actual.getURI().getQuery();
        return equalsString(wantedQuery, actualQuery);
    } else {//from w  w  w .  j  av a2s.c om
        return wanted == actual;
    }
}

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

@Test
public void testBuildRequestWithJsonPayload() throws Exception {
    final HttpUriRequest request = HttpUriRequestBuilder.create().method(HttpMethods.GET).path("/path")
            .jsonPayload(Optional.of("{'key1':'value1'}")).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));
    assertThat(request.containsHeader(HttpConstants.CONTENT_TYPE), equalTo(true));
    assertThat(request.getFirstHeader(HttpConstants.CONTENT_TYPE).getValue(),
            equalTo(HttpConstants.JSON_CONTENT_TYPE));
    assertThat(request, HttpUriRequestPayloadMatcher.hasPayload("{'key1':'value1'}"));
}