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

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

Introduction

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

Prototype

public URIBuilder addParameter(final String param, final String value) 

Source Link

Document

Adds parameter to URI query.

Usage

From source file:org.apache.ambari.server.view.ViewURLStreamProvider.java

private String addDoAs(String spec, String userName) throws IOException {
    if (spec.toLowerCase().contains(DO_AS_PARAM)) {
        throw new IllegalArgumentException("URL cannot contain \"" + DO_AS_PARAM + "\" parameter.");
    }//  ww  w .  j  ava2 s  .  com

    try {
        URIBuilder builder = new URIBuilder(spec);
        builder.addParameter(DO_AS_PARAM, userName);
        return builder.build().toString();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
}

From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java

@Override
public List<ResourceDescriptor> list(IProgressMonitor monitor, ResourceDescriptor rd) throws Exception {
    List<ResourceDescriptor> rds = new ArrayList<ResourceDescriptor>();
    if (rd.getWsType().equals(ResourceDescriptor.TYPE_REPORTUNIT)) {
        rd = get(monitor, rd, null);//ww w.j a va2s  . c  o m
        return rd.getChildren();
    } else {
        URIBuilder ub = new URIBuilder(url("resources"));
        ub.addParameter("folderUri", rd.getUriString());
        ub.addParameter("recursive", "false");
        ub.addParameter("sortBy", "label");
        ub.addParameter("limit", Integer.toString(Integer.MAX_VALUE));

        ClientResourceListWrapper resources = toObj(HttpUtils.get(ub.build().toASCIIString(), sp),
                ClientResourceListWrapper.class, monitor);
        if (resources != null)
            for (ClientResourceLookup crl : resources.getResourceLookups())
                rds.add(Rest2Soap.getRDLookup(this, crl));
    }
    return rds;
}

From source file:com.michaeljones.httpclient.apache.ApacheMethodClient.java

@Override
public int PutQuery(String url, List<Pair<String, String>> queryParams, StringBuilder redirect) {
    try {/*from   w w w. j  a v  a  2 s .  c o  m*/
        HttpPut httpPut = new HttpPut();
        URIBuilder fileUri = new URIBuilder(url);

        if (queryParams != null) {
            for (Pair<String, String> queryParam : queryParams) {
                fileUri.addParameter(queryParam.getFirst(), queryParam.getSecond());
            }
        }

        httpPut = new HttpPut(fileUri.build());
        CloseableHttpResponse response = clientImpl.execute(httpPut);
        try {
            Header[] hdrs = response.getHeaders("Location");
            if (redirect != null && hdrs.length > 0) {
                String redirectLocation = hdrs[0].getValue();

                redirect.append(redirectLocation);
                LOGGER.debug("Redirect to: " + redirectLocation);
            }

            return response.getStatusLine().getStatusCode();
        } finally {
            // I believe this releases the connection to the client pool, but does not
            // close the connection.
            response.close();
        }
    } catch (IOException | URISyntaxException ex) {
        throw new RuntimeException("Apache method putQuery: " + ex.getMessage());
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.portal.Portal.java

/**
 * Opens a new portal page in the current browser window
 *
 * @param friendlyUrl the url of the target page
 * @param parameters map of strings that are passed as portal parameters
 * @throws URISyntaxException/*from ww w  .j  av a 2 s .  co m*/
 */
public void open(String friendlyUrl, Map<String, String> parameters) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(friendlyUrl);
    if (parameters != null) {
        for (Entry<String, String> entry : parameters.entrySet()) {
            uriBuilder.addParameter(entry.getKey(), entry.getValue());
        }
    }
    String url = uriBuilder.build().toASCIIString();
    UI.getCurrent().getPage().open(url, "_self");
}

From source file:org.apache.falcon.request.BaseRequest.java

public HttpResponse run()
        throws URISyntaxException, IOException, AuthenticationException, InterruptedException {
    URIBuilder uriBuilder = new URIBuilder(this.url);

    /*falcon now reads a user.name parameter in the request.
    by default we will add it to every request.*/
    uriBuilder.addParameter(PseudoAuthenticator.USER_NAME, this.user);
    uri = uriBuilder.build();//from   w w  w.  j av  a2  s  . com
    this.url = uri.toString();
    // process the get
    if (this.method.equalsIgnoreCase("get")) {
        return execute(new HttpGet(this.url));
    } else if (this.method.equalsIgnoreCase("delete")) {
        return execute(new HttpDelete(this.url));
    }

    HttpEntityEnclosingRequest request = null;
    if (this.method.equalsIgnoreCase("post")) {
        request = new HttpPost(new URI(this.url));
    } else if (this.method.equalsIgnoreCase("put")) {
        request = new HttpPut(new URI(this.url));
    } else {
        throw new IOException("Unknown method: " + method);
    }
    if (this.requestData != null) {
        request.setEntity(new StringEntity(requestData));
    }
    return execute(request);
}

From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java

@Override
public ResourceDescriptor move(IProgressMonitor monitor, ResourceDescriptor rd, String destFolderURI)
        throws Exception {
    URIBuilder ub = new URIBuilder(url("resources" + destFolderURI));
    ub.addParameter("overwrite", "true");
    ub.addParameter("createFolders", "true");
    Request req = HttpUtils.put(ub.build().toASCIIString(), sp);
    req.setHeader("Content-Location", rd.getUriString());
    String rtype = WsTypes.INST().toRestType(rd.getWsType());
    ClientResource<?> crl = toObj(req, WsTypes.INST().getType(rtype), monitor);
    if (crl != null)
        return Rest2Soap.getRD(this, crl, rd);
    return null;//w  w  w .ja v a  2s  .  com
}

From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java

@Override
public ResourceDescriptor copy(IProgressMonitor monitor, ResourceDescriptor rd, String destFolderURI)
        throws Exception {
    URIBuilder ub = new URIBuilder(url("resources" + destFolderURI));
    ub.addParameter("overwrite", "true");
    ub.addParameter("createFolders", "true");
    Request req = HttpUtils.post(ub.build().toASCIIString(), sp);
    req.setHeader("Content-Location", rd.getUriString());
    String rtype = WsTypes.INST().toRestType(rd.getWsType());
    ClientResource<?> crl = toObj(req, WsTypes.INST().getType(rtype), monitor);
    if (crl != null)
        return Rest2Soap.getRD(this, crl, rd);
    return null;/*  w ww  .  j a  v  a 2s  .  com*/
}

From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java

@Override
public ResourceDescriptor get(IProgressMonitor monitor, ResourceDescriptor rd, File f) throws Exception {
    URIBuilder ub = new URIBuilder(url("resources" + rd.getUriString()));
    ub.addParameter("expanded", "true");
    Request req = HttpUtils.get(ub.build().toASCIIString(), sp);
    String rtype = WsTypes.INST().toRestType(rd.getWsType());
    req.setHeader("Accept", "application/repository." + rtype + "+" + FORMAT);
    ClientResource<?> crl = toObj(req, WsTypes.INST().getType(rtype), monitor);
    if (crl != null)
        return Rest2Soap.getRD(this, crl, rd);
    return null;/* www. j  a v a  2s  . co m*/
}

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.
 *//*  ww  w  .  j a  va  2 s  .co  m*/
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);
    }
}

From source file:org.broadleafcommerce.core.web.breadcrumbs.AbstractBreadcrumbServiceExtensionHandler.java

public String buildLink(String url, Map<String, String[]> params) {
    URIBuilder builder;
    try {// ww  w  .ja  va 2s. co  m
        builder = new URIBuilder(url);
        if (params != null) {
            for (String key : params.keySet()) {
                String[] paramValues = params.get(key);
                for (String value : paramValues) {
                    builder.addParameter(key, value);
                }
            }
        }
        return builder.build().toString();
    } catch (URISyntaxException e) {
        LOG.error("Error creating link for breadcrumb ", e);
        return url;
    }
}