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.qucosa.camel.component.fcrepo3.Fcrepo3APIAccess.java

public void modifyDatastream(String pid, String dsid, Boolean versionable, InputStream content)
        throws IOException {
    HttpResponse response = null;/*w  w  w .  j a  va 2  s .  c  o  m*/
    try {
        BasicHttpEntity entity = new BasicHttpEntity();
        entity.setContent(content);
        // Entity needs to be buffered because Fedora might reply in a way
        // forces resubmitting the entity
        BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);

        URIBuilder uriBuilder = new URIBuilder(
                format(FEDORA_DATASTREAM_MODIFICATION_URI_PATTERN, host, port, pid, dsid));
        if (versionable != null) {
            uriBuilder.addParameter("versionable", String.valueOf(versionable));
        }
        URI uri = uriBuilder.build();

        HttpPut put = new HttpPut(uri);
        put.setEntity(bufferedHttpEntity);
        response = httpClient.execute(put);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new IOException(format("Cannot modify datastream %s of object %s. Server responded: %s", dsid,
                    pid, response.getStatusLine()));
        }
    } catch (URISyntaxException e) {
        throw new IOException("Cannot ", e);
    } finally {
        consumeResponseEntity(response);
    }
}

From source file:com.activiti.service.activiti.ProcessDefinitionService.java

public JsonNode listProcesDefinitions(ServerConfig serverConfig, Map<String, String[]> parameterMap,
        boolean latest) {

    URIBuilder builder = null;
    try {// w  w  w  .j  a va2s .  c o  m
        builder = new URIBuilder("repository/process-definitions");
    } catch (Exception e) {
        log.error("Error building uri", e);
        throw new ActivitiServiceException("Error building uri", e);
    }

    for (String name : parameterMap.keySet()) {
        builder.addParameter(name, parameterMap.get(name)[0]);
    }
    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString()));
    return clientUtil.executeRequest(get, serverConfig);
}

From source file:org.flowable.admin.service.engine.ProcessDefinitionService.java

public JsonNode listProcesDefinitions(ServerConfig serverConfig, Map<String, String[]> parameterMap,
        boolean latest) {

    URIBuilder builder = null;
    try {/*from w  w w  . j  a v a  2 s.  c o  m*/
        builder = new URIBuilder("repository/process-definitions");
    } catch (Exception e) {
        log.error("Error building uri", e);
        throw new FlowableServiceException("Error building uri", e);
    }

    for (String name : parameterMap.keySet()) {
        builder.addParameter(name, parameterMap.get(name)[0]);
    }
    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString()));
    return clientUtil.executeRequest(get, serverConfig);
}

From source file:com.msopentech.odatajclient.engine.uri.AbstractURIBuilder.java

@Override
public URI build() {
    final StringBuilder segmentsBuilder = new StringBuilder();
    for (URIBuilder.Segment seg : segments) {
        if (segmentsBuilder.length() > 0 && seg.getType() != SegmentType.KEY) {
            segmentsBuilder.append('/');
        }/*from  w ww.  ja  va2s  .  c  om*/

        segmentsBuilder.append(seg.getValue());
    }

    try {
        final org.apache.http.client.utils.URIBuilder builder = new org.apache.http.client.utils.URIBuilder(
                segmentsBuilder.toString());

        for (Map.Entry<String, String> option : queryOptions.entrySet()) {
            builder.addParameter("$" + option.getKey(), option.getValue());
        }

        return builder.build().normalize();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Could not build valid URI", e);
    }
}

From source file:com.sonicle.webtop.core.app.DocEditorManager.java

private URI buildCallbackUrl(String loopbackUrl, String domainPubName, String sessionId, String editingId)
        throws URISyntaxException {
    URIBuilder builder = new URIBuilder(loopbackUrl);
    URIUtils.appendPath(builder, URIUtils.concatPaths(DocEditor.URL, domainPubName, DocEditor.TRACK_PATH));
    if (!StringUtils.isBlank(sessionId))
        builder.addParameter(DocEditor.SESSION_ID_PARAM, sessionId);
    builder.addParameter(DocEditor.EDITING_ID_PARAM, editingId);
    return builder.build();
}

From source file:com.collective.celos.CelosClient.java

public void iterateScheduler(ScheduledTime scheduledTime, Set<WorkflowID> workflowIDs) throws Exception {
    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + SCHEDULER_PATH);
    if (!workflowIDs.isEmpty()) {
        uriBuilder.addParameter(IDS_PARAM, StringUtils.join(workflowIDs, ","));
    }//  www .  ja  va2 s.  co  m
    uriBuilder.addParameter(TIME_PARAM, timeFormatter.formatPretty(scheduledTime));
    executePost(uriBuilder.build());
}

From source file:com.anrisoftware.simplerest.oanda.rest.AbstractInstrumentHistory.java

private URI getRequestURI0() throws URISyntaxException {
    URIBuilder builder = new URIBuilder(propertiesProvider.getOandaCandlesURI());
    builder.setParameter(ACCOUNT_ID_PARAM, account.getAccount());
    builder.setParameter(CANDLE_FORMAT_PARAM, candleFormat);
    builder.addParameter(INSTRUMENT_PARAM, instrument.getName());
    if (granularity != null) {
        builder.addParameter(GRANULARITY_PARAM, granularity.toString());
    }//from   ww w.jav a 2  s . c om
    if (endDate == null) {
        builder.addParameter(COUNT_PARAM, Integer.toString(count));
    }
    if (startDate != null) {
        builder.addParameter(START_PARAM, toRfc3339Date(startDate));
    }
    if (endDate != null) {
        builder.addParameter(END_PARAM, toRfc3339Date(endDate));
    }
    return builder.build();
}

From source file:com.sonicle.webtop.core.app.DocEditorManager.java

private URI generateUrl(String loopbackUrl, String domainPubName, String sessionId, String editingId)
        throws URISyntaxException {
    URIBuilder builder = new URIBuilder(loopbackUrl);
    URIUtils.appendPath(builder, URIUtils.concatPaths(DocEditor.URL, domainPubName, DocEditor.DOWNLOAD_PATH));
    if (!StringUtils.isBlank(sessionId))
        builder.addParameter(DocEditor.SESSION_ID_PARAM, sessionId);
    builder.addParameter(DocEditor.EDITING_ID_PARAM, editingId);
    return builder.build();
}

From source file:com.collective.celos.CelosClient.java

public WorkflowStatus getWorkflowStatus(WorkflowID workflowID, ScheduledTime startTime, ScheduledTime endTime)
        throws Exception {

    URIBuilder uriBuilder = new URIBuilder(address);
    uriBuilder.setPath(uriBuilder.getPath() + WORKFLOW_SLOTS_PATH);
    if (endTime != null) {
        uriBuilder.addParameter(END_TIME_PARAM, timeFormatter.formatPretty(endTime));
    }//from  w w w .  j  a v  a 2s.  c  o m
    if (startTime != null) {
        uriBuilder.addParameter(START_TIME_PARAM, timeFormatter.formatPretty(startTime));
    }
    uriBuilder.addParameter(ID_PARAM, workflowID.toString());
    URI uri = uriBuilder.build();

    HttpGet workflowListGet = new HttpGet(uri);
    HttpResponse getResponse = execute(workflowListGet);
    InputStream content = getResponse.getEntity().getContent();
    return parseWorkflowStatus(workflowID, content);
}

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

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

        if (queryParams != null) {
            // Query params are optional. In the case of a redirect the url will contain
            // all the params.
            for (Pair<String, String> queryParam : queryParams) {
                fileUri.addParameter(queryParam.getFirst(), queryParam.getSecond());
            }
        }

        HttpDelete httpDel = new HttpDelete(fileUri.build());
        CloseableHttpResponse response = clientImpl.execute(httpDel);
        return response.getStatusLine().getStatusCode();

    } catch (URISyntaxException | IOException ex) {
        throw new RuntimeException("Apache method deleteQuery: " + ex.getMessage());
    }
}