List of usage examples for org.apache.http.client.utils URLEncodedUtils format
public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:com.lexicalintelligence.admin.add.AddEntryRequest.java
public AddResponse execute() { List<BasicNameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("name", entry.getName())); params.add(new BasicNameValuePair("synonym", entry.getSynonym())); params.add(new BasicNameValuePair("matchWordOrder", Boolean.toString(entry.isOrderSensitive()))); params.add(new BasicNameValuePair("caseSensitive", Boolean.toString(entry.isCaseSensitive()))); params.add(new BasicNameValuePair("matchStopwords", Boolean.toString(entry.isMatchStopwords()))); params.add(new BasicNameValuePair("matchPunctuation", Boolean.toString(entry.isMatchPunctuation()))); params.add(new BasicNameValuePair("stem", Boolean.toString(entry.isStemmed()))); AddResponse addResponse;/*w w w.j a va 2s. c om*/ Reader reader = null; try { HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath() + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); addResponse = new AddResponse(Boolean.valueOf(IOUtils.toString(reader))); } catch (Exception e) { addResponse = new AddResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { log.error(e); } } return addResponse; }
From source file:co.tuzza.clicksend4j.http.HttpClientUtilsTest.java
/** * Test of getHttpClient method, of class HttpClientUtils. *///from w w w . j ava 2 s .c o m @Test public void testGetHttpClient() throws ProtocolException, UnsupportedEncodingException, IOException { System.out.println("getHttpClient"); HttpClientUtils instance = new HttpClientUtils(10000, 10000); HttpClient expResult = null; HttpClient httpClient = instance.getHttpClient(); // https://api.clicksend.com/rest/v2/send.json?method=rest&message=This%20is%20the%20message&to=%2B8611111111111%2C%2B61411111111%20 String loginPassword = "tuzzmaniandevil:5C148EA8-D97B-B5F8-1A3F-1BE0658F4DF5"; String auth = Base64.encodeBase64String(loginPassword.getBytes()); HttpUriRequest method; List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("method", "rest")); params.add(new BasicNameValuePair("to", "+61411111111")); params.add(new BasicNameValuePair("message", "This is a test message")); HttpPost httpPost = new HttpPost("https://api.clicksend.com/rest/v2/send.json"); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); httpPost.setHeader("Authorization", "Basic " + auth); method = httpPost; String url = "https://api.clicksend.com/rest/v2/send.json" + "?" + URLEncodedUtils.format(params, "utf-8"); HttpResponse httpResponse = httpClient.execute(method); int status = httpResponse.getStatusLine().getStatusCode(); String response = new BasicResponseHandler().handleResponse(httpResponse); }
From source file:com.frapim.windwatch.Http.java
/** * Making service call/* www .j av a 2 s.co m*/ * @url - url to make request * @method - http request method * @params - http request params * */ public String request(String url, int method, List<NameValuePair> params) { try { // http client DefaultHttpClient httpClient = new DefaultHttpClient(); HttpEntity httpEntity = null; HttpResponse httpResponse = null; // Checking http request method type if (method == POST) { HttpPost httpPost = new HttpPost(url); // adding post params if (params != null) { httpPost.setEntity(new UrlEncodedFormEntity(params)); } httpResponse = httpClient.execute(httpPost); } else if (method == GET) { // appending params to url if (params != null) { String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; } HttpGet httpGet = new HttpGet(url); httpResponse = httpClient.execute(httpGet); } httpEntity = httpResponse.getEntity(); response = EntityUtils.toString(httpEntity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return response; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.commontools.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try {// w w w .ja v a2 s .c o m // check for request method if (method == "POST") { // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data: " + e.toString()); Log.e("JSON Parser", "Error parsing data; source: " + json); } // return JSON String return jObj; }
From source file:net.modelbased.proasense.storage.reader.StorageReaderMongoServiceRestBenchmark.java
private HttpGet createGetRequest(String serviceURL, LinkedList<NameValuePair> params) { String queryString = URLEncodedUtils.format(params, "utf-8"); StringBuilder requestUrl = new StringBuilder(serviceURL); requestUrl.append("?"); requestUrl.append(queryString);/*from ww w . ja v a 2s . co m*/ return new HttpGet(requestUrl.toString()); }
From source file:org.onsteroids.eve.api.provider.img.DefaultCharacterPortraitApi.java
@Override public CharacterPortrait getCharacterPortrait(long characterId, PortraitSize size) throws ApiException { HttpClient httpClient = httpClientProvider.get(); List<NameValuePair> qparams = Lists.newArrayList(); qparams.add(new BasicNameValuePair("c", Long.toString(characterId))); qparams.add(new BasicNameValuePair("s", Integer.toString(size.getSize()))); final URI requestURI; try {/*from w ww .ja v a 2 s. c o m*/ requestURI = URIUtils.createURI(serverUri.getScheme(), serverUri.getHost(), serverUri.getPort(), serverUri.getPath(), URLEncodedUtils.format(qparams, "UTF-8"), null); } catch (URISyntaxException e) { throw new InternalApiException(e); } LOG.trace("Resulting URI: {}", requestURI); final HttpPost postRequest = new HttpPost(requestURI); // make the real call LOG.trace("Fetching result from {}...", serverUri); final HttpResponse response; try { response = httpClient.execute(postRequest); } catch (IOException e) { throw new InternalApiException(e); } if (!FORMAT.equals(response.getEntity().getContentType().getValue())) { throw new InternalApiException( "Failed to fetch portrait [" + response.getEntity().getContentType().getValue() + "]."); } try { return new DefaultCharacterPortrait(response); } catch (IOException e) { throw new InternalApiException(e); } }
From source file:org.mule.modules.valomnia.core.ConnectorConfig.java
public static String encodage(final List<CustomNameValuePair> parameters) { return URLEncodedUtils.format(parameters, "ISO-8859-1"); }
From source file:org.wso2.cep.ui.integration.test.login.DataSourcesTestCase.java
@Test(groups = "wso2.cep", description = "Verifying XSS Vulnerability in event data sources - description field") public void testXSSVenerabilityDescriptionField() throws Exception { boolean isVulnerable = false; // Login/*from www . jav a 2s.c o m*/ driver.get(getLoginURL()); driver.findElement(By.id("txtUserName")).clear(); driver.findElement(By.id("txtUserName")) .sendKeys(cepServer.getContextTenant().getContextUser().getUserName()); driver.findElement(By.id("txtPassword")).clear(); driver.findElement(By.id("txtPassword")) .sendKeys(cepServer.getContextTenant().getContextUser().getPassword()); driver.findElement(By.cssSelector("input.button")).click(); // Sending request to even-tracer admin service String url = backendURL.substring(0, 22) + "/carbon/ndatasource/newdatasource.jsp?"; List<NameValuePair> params = new ArrayList<>(); params.add( new BasicNameValuePair("description", "RiskScoringDB\"><script>alert(1)</script><example attr=\"")); params.add(new BasicNameValuePair("edit", "true")); url += URLEncodedUtils.format(params, "UTF-8"); driver.get(url); try { // Alert appears if vulnerable to XSS attack. Alert alert = driver.switchTo().alert(); alert.accept(); isVulnerable = true; } catch (NoAlertPresentException e) { // XSS vulnerability is not there } Assert.assertFalse(isVulnerable); driver.close(); }
From source file:com.example.pyrkesa.shwc.JSONParser.java
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try {//from ww w.j a v a2s .c o m // check for request method if (method == "POST") { // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } else if (method == "GET") { // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; }
From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.NoAuthSimpleHttpClient.java
@Override public <T> T doGet(String url, List<Entry<String, String>> queryStringParameters, ResponseHandler<T> handler) throws IOException { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); for (Entry<String, String> entry : queryStringParameters) { parameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); }//from w w w . j a v a2 s . co m return sendRequest(new HttpGet(url + '?' + URLEncodedUtils.format(parameters, "UTF-8")), handler); }