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

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

Introduction

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

Prototype

public URI getURI() 

Source Link

Document

Returns the original request URI.

Usage

From source file:org.piwik.sdk.TrackerBulkURLProcessor.java

private void logRequest(HttpRequestBase requestBase, String body) {
    Log.i(Tracker.LOGGER_TAG, "\tURI: " + requestBase.getURI().toString());
    if (body != null) {
        Log.i(Tracker.LOGGER_TAG, "\tBODY: " + body);
    }/*from   w w w.  j  a v a  2  s  .  co  m*/
}

From source file:com.jillesvangurp.httpclientfuture.HttpClientWithFuture.java

public List<Future<T>> executeMultiple(HttpContext context, long timeout, TimeUnit timeUnit,
        HttpRequestBase... requests) throws InterruptedException {
    metrics.scheduledConnections.incrementAndGet();
    List<Callable<T>> callables = new ArrayList<Callable<T>>();
    for (HttpRequestBase request : requests) {
        LoggingHttpClientTaskLifecycleCallback callback = new LoggingHttpClientTaskLifecycleCallback(
                request.getURI().toString());
        HttpClientCallable<T> callable = new HttpClientCallable<T>(httpclient, responseHandler, request,
                context, callback, metrics);
        callables.add(callable);/* ww  w  .  j a  va 2 s . c  o m*/
    }
    if (timeout > 0) {
        return executorService.invokeAll(callables, timeout, timeUnit);
    } else {
        return executorService.invokeAll(callables);
    }

}

From source file:com.woonoz.proxy.servlet.HttpRequestHandler.java

private void handleException(HttpRequestBase httpCommand, Exception e) {
    logger.error("Exception handling httpCommand: {}",
            (httpCommand != null ? httpCommand.getURI() : "(missing)"), e);
    if (httpCommand != null) {
        httpCommand.abort();//from ww  w  .j av a 2s .c  o m
    }
}

From source file:com.kolich.havalo.client.service.HavaloAbstractService.java

private final URI getFinalEndpoint(final HttpRequestBase request) {
    URI endPointURI = request.getURI();
    // If the request URI already starts with https:// then we don't
    // have to build a full endpoint URL anymore since its already
    // been provided.  This assumes the caller knows what they are
    // doing and have built a complete and proper URL to the API.
    if (!isComplete(endPointURI)) {
        endPointURI = URI.create(
                // Havalo API endpoints usually start with https://   
                apiEndpoint_.getScheme() + HTTP_SCHEME_SLASHES +
                // Returns the decoded authority component of this endpoint URI.
                // The authority of a URI is basically the hostname, otherwise
                // called the endpoint here.
                        apiEndpoint_.getAuthority() + apiEndpoint_.getPath() +
                        // Returns the decoded path component of the request URI.
                        // The path of a URI is the piece of the URI after the hostname,
                        // not including the query parameters.
                        getPath(endPointURI) +
                        // Returns the decoded query component of this URI.
                        // The query parameters, if any.
                        getQuery(endPointURI));
    }//from  w w w.j a  v a  2  s .c  o  m
    return endPointURI;
}

From source file:com.hpe.application.automation.tools.pc.MockPcRestProxy.java

@Override
protected HttpResponse executeRequest(HttpRequestBase request)
        throws PcException, ClientProtocolException, IOException {
    HttpResponse response = null;//from   ww w  .j  a  va 2  s  . c om
    String requestUrl = request.getURI().toString();
    if (requestUrl
            .equals(String.format(AUTHENTICATION_LOGIN_URL, PcTestBase.WEB_PROTOCOL, PcTestBase.PC_SERVER_NAME))
            || requestUrl.equals(String.format(AUTHENTICATION_LOGOUT_URL, PcTestBase.WEB_PROTOCOL,
                    PcTestBase.PC_SERVER_NAME))
            || requestUrl.equals(String.format(getBaseURL() + "/%s/%s/%s", RUNS_RESOURCE_NAME,
                    PcTestBase.RUN_ID, PcTestBase.STOP_MODE))) {
        response = getOkResponse();
    } else if (requestUrl.equals(String.format(getBaseURL() + "/%s", RUNS_RESOURCE_NAME)) || requestUrl
            .equals(String.format(getBaseURL() + "/%s/%s", RUNS_RESOURCE_NAME, PcTestBase.RUN_ID))) {
        response = getOkResponse();
        response.setEntity(new StringEntity(PcTestBase.runResponseEntity));
    } else if (requestUrl.equals(String.format(getBaseURL() + "/%s", TESTS_RESOURCE_NAME)) || requestUrl
            .equals(String.format(getBaseURL() + "/%s/%s", TESTS_RESOURCE_NAME, PcTestBase.TEST_ID))) {
        response = getOkResponse();
        response.setEntity(new StringEntity(PcTestBase.testResponseEntity));
    } else if (requestUrl
            .equals(String.format(getBaseURL() + "/%s/%s", RUNS_RESOURCE_NAME, PcTestBase.RUN_ID_WAIT))) {
        response = getOkResponse();
        response.setEntity(
                new StringEntity(PcTestBase.runResponseEntity.replace("*", runState.next().value())));
        if (!runState.hasNext())
            runState = initializeRunStateIterator();
    } else if (requestUrl.equals(String.format(getBaseURL() + "/%s/%s/%s", RUNS_RESOURCE_NAME,
            PcTestBase.RUN_ID, RESULTS_RESOURCE_NAME))) {
        response = getOkResponse();
        response.setEntity(new StringEntity(PcTestBase.runResultsEntity));
    } else if (requestUrl.equals(String.format(getBaseURL() + "/%s/%s/%s/%s/data", RUNS_RESOURCE_NAME,
            PcTestBase.RUN_ID, RESULTS_RESOURCE_NAME, PcTestBase.REPORT_ID))) {
        response = getOkResponse();
        response.setEntity(
                new FileEntity(new File(getClass().getResource(PcBuilder.pcReportArchiveName).getPath()),
                        ContentType.DEFAULT_BINARY));
    }
    if (response == null)
        throw new PcException(
                String.format("%s %s is not recognized by PC Rest Proxy", request.getMethod(), requestUrl));
    return response;
}

From source file:com.thoughtworks.go.util.HttpService.java

public CloseableHttpResponse execute(HttpRequestBase httpMethod) throws IOException {
    GoAgentServerHttpClient client = httpClientFactory.httpClient();

    if (httpMethod.getURI().getScheme().equals("http") || !useMutualTLS) {
        httpMethod.setHeader("X-Agent-GUID", agentRegistry.uuid());
        httpMethod.setHeader("Authorization", agentRegistry.token());
    }//from   w ww.j a va  2s . co m

    CloseableHttpResponse response = client.execute(httpMethod);
    LOGGER.info("Got back {} from server", response.getStatusLine().getStatusCode());
    return response;
}

From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java

/**
 * @param request// w  w w.ja va2  s .  co m
 * @param uriComponents
 * @see org.soyatec.windowsazure.authenticate.SharedKeyCredentials#signRequest(org.apache.http.HttpRequest,
 *      org.soyatec.windowsazure.internal.ResourceUriComponents)
 */
public void signRequest(HttpRequest request, ResourceUriComponents uriComponents) {
    if (request instanceof HttpRequestBase) {
        HttpRequestBase hrb = ((HttpRequestBase) request);
        URI uri = hrb.getURI();
        // replace the container name
        // replace the blob name
        // replace the account name
        uri = replaceAccountName(uri, shareAccessUrl.getAccountName());
        uri = replaceContainerName(uri, shareAccessUrl.getContainerName());
        uri = appendSignString(uri, shareAccessUrl.getSignedString());
        ((HttpRequestBase) request).setURI(uri);
    }

    //addVerisonHeader(request);
}

From source file:mobi.jenkinsci.ci.client.JenkinsHttpClient.java

private void ensurePreemptiveAuthRequest(final HttpRequestBase req) {
    final String username = config.getUsername();
    final String password = config.getPassword();
    final URI reqUri = req.getURI();
    final String reqUriString = reqUri.toString();
    if (reqUriString.indexOf(username) < 0) {
        try {//from  ww  w.  ja v a  2  s  . com
            final String newUriString = reqUriString.replaceAll("://", "://"
                    + URLEncoder.encode(username, "UTF-8") + ":" + URLEncoder.encode(password, "UTF-8") + "@");
            req.setURI(new URI(newUriString));
        } catch (final Exception e) {
            LOG.error("Cannot insert user into URI " + reqUriString, e);
            return;
        }
    }
}

From source file:com.flicklib.service.HttpClientSourceLoader.java

private Source buildSource(String url, HttpResponse response, HttpRequestBase httpMethod, HttpContext ctx)
        throws IOException {
    LOGGER.info("Finished loading at " + httpMethod.getURI().toString());
    final HttpEntity entity = response.getEntity();
    String responseCharset = EntityUtils.getContentCharSet(entity);
    String contentType = EntityUtils.getContentMimeType(entity);
    LOGGER.info("Response charset = " + responseCharset);
    String content = EntityUtils.toString(entity);

    HttpUriRequest req = (HttpUriRequest) ctx.getAttribute(ExecutionContext.HTTP_REQUEST);
    HttpHost target = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    URI resultUri;/*  w  w  w  . jav a2s . co  m*/
    try {
        resultUri = (target != null && req != null) ? new URI(target.toURI() + req.getURI().toString())
                : httpMethod.getURI();
    } catch (URISyntaxException e) {
        e.printStackTrace();
        resultUri = httpMethod.getURI();
    }
    // String contentType = URLConnection.guessContentTypeFromName(url)
    return new Source(resultUri.toString(), content, contentType, url);
}

From source file:net.paissad.waqtsalat.service.utils.HttpUtils.java

private static InputStream sendRequest(final String url, final RequestType requestType) throws WSException {

    InputStream in = null;/*from   w  ww. j ava  2  s.  c  o m*/
    HttpClient client = null;
    HttpRequestBase request = null;
    boolean errorOccured = false;

    try {
        request = getNewHttpRequest(url, requestType, null);
        client = getNewHttpClient();
        HttpResponse resp = client.execute(request);

        int statusCode = resp.getStatusLine().getStatusCode();

        if (statusCode == HttpStatus.SC_OK) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(resp.getEntity().getContent(), baos);
            baos.flush();
            in = new ByteArrayInputStream(baos.toByteArray());

        } else {
            // The response code is not OK.
            StringBuilder errMsg = new StringBuilder();
            errMsg.append("HTTP ").append(requestType).append(" failed => ").append(resp.getStatusLine());
            if (request != null) {
                errMsg.append(" : ").append(request.getURI());
            }
            throw new WSException(errMsg.toString());
        }

        return in;

    } catch (Exception e) {
        errorOccured = true;
        throw new WSException("Error during file HTTP request.", e);

    } finally {
        if (errorOccured) {
            if (request != null) {
                request.abort();
            }
        }
        if (client != null) {
            client.getConnectionManager().shutdown();
        }
    }
}