List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
From source file:com.gsma.mobileconnect.impl.ParseDiscoveryRedirectTest.java
@Test public void parseDiscoveryRedirect_withUnexpectedMccMnc_shouldReturnEmptyDetails() throws URISyntaxException { // GIVEN//from ww w . j a v a 2s .c o m URIBuilder builder = new URIBuilder("http://localhost/redirect"); builder.addParameter(MCC_MNC_PARAMETER, "random-string"); IDiscovery discovery = Factory.getDiscovery(null, null); CaptureParsedDiscoveryRedirect captureParsedDiscoveryRedirect = new CaptureParsedDiscoveryRedirect(); // WHEN discovery.parseDiscoveryRedirect(builder.build().toString(), captureParsedDiscoveryRedirect); // THEN ParsedDiscoveryRedirect parsedDiscoveryRedirect = captureParsedDiscoveryRedirect .getParsedDiscoveryRedirect(); assertNull(parsedDiscoveryRedirect.getSelectedMCC()); assertNull(parsedDiscoveryRedirect.getSelectedMNC()); assertNull(parsedDiscoveryRedirect.getEncryptedMSISDN()); assertFalse(parsedDiscoveryRedirect.hasMCCAndMNC()); }
From source file:com.gsma.mobileconnect.impl.ParseDiscoveryRedirectTest.java
@Test public void parseDiscoveryRedirect_withBlankMccMnc_shouldReturnEmptyDetails() throws URISyntaxException { // GIVEN// w w w. jav a2s . co m URIBuilder builder = new URIBuilder("http://localhost/redirect"); builder.addParameter(MCC_MNC_PARAMETER, ""); IDiscovery discovery = Factory.getDiscovery(null, null); CaptureParsedDiscoveryRedirect captureParsedDiscoveryRedirect = new CaptureParsedDiscoveryRedirect(); // WHEN discovery.parseDiscoveryRedirect(builder.build().toString(), captureParsedDiscoveryRedirect); // THEN ParsedDiscoveryRedirect parsedDiscoveryRedirect = captureParsedDiscoveryRedirect .getParsedDiscoveryRedirect(); assertNull(parsedDiscoveryRedirect.getSelectedMCC()); assertNull(parsedDiscoveryRedirect.getSelectedMNC()); assertNull(parsedDiscoveryRedirect.getEncryptedMSISDN()); assertFalse(parsedDiscoveryRedirect.hasMCCAndMNC()); }
From source file:it.txt.ens.core.impl.BasicENSResource.java
/** * //from w w w . j av a 2 s. c om * @param host * @param path * @param namespace * @param pattern * @throws IllegalArgumentException if at least one parameter is <code>null</code> or an empty string. * @throws URIBuildingException if an error occurs while building the URI */ /*private*/ BasicENSResource(String host, String path, String namespace, String pattern) throws IllegalArgumentException, URIBuildingException { if (host == null) throw new IllegalArgumentException("The host cannot be null"); if (host.length() == 0) throw new IllegalArgumentException("The host cannot be an empty string"); if (path == null) throw new IllegalArgumentException("The path cannot be null"); if (path.length() == 0) throw new IllegalArgumentException("The path cannot be an empty string"); if (namespace == null) throw new IllegalArgumentException("The namespace cannot be null"); if (namespace.length() == 0) throw new IllegalArgumentException("The namespace cannot be an empty string"); if (pattern == null) throw new IllegalArgumentException("The pattern cannot be null"); if (pattern.length() == 0) throw new IllegalArgumentException("The pattern cannot be an empty string"); this.host = host; this.namespace = namespace; if (path.startsWith(SLASH)) this.path = path; else this.path = SLASH + path; this.pattern = pattern; URIBuilder uriBuilder = new URIBuilder(); uriBuilder.addParameter(NAMESPACE_PARAMETER_NAME, this.namespace); uriBuilder.addParameter(PATTERN_PARAMETER_NAME, this.pattern); uriBuilder.setHost(this.host); uriBuilder.setPath(this.path); uriBuilder.setScheme(URI_SCHEME); try { this.uri = uriBuilder.build(); } catch (URISyntaxException e) { throw new URIBuildingException("getURI.URISyntaxException.log", e); } }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationMove.java
private HttpRequestBase onExecute(String id, String folder, String destination, String newName) { try {/*from w w w. j a v a2 s . c om*/ URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/" + id + "/move"); if (StringUtils.isNotBlank(folder)) { uriBuilder.addParameter("folder", folder); } if (StringUtils.isNotBlank(destination)) { uriBuilder.addParameter("destination", destination); } if (StringUtils.isNotBlank(newName)) { uriBuilder.addParameter("newName", newName); } return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:com.flipkart.aesop.serializer.batch.reader.UserInfoServiceReader.java
/** * Returns a number of {@link UserInfo} instances looked up from a service end-point. * Note : The end-point and parameters used here are very specific to this sample. Also the code is mostly for testing and production * ready (no Http connection pools etc.) * @see org.trpr.platform.batch.spi.spring.reader.BatchItemStreamReader#batchRead(org.springframework.batch.item.ExecutionContext) *///from w w w. j av a 2 s .c o m public UserInfo[] batchRead(ExecutionContext context) throws Exception, UnexpectedInputException, ParseException { if (!hasRun) { objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); for (int i = 0; i < PHONE_NUMBERS.length; i++) { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet executionGet = new HttpGet(SERVICE_URL); URIBuilder uriBuilder = new URIBuilder(executionGet.getURI()); uriBuilder.addParameter("primary_phone", PHONE_NUMBERS[i]); uriBuilder.addParameter("require", "{\"preferences\":true,\"addresses\":true}"); ((HttpRequestBase) executionGet).setURI(uriBuilder.build()); HttpResponse httpResponse = httpclient.execute(executionGet); String response = new String(EntityUtils.toByteArray(httpResponse.getEntity())); SearchResult searchResult = objectMapper.readValue(response, SearchResult.class); results[i] = searchResult.results[0]; // we take only the first result } hasRun = true; } else { if (modIndex < 0) { return null; } System.out.println("Modifiying response object at index : " + modIndex); results[modIndex].setFirst_name("Regu " + modIndex); results[modIndex].setLast_name("B " + modIndex); results[modIndex].setPrimary_email("regunathb@gmail.com" + modIndex); results[modIndex].setPrimary_phone("9886693892" + modIndex); if (results[modIndex].getPreferences() != null && results[modIndex].getPreferences().size() > 0) { Iterator<String> it = results[modIndex].getPreferences().keySet().iterator(); while (it.hasNext()) { String key = it.next(); UserPreferencesInfo upi = results[modIndex].getPreferences().get(key); Map<String, Object> values = new HashMap<String, Object>(); values.put("communication", "email"); values.put("address", "home"); upi.setValue(values); } } modIndex -= 1; } return results; }
From source file:ca.nrc.cadc.search.PackageServlet.java
/** * Handle a GET request with the given Registry client to perform the lookup. * * @param request The HTTP Request. * @param response The HTTP Response. * @param registryClient The RegistryClient to do lookups. * @throws IOException Any request access problems. *//*from w w w .j a v a2s . c o m*/ void get(final HttpServletRequest request, final HttpServletResponse response, final RegistryClient registryClient) throws IOException { // TODO: prior to version 2.5.0, this servlet supported multiple IDs. // TODO: Consider how this might be supported in future. final String[] idValues = request.getParameterValues("ID"); if (idValues.length > 1) { throw new UnsupportedOperationException("Multiple IDs in package lookup."); } else { final String IDValue = idValues[0]; if (IDValue.length() > 0) { try { final PublisherID publisherID = new PublisherID(URI.create(IDValue)); final URL serviceURL = registryClient.getServiceURL(publisherID.getResourceID(), Standards.PKG_10, AuthMethod.COOKIE); final URIBuilder builder = new URIBuilder(serviceURL.toURI()); builder.addParameter("ID", IDValue); response.sendRedirect(builder.build().toURL().toExternalForm()); } catch (URISyntaxException e) { throw new IOException(String.format("Service URL from %s is invalid.", IDValue), e); } } else { throw new UnsupportedOperationException("Invalid ID in package lookup."); } } }
From source file:com.activiti.service.activiti.AppService.java
public JsonNode getFormsForAppDeploymentId(ServerConfig serverConfig, String appDeploymentId) { URIBuilder builder = clientUtil.createUriBuilder(FORMS_URL); builder.addParameter("appDeploymentId", appDeploymentId); HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder)); return clientUtil.executeRequest(get, serverConfig); }
From source file:com.epam.ngb.cli.manager.command.handler.http.GeneAddingHandler.java
@Override public int runCommand() { try {//from w ww . j a v a 2s .c o m String url = serverParameters.getServerUrl() + getRequestUrl(); URIBuilder builder = new URIBuilder(String.format(url, referenceId)); if (geneFileId != null) { builder.addParameter("geneFileId", String.valueOf(geneFileId)); } HttpPut put = new HttpPut(builder.build()); setDefaultHeader(put); if (isSecure()) { addAuthorizationToRequest(put); } String result = RequestManager.executeRequest(put); checkAndPrintRegistrationResult(result, printJson, printTable); } catch (URISyntaxException e) { throw new ApplicationException(e.getMessage(), e); } return 0; }
From source file:com.singularity.ee.agent.systemagent.monitors.KeynoteMonitor.java
public URI getGraphDataURI(List<Integer> slotIdList) throws URISyntaxException { URIBuilder uriBuilder = getURIBuilder("getgraphdata"); uriBuilder.addParameter("slotidlist", StringUtils.join(slotIdList, ",")); uriBuilder.addParameter("bucket", Integer.toString(bucketSize)); uriBuilder.addParameter("timemode", "relative"); uriBuilder.addParameter("relativehours", "14400"); uriBuilder.addParameter("timezone", "UCT"); return uriBuilder.build(); }
From source file:com.google.appengine.tck.blobstore.BlobstoreServeTest.java
private void doTest(HttpClient client, URI uri, Set<Header> headers, Map<String, String> params, String expected) throws Exception { URIBuilder builder = new URIBuilder(uri); if (params != null) { for (Map.Entry<String, String> entry : params.entrySet()) { builder.addParameter(entry.getKey(), entry.getValue()); }/*from w w w. ja v a 2 s . c o m*/ } HttpGet get = new HttpGet(builder.build()); if (headers != null) { for (Header h : headers) { get.addHeader(h); } } HttpResponse response = client.execute(get); Assert.assertEquals(expected, EntityUtils.toString(response.getEntity())); }