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.vmware.photon.controller.nsxclient.RestClientTest.java

@Test
public void testPerformPut() {
    String payload = "{name: DUMMY}";
    ArgumentCaptor<HttpUriRequest> argumentCaptor = setup(RestClient.Method.PUT,
            new StringEntity(payload, ContentType.APPLICATION_JSON));

    HttpUriRequest request = argumentCaptor.getValue();
    assertNotNull(request);/*from   w  w  w.j av a  2s . c  o m*/
    assertTrue(request.getMethod().equalsIgnoreCase(RestClient.Method.PUT.toString()));
    assertEquals(request.getURI().toString(), target + path);

    HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) request;
    String actualPayload = null;
    try {
        actualPayload = IOUtils.toString(httpEntityEnclosingRequest.getEntity().getContent());
    } catch (IOException e) {
        fail(e.getMessage());
    }

    assertEquals(actualPayload, payload);
}

From source file:com.lumata.lib.lupa.internal.ProxiedReadableResource.java

/**
 * Gets the final URL reached on the current request after redirections
 * //from   w ww  .  j a  va 2s.  co m
 * @param locaContext
 *            the context used on the HTTP request execution
 * @return the target URL
 */
private String getTargetUrl(HttpContext locaContext) {
    HttpUriRequest currentReq = (HttpUriRequest) locaContext.getAttribute(ExecutionContext.HTTP_REQUEST);
    HttpHost currentHost = (HttpHost) locaContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    return currentHost.toURI() + currentReq.getURI();
}

From source file:com.vmware.photon.controller.nsxclient.RestClientTest.java

@Test
public void testPerformPost() {
    String payload = "{name: DUMMY}";
    ArgumentCaptor<HttpUriRequest> argumentCaptor = setup(RestClient.Method.POST,
            new StringEntity(payload, ContentType.APPLICATION_JSON));

    HttpUriRequest request = argumentCaptor.getValue();
    assertNotNull(request);/* www.jav a  2s.c  o m*/
    assertTrue(request.getMethod().equalsIgnoreCase(RestClient.Method.POST.toString()));
    assertEquals(request.getURI().toString(), target + path);

    HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) request;
    String actualPayload = null;
    try {
        actualPayload = IOUtils.toString(httpEntityEnclosingRequest.getEntity().getContent());
    } catch (IOException e) {
        fail(e.getMessage());
    }

    assertEquals(actualPayload, payload);
}

From source file:com.google.android.net.GoogleHttpClient.java

public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
    // Rewrite the supplied URL...
    URI uri = request.getURI();
    String original = uri.toString();
    UrlRules rules = UrlRules.getRules(mResolver);
    UrlRules.Rule rule = rules.matchRule(original);
    String rewritten = rule.apply(original);

    if (rewritten == null) {
        Log.w(TAG, "Blocked by " + rule.mName + ": " + original);
        throw new BlockedRequestException(rule);
    } else if (rewritten == original) {
        return executeWithoutRewriting(request, context); // Pass through
    }/*from w  w  w  . j a  v a  2s  . c o  m*/

    try {
        uri = new URI(rewritten);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Bad URL from rule: " + rule.mName, e);
    }

    // Wrap request so we can replace the URI.
    RequestWrapper wrapper = wrapRequest(request);
    wrapper.setURI(uri);
    request = wrapper;

    if (Config.LOGV) {
        Log.v(TAG, "Rule " + rule.mName + ": " + original + " -> " + rewritten);
    }
    return executeWithoutRewriting(request, context);
}

From source file:org.apache.hadoop.gateway.ha.dispatch.DefaultHaDispatch.java

private void failoverRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest,
        HttpServletResponse outboundResponse, HttpResponse inboundResponse, Exception exception)
        throws IOException {
    LOG.failingOverRequest(outboundRequest.getURI().toString());
    AtomicInteger counter = (AtomicInteger) inboundRequest.getAttribute(FAILOVER_COUNTER_ATTRIBUTE);
    if (counter == null) {
        counter = new AtomicInteger(0);
    }/* w w w .j ava2s  .  co  m*/
    inboundRequest.setAttribute(FAILOVER_COUNTER_ATTRIBUTE, counter);
    if (counter.incrementAndGet() <= maxFailoverAttempts) {
        haProvider.markFailedURL(getServiceRole(), outboundRequest.getURI().toString());
        //null out target url so that rewriters run again
        inboundRequest.setAttribute(AbstractGatewayFilter.TARGET_REQUEST_URL_ATTRIBUTE_NAME, null);
        URI uri = getDispatchUrl(inboundRequest);
        ((HttpRequestBase) outboundRequest).setURI(uri);
        if (failoverSleep > 0) {
            try {
                Thread.sleep(failoverSleep);
            } catch (InterruptedException e) {
                LOG.failoverSleepFailed(getServiceRole(), e);
            }
        }
        executeRequest(outboundRequest, inboundRequest, outboundResponse);
    } else {
        LOG.maxFailoverAttemptsReached(maxFailoverAttempts, getServiceRole());
        if (inboundResponse != null) {
            writeOutboundResponse(outboundRequest, inboundRequest, outboundResponse, inboundResponse);
        } else {
            throw new IOException(exception);
        }
    }
}

From source file:org.jasig.portlet.proxy.service.web.HttpContentServiceImplTest.java

@Test
public void testGetForm() {

    params.put("param1", new String[] { "value1" });
    params.put("param2", new String[] { "value3", "value4" });

    when(request.getParameter(HttpContentServiceImpl.IS_FORM_PARAM)).thenReturn("true");
    when(request.getParameter(HttpContentServiceImpl.FORM_METHOD_PARAM)).thenReturn("GET");
    when(processor.process(any(String.class), any(PortletRequest.class)))
            .thenReturn("http://somewhere.com/path/page.html");
    HttpContentRequestImpl proxyRequest = new HttpContentRequestImpl(request, processor);

    final HttpUriRequest httpRequest = service.getHttpRequest(proxyRequest, request);
    assertEquals("GET", httpRequest.getMethod());
    assertEquals("http://somewhere.com/path/page.html?param1=value1&param2=value3&param2=value4",
            httpRequest.getURI().toString());

}

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

private void alert(IInjectionModuleContext ctx, String type, String message, HttpUriRequest request,
        IHttpResponse response) {/* w w w.  j a  va 2 s  .c  o m*/
    final String resource = request.getURI().toString();
    final String key = createAlertKey(ctx, type, request);
    ctx.publishAlert(type, key, message, request, response, "resource", resource);
}

From source file:org.fcrepo.apix.jena.impl.LdpContainerRegistryTest.java

@SuppressWarnings("unchecked")
@Test//from  w  w w.ja va2s.  c  om
public void createWithInitialContentTest() throws Exception {
    final URI containerURI = URI.create("test:Container");
    toTest.setContainer(containerURI);

    when(entityStatus.getStatusCode()).thenReturn(HttpStatus.SC_CREATED);

    when(header.getValue()).thenReturn(containerURI.toString());
    when(entityResponse.getFirstHeader(HttpHeaders.LOCATION)).thenReturn(header);

    when(headStatus.getStatusCode()).thenReturn(HttpStatus.SC_NOT_FOUND);

    toTest.setCreateContainer(true);
    toTest.setHttpClient(client);
    toTest.setContainerContent(URI.create("classpath:/objects/service-registry.ttl"));
    toTest.init();

    verify(client, times(1)).execute(requestCaptor.capture(), isA(ResponseHandler.class));

    final HttpUriRequest request = requestCaptor.getValue();

    assertEquals(HttpPut.class, request.getClass());
    assertEquals(containerURI, request.getURI());

    final byte[] content = IOUtils.toByteArray(((HttpPut) request).getEntity().getContent());
    assertTrue(content.length > 0);

}

From source file:io.soabase.client.apache.WrappedHttpClient.java

@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
    addRequestId(request);/*from w ww.j a  v  a  2  s.  c  o  m*/

    RetryContext retryContext = new RetryContext(retryComponents, request.getURI(), request.getMethod());
    for (int retryCount = 0; /* no check */; ++retryCount) {
        SoaDiscoveryInstance instance = ClientUtils.hostToInstance(discovery, retryContext.getOriginalHost());
        retryContext.setInstance(instance);

        URI filteredUri = ClientUtils.filterUri(request.getURI(), instance);
        if (filteredUri != null) {
            request = new WrappedHttpUriRequest(request, filteredUri);
        }
        try {
            HttpResponse response = implementation.execute(request, context);
            if (!retryContext.shouldBeRetried(retryCount, response.getStatusLine().getStatusCode(), null)) {
                return response;
            }
        } catch (IOException e) {
            if (!retryContext.shouldBeRetried(retryCount, 0, e)) {
                throw e;
            }
        }
    }
}