List of usage examples for org.apache.http.client.utils URIBuilder toString
@Override
public String toString()
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 ww w . j a v a 2s .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.plugish.woominecraft.WooMinecraft.java
/** * Checks all online players against the * website's database looking for pending donation deliveries * * @return boolean//from w ww . j ava 2 s . c om * @throws Exception */ public boolean check() throws Exception { // Make 100% sure the config has at least a key and url this.validateConfig(); URIBuilder uriBuilder = new URIBuilder(getConfig().getString("url")); uriBuilder.addParameter("wmc_key", getConfig().getString("key")); String url = uriBuilder.toString(); if (url.equals("")) { throw new Exception("WMC URL is empty for some reason"); } RcHttp rcHttp = new RcHttp(this); String httpResponse = rcHttp.request(url); // No response, kill out here. if (httpResponse.equals("")) { return false; } JSONObject pendingCommands = new JSONObject(httpResponse); if (!pendingCommands.getBoolean("success")) { Object dataCheck = pendingCommands.get("data"); if (dataCheck instanceof JSONObject) { JSONObject errors = pendingCommands.getJSONObject("data"); String msg = errors.getString("msg"); throw new Exception(msg); } return false; } Object dataCheck = pendingCommands.get("data"); if (!(dataCheck instanceof JSONObject)) { return false; } JSONObject data = pendingCommands.getJSONObject("data"); Iterator<String> playerNames = data.keys(); JSONArray processedData = new JSONArray(); while (playerNames.hasNext()) { // Walk over players. String playerName = playerNames.next(); @SuppressWarnings("deprecation") Player player = Bukkit.getServer().getPlayerExact(playerName); if (player == null) { continue; } // If the user isn't in a white-listed world, commands will not run here. if (!getConfig().getStringList("whitelist-worlds").contains(player.getWorld().getName())) { continue; } // Get all orders for the current player. JSONObject playerOrders = data.getJSONObject(playerName); Iterator<String> orderIDs = playerOrders.keys(); while (orderIDs.hasNext()) { String orderID = orderIDs.next(); // Get all commands per order JSONArray commands = playerOrders.getJSONArray(orderID); // Walk over commands, executing them one by one. for (Integer x = 0; x < commands.length(); x++) { final String command = commands.getString(x).replace("%s", playerName).replace(""", "\"") .replace("'", "'"); BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); // TODO: Make this better... nesting a 'new' class while not a bad idea is bad practice. scheduler.scheduleSyncDelayedTask(instance, new Runnable() { @Override public void run() { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command); } }, 20L); } processedData.put(Integer.parseInt(orderID)); } } if (1 > processedData.length()) { return false; } HashMap<String, String> postData = new HashMap<>(); postData.put("processedOrders", processedData.toString()); String updatedCommandSet = rcHttp.send(url, postData); JSONObject updatedResponse = new JSONObject(updatedCommandSet); boolean status = updatedResponse.getBoolean("success"); if (!status) { Object dataSet = updatedResponse.get("data"); if (dataSet instanceof JSONObject) { String message = ((JSONObject) dataSet).getString("msg"); throw new Exception(message); } throw new Exception( "Failed sending updated orders to the server, got this instead:" + updatedCommandSet); } return true; }
From source file:com.askfast.askfastapi.util.HttpUtil.java
/** * Append query parameters to given url/*from w w w . j a va2s .co m*/ * * @param url * Url as string * @param params * Map with query parameters * @return url Url with query parameters appended * @throws IOException * Errors in connecting to the given URL */ static public String appendQueryParams(String url, Map<String, String> params) throws IOException { if (params != null) { for (String param : params.keySet()) { try { url = url.replace(" ", "%20"); URIBuilder uriBuilder = new URIBuilder(new URI(url)); URIBuilder returnResult = new URIBuilder(new URI(url)).removeQuery(); //avoid double decoding String queryValue = params.get(param); //replace + with encoded version. it will be replaced by space otherwise queryValue = queryValue.replace("+", URLEncoder.encode("+", "UTF-8")); String decodedQueryParam = URLDecoder.decode(queryValue, "UTF-8"); //queryValue is already encoded if after decoded its not the same if (!decodedQueryParam.equals(queryValue)) { queryValue = decodedQueryParam; } returnResult.addParameter(param, queryValue); for (NameValuePair nameValue : uriBuilder.getQueryParams()) { if (!nameValue.getName().equals(queryValue)) { returnResult.addParameter(nameValue.getName(), nameValue.getValue()); } } url = returnResult.toString(); } catch (Exception e) { e.printStackTrace(); } } } return url; }
From source file:org.geosdi.geoplatform.experimental.openam.support.config.connector.OpenAMConnector.java
/** * @param token/*from w w w.j a v a 2s . com*/ * @return {@link Boolean} * @throws Exception */ @Override public IOpenAMValidateToken validateToken(String token) throws Exception { Preconditions.checkArgument((token != null) && !(token.isEmpty()), "The Token to validate " + "must not be null or an Empty String."); logger.debug( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TRYING TO VALIDATE_TOKEN WITH " + "OPENAM_CONNECTOR_SETTINGS : {}\n", this.openAMConnectorSettings); ValidateTokenRequest validateTokenRequest = this.openAMRequestMediator.getRequest(VALIDATE_TOKEN); URIBuilder uriBuilder = this.buildURI(this.openAMConnectorSettings, validateTokenRequest.setExtraPathParam(token)); validateTokenRequest.addRequestParameter(uriBuilder, this.requestParameterMediator.getRequest(ACTION_VALIDATE)); logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OPENAM_VALIDATE_TOKEN_CONNECTOR_URI : {}\n", URLDecoder.decode(uriBuilder.toString(), "UTF-8")); HttpPost httpPost = new HttpPost(uriBuilder.build()); httpPost.addHeader("Content-Type", "application/json"); CloseableHttpResponse response = this.httpClient.execute(httpPost); if (response.getStatusLine().getStatusCode() != 200) { throw new IllegalStateException( "OpenAMValidateToken Error Code : " + response.getStatusLine().getStatusCode()); } return this.openAMReader.readValue(response.getEntity().getContent(), OpenAMValidateToken.class); }
From source file:org.flowable.admin.service.engine.DecisionTableDeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {//from w ww . j a v a 2 s .c o m builder = new URIBuilder("dmn-repository/deployments"); } catch (Exception e) { log.error("Error building uri", e); throw new FlowableServiceException("Error building uri", e); } for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); } HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }
From source file:com.activiti.service.activiti.JobService.java
public JsonNode listJobs(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {/*from w ww. j a v a 2 s . c om*/ builder = new URIBuilder("management/jobs"); } catch (Exception e) { log.error("Error building uri", e); throw new ActivitiServiceException("Error building uri", e); } for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); } HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }
From source file:org.flowable.admin.service.engine.JobService.java
public JsonNode listJobs(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {//from w ww . ja v a 2s . c o m builder = new URIBuilder("management/jobs"); } catch (Exception e) { log.error("Error building uri", e); throw new FlowableServiceException("Error building uri", e); } for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); } HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }
From source file:org.flowable.admin.service.engine.FormDeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {// w w w.j a v a 2 s. co m builder = new URIBuilder("form-repository/deployments"); } catch (Exception e) { log.error("Error building uri", e); throw new FlowableServiceException("Error building uri", e); } for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); } HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }
From source file:org.eclipse.cft.server.core.internal.ssh.SshClientSupport.java
public String getSshCode() { try {// w ww .j a v a 2s.c o m URIBuilder builder = new URIBuilder(authorizationUrl + "/oauth/authorize"); //$NON-NLS-1$ builder.addParameter("response_type" //$NON-NLS-1$ , "code"); //$NON-NLS-1$ builder.addParameter("grant_type", //$NON-NLS-1$ "authorization_code"); //$NON-NLS-1$ builder.addParameter("client_id", sshClientId); //$NON-NLS-1$ URI url = new URI(builder.toString()); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); HttpStatus statusCode = response.getStatusCode(); if (statusCode != HttpStatus.FOUND) { throw new CloudFoundryException(statusCode); } String loc = response.getHeaders().getFirst("Location"); //$NON-NLS-1$ if (loc == null) { throw new CloudOperationException("No 'Location' header in redirect response"); //$NON-NLS-1$ } List<NameValuePair> qparams = URLEncodedUtils.parse(new URI(loc), "utf8"); //$NON-NLS-1$ for (NameValuePair pair : qparams) { String name = pair.getName(); if (name.equals("code")) { //$NON-NLS-1$ return pair.getValue(); } } throw new CloudOperationException("No 'code' param in redirect Location: " + loc); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new CloudOperationException(e); } }
From source file:com.activiti.service.activiti.DeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {/*www . j a va 2s .c o m*/ builder = new URIBuilder("repository/deployments"); } catch (Exception e) { log.error("Error building uri", e); throw new ActivitiServiceException("Error building uri", e); } for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); } HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }