List of usage examples for org.apache.http.client.utils URIBuilder setParameter
public URIBuilder setParameter(final String param, final String value)
From source file:org.outermedia.solrfusion.adapter.solr.DefaultSolrAdapter.java
protected void buildHighlightHttpClientParams(Multimap<String> params, URIBuilder ub) { String doHighlighting = params.getFirst(HIGHLIGHT); if ("true".equals(doHighlighting)) { ub.setParameter(HL_ON_PARAMETER, "true"); addIfNotNull(ub, HL_SIMPLE_PRE_PARAMETER, params.getFirst(HIGHLIGHT_PRE)); addIfNotNull(ub, HL_SIMPLE_POST_PARAMETER, params.getFirst(HIGHLIGHT_POST)); addIfNotNull(ub, HL_FIELDS_PARAMETER, params.getFirst(HIGHLIGHT_FIELDS_TO_RETURN)); addIfNotNull(ub, HL_QUERY_PARAMETER, params.getFirst(HIGHLIGHT_QUERY)); }/*from ww w . j a va 2 s. c o m*/ }
From source file:webrequester.AbstractWebRequest.java
protected URI buildURI() { try {/*from w w w . ja v a 2 s .c o m*/ URIBuilder uriB = new URIBuilder(); uriB.setScheme(scheme).setHost(host); if (port > 0) { uriB.setPort(port); } uriB.setPath(path); for (NameValuePair pair : listParameters) { uriB.setParameter(pair.getName(), pair.getValue()); } return uriB.build(); } catch (URISyntaxException ex) { return null; } }
From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransport.java
/** * @see Transport#ping(PingRequest)/*from w ww. j a va 2 s .c o m*/ */ public PingResponse ping(PingRequest request) throws LaunchKeyException { log.trace("Beginning ping request"); PingResponse pingResponse; try { URIBuilder uriBuilder = new URIBuilder(getUrlForPath("/ping")); String dateStamp = request.getDateStamp(); if (dateStamp != null) { uriBuilder.setParameter("date_stamp", dateStamp); } HttpGet ping = new HttpGet(uriBuilder.build()); HttpResponse httpResponse = client.execute(ping); pingResponse = getTransportObjectFromResponse(PingResponse.class, httpResponse); } catch (LaunchKeyException e) { log.trace("Error encountered in response from LaunchKey engine", e); throw e; } catch (Exception e) { log.trace("Exception caught processing ping request", e); throw new LaunchKeyException("Exception caught processing ping request", e, 0); } log.trace("Completed ping request"); log.trace(pingResponse); return pingResponse; }
From source file:ching.icecreaming.action.EditAction.java
@Action(value = "edit", results = { @Result(name = "login", location = "edit.jsp"), @Result(name = "success", location = "view.jsp"), @Result(name = "error", location = "error.jsp") }) public String execute() throws Exception { URL url1 = null;/*from ww w .j av a 2s . co m*/ URI uri1 = null; HttpGet httpGet1 = null; DefaultHttpClient httpClient1 = new DefaultHttpClient(); HttpResponse httpResponse1 = null; int int1 = 0, int2 = 401; String[] array1 = null; String string1 = getText("Error") + " %d: %s", result1 = LOGIN; byte[] bytes1 = null; if (StringUtils.isBlank(timeZone1)) timeZone1 = portletPreferences.getValue("timeZone", TimeZone.getDefault().getID()); if (StringUtils.isNotBlank(sid) && StringUtils.isNotBlank(uid) && StringUtils.isNotBlank(pid)) { try { url1 = new URL(sid); URIBuilder uriBuilder = new URIBuilder(sid); uriBuilder.setParameter("j_username", uid); uriBuilder.setParameter("j_password", pid); uriBuilder.setPath(url1.getPath() + "/rest/login"); uri1 = uriBuilder.build(); httpGet1 = new HttpGet(uri1); httpResponse1 = httpClient1.execute(httpGet1); int2 = httpResponse1.getStatusLine().getStatusCode(); } catch (IOException exception1) { exception1.printStackTrace(); } catch (URISyntaxException exception1) { exception1.printStackTrace(); } finally { httpClient1.getConnectionManager().shutdown(); if (int2 == HttpStatus.SC_OK) { sid = new String(Base64.encodeBase64(sid.getBytes())); uid = new String(Base64.encodeBase64(uid.getBytes())); pid = new String(Base64.encodeBase64(pid.getBytes())); urlString = "/"; wsType = "folder"; array1 = new String[] { sid, uid, pid, StringUtils.defaultString(alias1) }; portletPreferences.setValue("urlString", urlString); portletPreferences.setValue("wsType", wsType); portletPreferences.setValue("timeZone", timeZone1); portletPreferences.setValues("server", array1); portletPreferences.store(); result1 = SUCCESS; } else { array1 = portletPreferences.getValues("server", null); if (array1 != null) if (ArrayUtils.isNotEmpty(array1)) { for (int1 = 0; int1 < array1.length; int1++) { switch (int1) { case 0: sid = array1[int1]; break; case 1: uid = array1[int1]; break; case 2: pid = array1[int1]; break; case 3: alias1 = array1[int1]; break; default: break; } } sid = new String(Base64.decodeBase64(sid.getBytes())); uid = new String(Base64.decodeBase64(uid.getBytes())); pid = new String(Base64.decodeBase64(pid.getBytes())); } addActionError(String.format(string1, int2, getText(Integer.toString(int2)))); } } } else { array1 = portletPreferences.getValues("server", null); if (StringUtils.isBlank(urlString) || StringUtils.isBlank(wsType)) { urlString = portletPreferences.getValue("urlString", "/"); wsType = portletPreferences.getValue("wsType", "folder"); } if (array1 != null) { if (ArrayUtils.isNotEmpty(array1)) { for (int1 = 0; int1 < array1.length; int1++) { switch (int1) { case 0: sid = array1[int1]; break; case 1: uid = array1[int1]; break; case 2: pid = array1[int1]; break; case 3: alias1 = array1[int1]; break; default: break; } } sid = new String(Base64.decodeBase64(sid.getBytes())); uid = new String(Base64.decodeBase64(uid.getBytes())); pid = new String(Base64.decodeBase64(pid.getBytes())); } } } return result1; }
From source file:com.grameenfoundation.ictchallenge.controllers.ConnectedAppREST.java
private JSONObject showFarmers(String instanceUrl, String accessToken) throws ServletException, IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(); //add key and value httpGet.addHeader("Authorization", "OAuth " + accessToken); try {//from w ww .j a v a2s .com URIBuilder builder = new URIBuilder(instanceUrl + "/services/data/v30.0/query"); //builder.setParameter("q", "SELECT Name, Id from Account LIMIT 100"); builder.setParameter("q", "SELECT Name__c,Date_Of_Birth__c,Land_size__c,Farmer_I_D__c,Picture__c from Farmer__c LIMIT 100"); httpGet.setURI(builder.build()); log.log(Level.INFO, "URl to salesforce {0}", builder.build().getPath()); CloseableHttpResponse closeableresponse = httpclient.execute(httpGet); System.out.println("Response Status line :" + closeableresponse.getStatusLine()); if (closeableresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Now lets use the standard java json classes to work with the // results try { // Do the needful with entity. HttpEntity entity = closeableresponse.getEntity(); InputStream rstream = entity.getContent(); JSONObject authResponse = new JSONObject(new JSONTokener(rstream)); log.log(Level.INFO, "Query response: {0}", authResponse.toString(2)); log.log(Level.INFO, "{0} record(s) returned\n\n", authResponse.getInt("totalSize")); return authResponse; } catch (JSONException e) { e.printStackTrace(); throw new ServletException(e); } } } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { httpclient.close(); } return null; }
From source file:com.grameenfoundation.ictchallenge.controllers.ConnectedAppREST.java
private JSONObject getFarmerById(String instanceUrl, String accessToken, String id) throws ServletException, IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(); //add key and value httpGet.addHeader("Authorization", "OAuth " + accessToken); try {/*from ww w. ja va2s. c o m*/ URIBuilder builder = new URIBuilder(instanceUrl + "/services/data/v30.0/query"); //builder.setParameter("q", "SELECT Name, Id from Account LIMIT 100"); builder.setParameter("q", "SELECT Name__c,Date_Of_Birth__c,Land_size__c,Farmer_I_D__c,Picture__c from Farmer__c " + " WHERE Farmer_I_D__c=" + "'" + id + "'"); httpGet.setURI(builder.build()); CloseableHttpResponse closeableresponse = httpclient.execute(httpGet); System.out.println("Response Status line :" + closeableresponse.getStatusLine()); if (closeableresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Now lets use the standard java json classes to work with the // results try { // Do the needful with entity. HttpEntity entity = closeableresponse.getEntity(); InputStream rstream = entity.getContent(); JSONObject authResponse = new JSONObject(new JSONTokener(rstream)); log.log(Level.INFO, "Query response: {0}", authResponse.toString(2)); log.log(Level.INFO, "{0} record(s) returned\n\n", authResponse.getInt("totalSize")); return authResponse; } catch (JSONException e) { e.printStackTrace(); } } } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ConnectedAppREST.class.getName()).log(Level.SEVERE, null, ex); } finally { httpclient.close(); } return null; }
From source file:org.squashtest.tm.plugin.testautomation.jenkins.internal.net.HttpRequestFactory.java
protected HttpPost newStartBuild(TestAutomationProject project, ParameterArray params) { TestAutomationServer server = project.getServer(); URIBuilder builder = uriBuilder(server); concatPath(builder, JOB_PATH + project.getJobName() + "/build"); String jsonParam = jsonParser.toJson(params); builder.setParameter("json", jsonParam); return new HttpPost(build(builder)); }
From source file:ph.com.globe.connect.Payment.java
/** * Build request url.//from www .j a v a 2s. c o m * * @param url target url * @param appId app id * @param appSecret app secret * @return String * @throws ApiException api exception */ protected String buildUrl(String url, String appId, String appSecret) throws ApiException { // try parsing url try { // initialize url builder URIBuilder builder = new URIBuilder(url); // set app id parameter builder.setParameter("app_id", appId); // set app secret parameter builder.setParameter("app_secret", appSecret); // build the url url = builder.build().toString(); return url; } catch (URISyntaxException e) { // throw exception throw new ApiException(e.getMessage()); } }
From source file:com.hp.octane.integrations.services.coverage.SonarServiceImpl.java
private InputStream getPageFromSonar(SonarBuildCoverageQueueItem queueItem, Integer page) { String sonarURL = queueItem.sonarURL; String projectKey = queueItem.projectKey; String token = queueItem.sonarToken; try {/*from w ww . ja va2s .c om*/ URIBuilder uriBuilder = new URIBuilder(sonarURL + COMPONENT_TREE_URI); uriBuilder.setParameter("metricKeys", "lines_to_cover,uncovered_lines") .setParameter("component", projectKey).setParameter("qualifiers", "FIL,TRK") .setParameter("ps", "500").setParameter("p", page.toString()); HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(uriBuilder.build()); setTokenInHttpRequest(request, token); HttpResponse httpResponse = httpClient.execute(request); return httpResponse.getEntity().getContent(); } catch (Exception e) { String errorMessage = "".concat("failed to get coverage data from sonar for project: ") .concat(projectKey); logger.error(errorMessage, e); throw new PermanentException(errorMessage, e); } }
From source file:ph.com.globe.connect.Payment.java
/** * Build request url./* w w w. java2 s . c o m*/ * * @param url target url * @return String * @throws ApiException api exception */ protected String buildUrl(String url) throws ApiException { // try parsing url try { // initialize url builder URIBuilder builder = new URIBuilder(url); // set access token parameter builder.setParameter("access_token", this.accessToken); // build the url url = builder.build().toString(); return url; } catch (URISyntaxException e) { // throw exception throw new ApiException(e.getMessage()); } }