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:com.activiti.service.activiti.AppService.java

public JsonNode getProcessDefinitionsForDeploymentId(ServerConfig serverConfig, String deploymentId) {
    URIBuilder builder = clientUtil.createUriBuilder(PROCESS_DEFINITIONS_URL);
    builder.addParameter("deploymentId", deploymentId);
    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder));
    return clientUtil.executeRequest(get, serverConfig);
}

From source file:org.apache.ambari.server.controller.metrics.timeline.AMSReportPropertyProviderTest.java

@Test
public void testPopulateResources() throws Exception {
    TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH);
    injectCacheEntryFactoryWithStreamProvider(streamProvider);
    TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
    ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);

    Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper
            .getMetricPropertyIds(Resource.Type.Cluster);

    AMSReportPropertyProvider propertyProvider = new AMSReportPropertyProvider(propertyIds, streamProvider,
            sslConfiguration, cacheProvider, metricHostProvider, CLUSTER_NAME_PROPERTY_ID);

    String propertyId = PropertyHelper.getPropertyId("metrics/cpu", "User");
    Resource resource = new ResourceImpl(Resource.Type.Cluster);
    resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
    Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
    temporalInfoMap.put(propertyId, new TemporalInfoImpl(1416445244800L, 1416448936474L, 1L));
    Request request = PropertyHelper.getReadRequest(Collections.singleton(propertyId), temporalInfoMap);
    Set<Resource> resources = propertyProvider.populateResources(Collections.singleton(resource), request,
            null);//from   www  .jav  a  2s.c  o  m
    Assert.assertEquals(1, resources.size());
    Resource res = resources.iterator().next();
    Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next());
    Assert.assertNotNull(properties);
    URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false);
    uriBuilder.addParameter("metricNames", "cpu_user");
    uriBuilder.addParameter("appId", "HOST");
    uriBuilder.addParameter("startTime", "1416445244800");
    uriBuilder.addParameter("endTime", "1416448936474");
    Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec());
    Number[][] val = (Number[][]) res.getPropertyValue("metrics/cpu/User");
    Assert.assertEquals(111, val.length);
}

From source file:org.apache.ambari.server.controller.metrics.timeline.AMSReportPropertyProviderTest.java

@Test
public void testPopulateResourceWithAggregateFunction() throws Exception {
    TestStreamProvider streamProvider = new TestStreamProvider(AGGREGATE_CLUSTER_METRICS_FILE_PATH);
    injectCacheEntryFactoryWithStreamProvider(streamProvider);
    TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
    ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);

    Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper
            .getMetricPropertyIds(Resource.Type.Cluster);

    AMSReportPropertyProvider propertyProvider = new AMSReportPropertyProvider(propertyIds, streamProvider,
            sslConfiguration, cacheProvider, metricHostProvider, CLUSTER_NAME_PROPERTY_ID);

    String propertyId = PropertyHelper.getPropertyId("metrics/cpu", "User._sum");
    Resource resource = new ResourceImpl(Resource.Type.Cluster);
    resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
    Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
    temporalInfoMap.put(propertyId, new TemporalInfoImpl(1432033257812L, 1432035927922L, 1L));
    Request request = PropertyHelper.getReadRequest(Collections.singleton(propertyId), temporalInfoMap);
    Set<Resource> resources = propertyProvider.populateResources(Collections.singleton(resource), request,
            null);//from   w  w w . j  av  a2s  . c om
    Assert.assertEquals(1, resources.size());
    Resource res = resources.iterator().next();
    Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next());
    Assert.assertNotNull(properties);
    URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false);
    uriBuilder.addParameter("metricNames", "cpu_user._sum");
    uriBuilder.addParameter("appId", "HOST");
    uriBuilder.addParameter("startTime", "1432033257812");
    uriBuilder.addParameter("endTime", "1432035927922");
    Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec());
    Number[][] val = (Number[][]) res.getPropertyValue("metrics/cpu/User._sum");
    Assert.assertEquals(90, val.length);
}

From source file:com.google.appengine.tck.blobstore.support.FileUploader.java

private String getUploadUrl(URL url, Method method, Map<String, String> params)
        throws URISyntaxException, IOException {
    URIBuilder builder = new URIBuilder(url.toURI());
    for (Map.Entry<String, String> entry : params.entrySet()) {
        builder.addParameter(entry.getKey(), entry.getValue());
    }//from  w w  w . ja  va 2  s . c om
    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpUriRequest request;
        switch (method) {
        case GET:
            request = new HttpGet(builder.build());
            break;
        case POST:
            request = new HttpPost(builder.build());
            break;
        default:
            throw new IllegalArgumentException(String.format("No such method: %s", method));
        }
        HttpResponse response = httpClient.execute(request);
        return EntityUtils.toString(response.getEntity()).trim();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:com.opensearchserver.client.v1.WebCrawlerApi1.java

/**
 * Enable or disable pattern inclusion and exclusion
 * //from  w  w w  .  j a v a2s . c  o  m
 * @param indexName
 *            The name of the index
 * @param inclusionStatus
 *            Enable or disable inclusion list
 * @param exclusionStatus
 *            Enable or disable inclusion list
 * @return the result of the call
 * @throws IOException
 *             if any IO error occurs
 * @throws URISyntaxException
 *             if the URI is not valid
 */
public CommonResult setPatternStatus(String indexName, Boolean inclusionStatus, Boolean exclusionStatus)
        throws IOException, URISyntaxException {
    URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/crawler/web/patterns/status");
    if (inclusionStatus != null)
        uriBuilder.addParameter("inclusion", inclusionStatus.toString());
    if (exclusionStatus != null)
        uriBuilder.addParameter("exclusion", exclusionStatus.toString());
    Request request = Request.Put(uriBuilder.build());
    return client.execute(request, null, null, CommonResult.class, 200);
}

From source file:com.katsu.springframework.security.authentication.dni.HttpDniAuthenticationDao.java

private Collection<? extends GrantedAuthority> doLogin(URL url, String username, String password, String dni)
        throws Exception {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = null;// w ww .ja  v a  2  s .c  o m
    HttpResponse httpResponse = null;
    HttpEntity entity = null;
    try {
        httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY),
                new UsernamePasswordCredentials(username, password));
        URIBuilder urib = new URIBuilder(url.toURI().toASCIIString());
        urib.addParameter("dni", dni);
        httpget = new HttpGet(urib.build());
        httpResponse = httpclient.execute(httpget);
        entity = httpResponse.getEntity();

        if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            logger.trace(httpResponse.getStatusLine().toString());
            String body = new java.util.Scanner(new InputStreamReader(entity.getContent())).useDelimiter("\\A")
                    .next();
            List<? extends GrantedAuthority> roles = json.deserialize(body, new TypeToken<List<Role>>() {
            }.getType());
            if (roles != null && roles.size() > 0 && roles.get(0).getAuthority() == null) {
                roles = json.deserialize(body, new TypeToken<List<Role1>>() {
                }.getType());
            }
            return roles;
        } else {
            throw new Exception(httpResponse.getStatusLine().getStatusCode() + " Http code response.");
        }
    } catch (Exception e) {
        if (entity != null) {
            logger.error(log(entity.getContent()), e);
        } else {
            logger.error(e);
        }
        throw e;
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

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

public JsonNode getVariables(ServerConfig serverConfig, String taskId) {
    URIBuilder builder = clientUtil.createUriBuilder(HISTORIC_VARIABLE_INSTANCE_LIST_URL);
    builder.addParameter("taskId", taskId);
    builder.addParameter("size", DEFAULT_VARIABLE_RESULT_SIZE);
    builder.addParameter("sort", "variableName");

    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder));
    return clientUtil.executeRequest(get, serverConfig);
}

From source file:org.deegree.securityproxy.sessionid.WassSessionIdRetriever.java

private URI createRequest(String userName, String password) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(baseUrl);
    uriBuilder.addParameter("SERVICE", "WAS");
    uriBuilder.addParameter("REQUEST", "GetSession");
    uriBuilder.addParameter("VERSION", "1.0.0");
    uriBuilder.addParameter("AUTHMETHOD", "urn:x-gdi-nrw:authnMethod:1.0:password");
    uriBuilder.addParameter("CREDENTIALS", userName + "," + password);
    return uriBuilder.build();
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationCopy.java

private HttpRequestBase onExecute(final String preparationId, final String destination, final String newName) {
    try {/* w w w  .  j a v  a2  s.c o  m*/
        URIBuilder uriBuilder = new URIBuilder(
                preparationServiceUrl + "/preparations/" + preparationId + "/copy");
        if (StringUtils.isNotBlank(destination)) {
            uriBuilder.addParameter("destination", destination);
        }
        if (StringUtils.isNotBlank(newName)) {
            uriBuilder.addParameter("name", newName);
        }
        return new HttpPost(uriBuilder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}