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.flowable.ui.admin.service.engine.FlowableClientService.java

public void addParameterToBuilder(String name, JsonNode bodyNode, URIBuilder builder) {
    JsonNode nameNode = bodyNode.get(name);
    if (nameNode != null && !nameNode.isNull()) {
        builder.addParameter(name, nameNode.asText());
        ((ObjectNode) bodyNode).remove(name);
    }//from   w w  w  .j  ava2 s.c o  m
}

From source file:org.flowable.ui.admin.service.engine.FormDeploymentService.java

public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) {

    URIBuilder builder = null;
    try {// w  w  w.  j a v  a2 s.c o  m
        builder = new URIBuilder("form-repository/deployments");
    } catch (Exception e) {
        LOGGER.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:org.talend.components.datastewardship.connection.TdsConnection.java

/**
 * Executes Http Get request//from   ww  w .  ja  v a 2 s  .  c  o  m
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param parameters http query parameters
 * @return response result
 * @throws IOException
 */
public String get(String resource, Map<String, Object> parameters) throws IOException {
    try {
        URIBuilder builder = new URIBuilder(hostPort + resource);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue().toString());
        }
        URI uri = builder.build();
        Request get = Request.Get(uri).addHeader(authorization);
        return executor.execute(get).returnContent().asString();
    } catch (URISyntaxException e) {
        LOG.debug("Wrong URI. {}", e.getMessage()); //$NON-NLS-1$
        throw new IOException("Wrong URI", e); //$NON-NLS-1$
    }
}

From source file:org.talend.components.datastewardship.connection.TdsConnection.java

/**
 * Executes Http Delete request/*from www.j a  v  a  2  s .c  o m*/
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param parameters http query parameters
 * @return http status code
 * @throws IOException
 */
public int delete(String resource, Map<String, Object> parameters) throws IOException {
    try {
        URIBuilder builder = new URIBuilder(hostPort + resource);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue().toString());
        }
        URI uri = builder.build();
        Request delete = Request.Delete(uri).addHeader(authorization);
        return executor.execute(delete).returnResponse().getStatusLine().getStatusCode();
    } catch (URISyntaxException e) {
        LOG.debug("Wrong URI. {}", e.getMessage()); //$NON-NLS-1$
        throw new IOException("Wrong URI", e); //$NON-NLS-1$
    }
}

From source file:org.talend.components.jira.connection.Rest.java

/**
 * Executes Http Get request/*from   w  ww  .  jav a2s  .  c  om*/
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param parameters http query parameters
 * @return response result
 * @throws IOException
 */
public String get(String resource, Map<String, Object> parameters) throws IOException {
    try {
        URIBuilder builder = new URIBuilder(hostPort + resource);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue().toString());
        }
        URI uri = builder.build();
        Request get = Request.Get(uri);
        for (Header header : headers) {
            get.addHeader(header);
        }
        executor.clearCookies();
        return executor.execute(get).returnContent().asString();
    } catch (URISyntaxException e) {
        LOG.debug("Wrong URI. {}", e.getMessage());
        throw new IOException("Wrong URI", e);
    }
}

From source file:org.talend.components.jira.connection.Rest.java

/**
 * Executes Http Delete request//  ww  w.jav a2 s .c  o  m
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param parameters http query parameters
 * @return http status code
 * @throws IOException
 */
public int delete(String resource, Map<String, Object> parameters) throws IOException {
    try {
        URIBuilder builder = new URIBuilder(hostPort + resource);
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            builder.addParameter(entry.getKey(), entry.getValue().toString());
        }
        URI uri = builder.build();
        Request delete = Request.Delete(uri);
        for (Header header : headers) {
            delete.addHeader(header);
        }
        executor.clearCookies();
        return executor.execute(delete).returnResponse().getStatusLine().getStatusCode();
    } catch (URISyntaxException e) {
        LOG.debug("Wrong URI. {}", e.getMessage());
        throw new IOException("Wrong URI", e);
    }
}

From source file:org.talend.dataprep.api.service.command.folder.FolderChildrenList.java

private HttpRequestBase onExecute(final String parentId, final String sort, final String order) {
    try {/*from w w  w  .  j ava  2s . co m*/
        final URIBuilder uriBuilder = new URIBuilder(
                preparationServiceUrl + "/folders/" + parentId + "/children");

        if (StringUtils.isNotBlank(sort)) {
            uriBuilder.addParameter("sort", sort);
        }
        if (StringUtils.isNotBlank(order)) {
            uriBuilder.addParameter("order", order);
        }

        return new HttpGet(uriBuilder.build());

    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public void setTableSchema(int tenantId, String username, String tableName, AnalyticsSchema schema,
        boolean securityEnabled) throws AnalyticsServiceException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.SCHEMA_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.SET_SCHEMA_OPERATION)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled))
            .addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId))
            .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName);
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {/*from   w ww .ja v a  2  s.  c  o m*/
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpPost postMethod = new HttpPost(builder.build().toString());
        postMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        postMethod.setEntity(new ByteArrayEntity(GenericUtils.serializeObject(schema)));
        HttpResponse httpResponse = httpClient.execute(postMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to set the schema for the table - " + tableName
                    + ", schema - " + gson.toJson(schema) + " for tenant id : " + tenantId + ". " + response);
        } else {
            EntityUtils.consume(httpResponse.getEntity());
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public AnalyticsSchema getTableSchema(int tenantId, String username, String tableName, boolean securityEnabled)
        throws AnalyticsServiceException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.SCHEMA_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.GET_SCHEMA_OPERATION)
            .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {/*w  w  w  .j a  va 2s .co m*/
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            String response = getResponseString(httpResponse);
            throw new AnalyticsServiceException("Unable to get the schema for the table - " + tableName
                    + " for tenant id : " + tenantId + ". " + response);
        } else {
            Object analyticsSchemaObject = GenericUtils
                    .deserializeObject(httpResponse.getEntity().getContent());
            EntityUtils.consumeQuietly(httpResponse.getEntity());
            if (analyticsSchemaObject != null && analyticsSchemaObject instanceof AnalyticsSchema) {
                return (AnalyticsSchema) analyticsSchemaObject;
            } else {
                throw new AnalyticsServiceException(
                        getUnexpectedResponseReturnedErrorMsg("getting the table schema", tableName,
                                "analytics schema object ", analyticsSchemaObject));
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}

From source file:org.wso2.carbon.analytics.api.internal.client.AnalyticsAPIHttpClient.java

public boolean isTableExists(int tenantId, String username, String tableName, boolean securityEnabled)
        throws AnalyticsServiceException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(protocol).setHost(hostname).setPort(port)
            .setPath(AnalyticsAPIConstants.TABLE_PROCESSOR_SERVICE_URI)
            .addParameter(AnalyticsAPIConstants.OPERATION, AnalyticsAPIConstants.TABLE_EXISTS_OPERATION)
            .addParameter(AnalyticsAPIConstants.TABLE_NAME_PARAM, tableName)
            .addParameter(AnalyticsAPIConstants.ENABLE_SECURITY_PARAM, String.valueOf(securityEnabled));
    if (!securityEnabled) {
        builder.addParameter(AnalyticsAPIConstants.TENANT_ID_PARAM, String.valueOf(tenantId));
    } else {//from www  .ja  va 2  s  .c  om
        builder.addParameter(AnalyticsAPIConstants.USERNAME_PARAM, username);
    }
    try {
        HttpGet getMethod = new HttpGet(builder.build().toString());
        getMethod.addHeader(AnalyticsAPIConstants.SESSION_ID, sessionId);
        HttpResponse httpResponse = httpClient.execute(getMethod);
        String response = getResponseString(httpResponse);
        if (httpResponse.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) {
            throw new AnalyticsServiceException("Unable to check the existence for the table - " + tableName
                    + " for tenant id : " + tenantId + ". " + response);
        } else {
            if (response.startsWith(AnalyticsAPIConstants.TABLE_EXISTS)) {
                String[] reponseElements = response.split(AnalyticsAPIConstants.SEPARATOR);
                if (reponseElements.length == 2) {
                    return Boolean.parseBoolean(reponseElements[1]);
                } else {
                    throw new AnalyticsServiceException("Invalid response returned, cannot find table existence"
                            + " message. Response:" + response);
                }
            } else {
                throw new AnalyticsServiceException(
                        "Invalid response returned, table existence message not found!" + response);
            }
        }
    } catch (URISyntaxException e) {
        throw new AnalyticsServiceAuthenticationException("Malformed URL provided. " + e.getMessage(), e);
    } catch (IOException e) {
        throw new AnalyticsServiceAuthenticationException(
                "Error while connecting to the remote service. " + e.getMessage(), e);
    }
}