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:tech.sirwellington.alchemy.http.AlchemyRequestMapperTest.java

@Test
public void testPostExpandsURL() throws Exception {
    instance = AlchemyRequestMapper.POST;

    when(request.hasQueryParams()).thenReturn(Boolean.TRUE);

    HttpUriRequest result = instance.convertToApacheRequest(request);
    assertThat(result.getURI(), is(expandedUrl.toURI()));
}

From source file:tech.sirwellington.alchemy.http.AlchemyRequestMapperTest.java

@Test
public void testPutExpandsURL() throws Exception {
    instance = AlchemyRequestMapper.PUT;

    when(request.hasQueryParams()).thenReturn(Boolean.TRUE);

    HttpUriRequest result = instance.convertToApacheRequest(request);
    assertThat(result.getURI(), is(expandedUrl.toURI()));
}

From source file:tech.sirwellington.alchemy.http.AlchemyRequestMapperTest.java

@Test
public void testDeleteExpandsURL() throws Exception {
    instance = AlchemyRequestMapper.DELETE;

    when(request.hasQueryParams()).thenReturn(Boolean.TRUE);

    HttpUriRequest result = instance.convertToApacheRequest(request);
    assertThat(result.getURI(), is(expandedUrl.toURI()));
}

From source file:org.mythdroid.services.JSONClient.java

private JSONObject Request(HttpUriRequest req) throws IOException {

    req.setHeader("Accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
    LogUtil.debug("JSON request: " + req.getURI().toString()); //$NON-NLS-1$

    String res = null;/*from   ww w  .  j a v  a  2  s  .c om*/

    try {
        res = new HttpFetcher(req, Globals.muxConns).getContent();
    } catch (SocketTimeoutException e) {
        throw new IOException(Messages.getString("JSONClient.0") + //$NON-NLS-1$
                req.getURI().getHost() + ":" + req.getURI().getPort() //$NON-NLS-1$
        );
    } catch (ClientProtocolException e) {
        ErrUtil.logErr(e);
        throw new IOException(e.getMessage());
    }

    LogUtil.debug("JSON response: " + res); //$NON-NLS-1$

    try {
        return new JSONObject(res);
    } catch (JSONException e) {
        ErrUtil.logErr(e);
        throw new IOException(e.getMessage());
    }

}

From source file:com.jgoetsch.eventtrader.source.HttpStreamingMsgSource.java

protected boolean executeRequest(HttpClient client, HttpUriRequest request, MsgParser msgParser) {
    HttpEntity entity = null;/*from w w w.j av a  2  s.  c  o  m*/
    try {
        HttpResponse rsp = client.execute(request);
        entity = rsp.getEntity();
        if (rsp.getStatusLine().getStatusCode() >= 400 || entity == null) {
            log.warn("HTTP request to " + request.getURI() + " failed with status " + rsp.getStatusLine());

            // if 400 level error don't keep trying
            return (rsp.getStatusLine().getStatusCode() >= 500);
        } else {
            log.info("Connected to streaming source " + request.getURI().getHost() + ", waiting for messages");
            return msgParser.parseContent(entity.getContent(), -1, entity.getContentType().getValue(), this);
        }
    } catch (SocketTimeoutException e) {
        return true;
    } catch (Exception e) {
        log.warn("Exception reading or parsing message source", e);
        return false;
    } finally {
        request.abort();
    }
}

From source file:org.everit.authentication.http.session.ecm.tests.SessionAuthenticationComponentTest.java

private void logoutGet(final HttpContext httpContext) throws ClientProtocolException, IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(logoutUrl);
    HttpResponse httpResponse = httpClient.execute(httpGet, httpContext);
    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, httpResponse.getStatusLine().getStatusCode());

    HttpUriRequest currentReq = (HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST);
    HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString()
            : (currentHost.toURI() + currentReq.getURI());
    Assert.assertEquals(loggedOutUrl, currentUrl);
}

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

@Test
public void configure() {

    HttpUriRequest request = builder.createRequest("configure", "depId", "somePackage", "someUnit");

    assertCommonParts(request);//from  w w w.j a  v  a2  s  . c o  m
    assertEquals("PUT", request.getMethod());
    assertEquals("/dcc/depId/packages/somePackage/units/someUnit/configure", request.getURI().getPath());
}

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

@Test
public void bootstrap() {

    HttpUriRequest request = builder.createRequest("bootstrap", "depId", "somePackage", "someUnit");

    assertCommonParts(request);//from   ww  w.  j ava2 s.c om
    assertEquals("PUT", request.getMethod());
    assertEquals("/dcc/depId/packages/somePackage/units/someUnit/bootstrap", request.getURI().getPath());
}

From source file:org.pixmob.feedme.net.NetworkClient.java

private void prepareRequest(HttpUriRequest req) throws NetworkClientException {
    final String authToken = getAuthToken();
    if (authToken == null) {
        throw new NetworkClientException("Missing authentication token", req.getURI().toString());
    }//  w  ww . ja v  a  2 s. c  o m
    req.setHeader("Authorization", "GoogleLogin auth=" + authToken);
}

From source file:com.subgraph.vega.impl.scanner.urls.ResponseAnalyzer.java

private String createAlertKey(IInjectionModuleContext ctx, String type, HttpUriRequest request) {
    if (ctx.getPathState().isParametric()) {
        final String uri = stripQuery(request.getURI()).toString();
        return type + ":" + uri + ":" + ctx.getPathState().getFuzzableParameter().getName();
    } else {/*from w  ww .j  a  v a2 s. c om*/
        return type + ":" + request.getURI();
    }
}