Example usage for org.apache.http.client.utils URIBuilder URIBuilder

List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder URIBuilder.

Prototype

public URIBuilder(final URI uri) 

Source Link

Document

Construct an instance from the provided URI.

Usage

From source file:ph.com.globe.connect.Authentication.java

/**
 * Returns the Oauth dialog url./*  w w w.j ava2s .  c om*/
 * 
 * @return String
 * @throws ApiException api exception
 */
public String getDialogUrl() throws ApiException {
    // try parsing url
    try {
        // build url
        String url = this.API_HOST + this.DIALOG_URL;
        // initialize url builder
        URIBuilder builder = new URIBuilder(url);

        // set app_id parameter
        builder.setParameter("app_id", this.appId);

        // build the url
        url = builder.build().toString();

        return url;
    } catch (URISyntaxException e) {
        // throw exception
        throw new ApiException(e.getMessage());
    }
}

From source file:com.axelor.studio.web.ReportBuilderController.java

private ActionResponse downloadPdf(String html, String fileName, Boolean printPageNo, ActionResponse response)
        throws URISyntaxException {

    URIBuilder builder = new URIBuilder("ws/htmlToPdf");
    builder.addParameter("html", html);
    builder.addParameter("fileName", fileName);
    if (printPageNo != null && printPageNo) {
        builder.addParameter("printPageNo", "true");
    }/*from  w ww .  j  a v  a  2  s .  c o m*/

    String url = builder.build().toString();
    response.setView(ActionView.define(I18n.get("Print")).add("html", url).param("download", "true")
            .param("fileName", fileName).map());

    return response;
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransport.java

/**
 * @see Transport#ping(PingRequest)//from  ww  w  . jav  a 2  s. c  o  m
 */
public PingResponse ping(PingRequest request) throws LaunchKeyException {
    log.trace("Beginning ping request");
    PingResponse pingResponse;
    try {
        URIBuilder uriBuilder = new URIBuilder(getUrlForPath("/ping"));
        String dateStamp = request.getDateStamp();
        if (dateStamp != null) {
            uriBuilder.setParameter("date_stamp", dateStamp);
        }
        HttpGet ping = new HttpGet(uriBuilder.build());
        HttpResponse httpResponse = client.execute(ping);
        pingResponse = getTransportObjectFromResponse(PingResponse.class, httpResponse);
    } catch (LaunchKeyException e) {
        log.trace("Error encountered in response from LaunchKey engine", e);
        throw e;
    } catch (Exception e) {
        log.trace("Exception caught processing ping request", e);
        throw new LaunchKeyException("Exception caught processing ping request", e, 0);
    }
    log.trace("Completed ping request");
    log.trace(pingResponse);
    return pingResponse;
}

From source file:org.eclipse.cft.server.core.internal.ssh.SshClientSupport.java

public String getSshCode() {
    try {/*from  w  ww .j  a v  a  2  s .  com*/
        URIBuilder builder = new URIBuilder(authorizationUrl + "/oauth/authorize"); //$NON-NLS-1$

        builder.addParameter("response_type" //$NON-NLS-1$
                , "code"); //$NON-NLS-1$
        builder.addParameter("grant_type", //$NON-NLS-1$
                "authorization_code"); //$NON-NLS-1$
        builder.addParameter("client_id", sshClientId); //$NON-NLS-1$

        URI url = new URI(builder.toString());

        ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
        HttpStatus statusCode = response.getStatusCode();
        if (statusCode != HttpStatus.FOUND) {
            throw new CloudFoundryException(statusCode);
        }

        String loc = response.getHeaders().getFirst("Location"); //$NON-NLS-1$
        if (loc == null) {
            throw new CloudOperationException("No 'Location' header in redirect response"); //$NON-NLS-1$
        }
        List<NameValuePair> qparams = URLEncodedUtils.parse(new URI(loc), "utf8"); //$NON-NLS-1$
        for (NameValuePair pair : qparams) {
            String name = pair.getName();
            if (name.equals("code")) { //$NON-NLS-1$
                return pair.getValue();
            }
        }
        throw new CloudOperationException("No 'code' param in redirect Location: " + loc); //$NON-NLS-1$
    } catch (URISyntaxException e) {
        throw new CloudOperationException(e);
    }
}

From source file:com.sheepdog.mashmesh.PickupNotification.java

private URI createStaticMapUri(String overviewPolyline) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(STATIC_MAPS_ENDPOINT_URL);

    uriBuilder.addParameter("sensor", "false");
    uriBuilder.addParameter("key", ApplicationConfiguration.getApiKey());
    uriBuilder.addParameter("size", "600x400");
    uriBuilder.addParameter("markers", "color:green|label:A|" + itinerary.getStartLatLng());
    uriBuilder.addParameter("markers", "color:blue|label:B|" + itinerary.getPickupLatLng());
    uriBuilder.addParameter("markers", "color:blue|label:C|" + itinerary.getEndLatLng());
    uriBuilder.addParameter("language", "en_US");
    uriBuilder.addParameter("maptype", "roadmap");

    if (!overviewPolyline.isEmpty()) {
        uriBuilder.addParameter("path", "weight:4|color:blue|enc:" + overviewPolyline);
    }//www  . ja va2 s. c o  m

    return uriBuilder.build();
}

From source file:ezbake.azkaban.manager.ExecutionManager.java

/**
 * Class for executing a flow in Azkaban
 *
 * @param azkabanUri The Azkaban URL/* ww w. j av  a2s. c o m*/
 * @param username   The username to use
 * @param password   The password for the username
 */
public ExecutionManager(URI azkabanUri, String username, String password) {
    try {
        this.executionUri = new URIBuilder(azkabanUri).setPath("/executor").build();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    final AuthenticationManager azkabanAuthenticator = new AuthenticationManager(azkabanUri, username,
            password);
    final AuthenticationResult result = azkabanAuthenticator.login();
    if (result.hasError()) {
        throw new IllegalStateException(result.getError());
    }
    this.sessionId = result.getSessionId();
}

From source file:io.rainfall.web.operation.HttpOperation.java

private HttpRequestBase httpRequest(final String finalUrl) {
    try {/*from   ww w  .j  a v  a  2 s .  c o m*/
        if (HttpRequest.GET.equals(this.operation)) {
            return new HttpGet(new URIBuilder(finalUrl).setParameters(this.queryParams).build());
        } else if (HttpRequest.POST.equals(this.operation)) {
            return new HttpPost(new URIBuilder(finalUrl).setParameters(this.queryParams).build());
        }
    } catch (URISyntaxException e) {
        return null;
    }
    return null;
}

From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4Client.java

private HttpRequestBase buildRequest(Request request) {

    Method method = request.getMethod();
    String url = request.getUrl();
    String body = request.getBody();

    if (request.getParameters() != null) {
        try {//from  w  ww.  j  a  v  a2  s.  c  om
            URIBuilder builder = new URIBuilder(url);
            for (Map.Entry<String, String> param : request.getParameters().entrySet()) {
                builder.setParameter(param.getKey(), param.getValue());
            }
            url = builder.build().toString();
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Invalid URL: \"" + request.getUrl() + "\"");
        }
    }

    HttpRequestBase clientRequest = createBaseRequest(method, url, body);

    if (request.getHeaders() != null) {
        for (Map.Entry<String, String> header : request.getHeaders().entrySet()) {
            clientRequest.setHeader(header.getKey(), header.getValue());
        }
    }

    return clientRequest;

}

From source file:com.github.tmyroadctfig.icloud4j.DriveNode.java

/**
 * Downloads the file data for the item into the given output stream.
 *
 * @param outputStream the output stream to write to.
 *///from ww  w.ja v a 2s  .com
public void downloadFileData(OutputStream outputStream) {
    try {
        URIBuilder uriBuilder = new URIBuilder(
                String.format("%s/ws/%s/download/by_id", driveService.getDocsServiceUrl(), nodeDetails.zone));
        iCloudService.populateUriParameters(uriBuilder);
        uriBuilder.addParameter("clientMasteringNumber", iCloudService.getClientBuildNumber());
        uriBuilder.addParameter("document_id", Iterables.getLast(Splitter.on(":").splitToList(id)));
        uriBuilder.addParameter("token", downloadUrlToken);
        URI contentUrlLookupUrl = uriBuilder.build();

        // Get the download URL for the item
        HttpGet contentUrlGetRequest = new HttpGet(contentUrlLookupUrl);
        iCloudService.populateRequestHeadersParameters(contentUrlGetRequest);

        Map<String, Object> result = iCloudService.getHttpClient().execute(contentUrlGetRequest,
                new JsonToMapResponseHandler());
        @SuppressWarnings("unchecked")
        Map<String, Object> dataTokenMap = (Map<String, Object>) result.get("data_token");

        String contentUrl = (String) dataTokenMap.get("url");
        HttpGet contentRequest = new HttpGet(contentUrl);

        try (InputStream inputStream = iCloudService.getHttpClient().execute(contentRequest).getEntity()
                .getContent()) {
            IOUtils.copyLarge(inputStream, outputStream, new byte[0x10000]);
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}