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.controlj.addon.weather.util.HTTPHelper.java
private String encodeParams(Map<String, Object> params) { if (params == null) return null; List<NameValuePair> qparams = new ArrayList<NameValuePair>(); for (Map.Entry<String, Object> entry : params.entrySet()) qparams.add(new BasicNameValuePair(entry.getKey(), ObjectUtils.toString(entry.getValue()))); return URLEncodedUtils.format(qparams, "UTF-8"); }
From source file:com.antorofdev.util.Http.java
/** * Performs http GET petition to server. * * @param url URL to perform GET petition. * @param parameters Parameters to include in petition. * * @return Response from the server./*from w w w.ja v a 2s. c o m*/ * @throws IOException If the <tt>parameters</tt> have errors, connection timmed out, * socket timmed out or other error related with the connection occurs. */ public static HttpResponse get(String url, ArrayList<NameValuePair> parameters) throws IOException { HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 10000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 10000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient httpclient = new DefaultHttpClient(httpParameters); if (parameters != null) { String paramString = URLEncodedUtils.format(parameters, "utf-8"); url += paramString; } HttpGet httpget = new HttpGet(url); HttpResponse response = httpclient.execute(httpget); return response; }
From source file:com.devicehive.model.oauth.IdentityProviderUtils.java
public String executeGet(final HttpTransport transport, final List<NameValuePair> params, final String endpoint, final String providerName) { logger.debug("executeGet: endpoint {}, providerName {}", endpoint, providerName); try {/*from w w w . jav a 2 s . com*/ final HttpRequestFactory requestFactory = transport.createRequestFactory(); final String paramString = URLEncodedUtils.format(params, Charset.forName(UTF8)); final GenericUrl url = new GenericUrl(String.format("%s?%s", endpoint, paramString)); final HttpRequest request = requestFactory.buildGetRequest(url); return request.execute().parseAsString(); } catch (IOException e) { logger.error("Exception has been caught during Identity Provider GET request execution", e); throw new HiveException(Messages.IDENTITY_PROVIDER_API_REQUEST_ERROR, Response.Status.SERVICE_UNAVAILABLE.getStatusCode()); } }
From source file:org.wso2.identity.ui.integration.test.login.ISLoginTestCase.java
@Test(groups = "wso2.identity", description = "verify XSS vulnerability fix") public void testXSSVulnerability() throws Exception { boolean isVulnerable = false; String authEndpoint = backendURL.substring(0, 22) + "/authenticationendpoint/login.do?"; List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("client_id", "XXXXXXXX")); params.add(new BasicNameValuePair("commonAuthCallerPath", "/oauth2/authorize")); params.add(new BasicNameValuePair("forceAuth", "false")); params.add(new BasicNameValuePair("passiveAuth", "false")); params.add(new BasicNameValuePair("redirect_uri", "https://localhost/login")); params.add(new BasicNameValuePair("response_type", "code")); params.add(new BasicNameValuePair("scope", "openid")); params.add(new BasicNameValuePair("state", "XXXXXXXX")); params.add(new BasicNameValuePair("tenantDomain", "carbon.super")); params.add(new BasicNameValuePair("sessionDataKey", "XXXXXXXX")); params.add(new BasicNameValuePair("relyingParty", "XXXXXXXX")); params.add(new BasicNameValuePair("type", "oidc")); params.add(new BasicNameValuePair("sp", "mytestapp")); params.add(new BasicNameValuePair("isSaaSApp", "false")); params.add(new BasicNameValuePair("authenticators", "BasicAuthenticator:LOCAL\"></script>\"//'//" + "<svg onload=(function(){setTimeout(function(){$('body').prepend($('<div></div>')" + ".attr('id','vulnerable'))},2000)})()//")); driver = BrowserManager.getWebDriver(); driver.get(authEndpoint + URLEncodedUtils.format(params, "UTF-8")); WebDriverWait webDriverWait = new WebDriverWait(driver, 5); try {//from w ww.j av a 2s .c o m webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.id("vulnerable"))); // If not vulnerable, element with #vulnerable would not get injected // Therefore it'll throw an exception mentioning that. isVulnerable = true; } catch (Exception ignored) { } Assert.assertFalse(isVulnerable); driver.close(); }
From source file:me.vertretungsplan.parser.ESchoolParser.java
@Override public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException { if (!(scheduleData.getAuthenticationData() instanceof NoAuthenticationData) && (credential == null || !(credential instanceof PasswordCredential) || ((PasswordCredential) credential).getPassword() == null || ((PasswordCredential) credential).getPassword().isEmpty())) { throw new IOException("no login"); }/*from ww w . j av a 2 s. c o m*/ List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("wp", scheduleData.getData().getString(PARAM_ID))); nvps.add(new BasicNameValuePair("go", "vplan")); nvps.add(new BasicNameValuePair("content", "x14")); nvps.add(new BasicNameValuePair("sortby", "S")); String url = BASE_URL + "?" + URLEncodedUtils.format(nvps, "UTF-8"); Document doc = Jsoup.parse(httpGet(url, ENCODING)); if (doc.select("form[name=loginform]").size() > 0 && scheduleData.getAuthenticationData() instanceof PasswordAuthenticationData) { // Login required List<NameValuePair> formParams = new ArrayList<>(); formParams.add(new BasicNameValuePair("password", ((PasswordCredential) credential).getPassword())); formParams.add(new BasicNameValuePair("login", "")); doc = Jsoup.parse(httpPost(url, ENCODING, formParams)); if (doc.select("font[color=red]").text().contains("fehlgeschlagen")) { throw new CredentialInvalidException(); } } SubstitutionSchedule schedule = parseESchoolSchedule(doc); return schedule; }
From source file:io.mapzone.arena.share.content.ImagePngContentProvider.java
@Override public ImagePngContent get() { ImagePngContent content = new ImagePngContent(); StringJoiner layers = new StringJoiner(","); for (SelectionDescriptor selection : context.selectionDescriptors.get()) { layers.add(GeoServerUtils.simpleName(selection.layer.get().label.get())); // FIXME, if multilayers are working, remove this break!!! //break;/*from w w w . j a v a 2 s . c om*/ } Envelope bbox = context.boundingBox.get(); String extent = Joiner.on(",").join((int) bbox.getMinX(), (int) bbox.getMinY(), (int) bbox.getMaxX(), (int) bbox.getMaxY()); String imageUrl = ArenaPlugin.instance().config().getProxyUrl() + GeoServerStarter.ALIAS; List<NameValuePair> params = new ArrayList() { { add(nameValue("SERVICE", "WMS")); add(nameValue("VERSION", "1.3.0")); add(nameValue("REQUEST", "GetMap")); add(nameValue("FORMAT", "image/png")); add(nameValue("CRS", "EPSG:3857")); add(nameValue("BBOX", extent.toString())); add(nameValue("LAYERS", layers.toString())); } }; if (!StringUtils.isBlank(ArenaPlugin.instance().config().getServiceAuthToken())) { params.add(nameValue("authToken", ArenaPlugin.instance().config().getServiceAuthToken())); } content.imgWidth = context.displaySize.get().x; content.imgHeight = context.displaySize.get().y; content.previewWidth = 320; content.previewHeight = content.previewWidth * content.imgHeight / content.imgWidth; ArrayList previewParams = new ArrayList(params) { { add(nameValue("WIDTH", content.previewWidth)); add(nameValue("HEIGHT", content.previewHeight)); } }; content.previewResource = imageUrl + "?" + URLEncodedUtils.format(previewParams, "UTF-8"); ArrayList imgParams = new ArrayList(params) { { add(nameValue("WIDTH", content.imgWidth)); add(nameValue("HEIGHT", content.imgHeight)); } }; content.imgResource = imageUrl + "?" + URLEncodedUtils.format(imgParams, "UTF-8"); return content; }
From source file:helper.util.RESTClient.java
/** * Main method for server request. Depending on call status, the callback methods are * invoked./*from ww w. j av a 2 s .co m*/ * @param URI full address from which we need to get response. */ @Override protected Void doInBackground(URI... uris) { if (!networkAvailable()) { System.out.println("no network connection"); _handler.onFailure(FailStatus.NoNetworkConnection); return null; } HttpClient httpclient = new DefaultHttpClient(); final HttpParams httpParameters = httpclient.getParams(); int connectionTimeOutSec = 10; HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeOutSec * 1000); int socketTimeoutSec = 10; HttpConnectionParams.setSoTimeout(httpParameters, socketTimeoutSec * 1000); HttpRequestBase httpRequest = null; if (_methodType == "GET") { // check if we have any params if (_params != null) { String paramString = URLEncodedUtils.format(_params, "utf-8"); httpRequest = new HttpGet(uris[0] + "?" + paramString); Log.d("request", uris[0] + "?" + paramString); } else { httpRequest = new HttpGet(uris[0]); Log.d("request", uris[0].toString()); } } else { httpRequest = new HttpPost(uris[0]); if (_params != null) { Log.d("request", uris[0].toString()); addPostParameters(httpRequest); } } httpRequest.setHeader("Accept", "application/json"); httpRequest.setHeader("Content-Type", "application/json"); try { // start http request HttpResponse response = httpclient.execute(httpRequest); // get response string String responseData = EntityUtils.toString(response.getEntity(), HTTP.UTF_8); // determine response type(json array or object) Object json = null; try { json = new JSONTokener(responseData).nextValue(); _handler.onSuccess(json); } catch (JSONException e) { _handler.onFailure(FailStatus.JSONException); } } catch (ClientProtocolException e) { System.out.println("AsyncTask:GetUserDataThread:ClientProtocolException: " + e.getMessage()); _handler.onFailure(FailStatus.ClientProtocolException); } catch (IOException e) { System.out.println("AsyncTask:GetUserDataThread:IOException: " + e.getMessage()); _handler.onFailure(FailStatus.IOException); } return null; }
From source file:com.leclercb.taskunifier.gui.plugins.PluginLicense.java
private URI getCheckSerialUri() throws Exception { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("plugin", this.pluginId)); parameters.add(new BasicNameValuePair("email", this.email)); return URIUtils.createURI("http", "www.taskunifier.com", -1, "/plugins/paypal/checklicense.php", URLEncodedUtils.format(parameters, "UTF-8"), null); }
From source file:org.openbase.bco.ontology.lib.commun.trigger.OntologyRemoteImpl.java
private HttpEntity getHttpEntity(final String query) throws IOException { final List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("query", query)); final HttpClient httpclient = HttpClients.createDefault(); final HttpGet httpGet = new HttpGet( OntConfig.getOntologyDbUrl() + "sparql?" + URLEncodedUtils.format(params, "UTF-8")); final HttpEntity httpEntity = httpclient.execute(httpGet).getEntity(); if (httpEntity != null) { return httpEntity; } else {/*w ww . ja va 2 s . com*/ throw new IOException("Could not get query result, cause http entity is null."); } }
From source file:org.hawkular.alerter.prometheus.PrometheusQueryTest.java
@Ignore @Test/*w w w. j av a 2 s . co m*/ public void queryEncodedUrl() throws Exception { CloseableHttpClient client = HttpClients.createDefault(); StringBuffer url = new StringBuffer("http://localhost:9090"); url.append("/api/v1/query?"); BasicNameValuePair param = new BasicNameValuePair("query", "rate(http_requests_total{handler=\"query\",job=\"prometheus\"}[5m])>0"); url.append(URLEncodedUtils.format(Arrays.asList(param), "UTF-8")); HttpGet getRequest = new HttpGet(url.toString()); HttpResponse response = client.execute(getRequest); assertEquals(200, response.getStatusLine().getStatusCode()); client.close(); }