List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
From source file:io.fabric8.etcd.impl.dsl.GetDataImpl.java
@Override public HttpUriRequest createRequest(OperationContext context) { try {// w ww . java 2 s. c o m URIBuilder builder = new URIBuilder(context.getBaseUri()).setPath(Keys.makeKey(key)) .addParameter("recursive", String.valueOf(recursive)) .addParameter("sorted", String.valueOf(sorted)); if (shouldWait) { builder = builder.addParameter("wait", "true"); if (waitIndex > 0) { builder = builder.addParameter("waitIndex", String.valueOf(waitIndex)); } } return new HttpGet(builder.build()); } catch (Exception e) { throw new RuntimeException(e); } }
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 w w. java2 s . co m*/ * @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:org.flowable.admin.service.engine.FormDeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {/*www.j av a 2 s . com*/ 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.dspace.submit.lookup.PubmedService.java
public List<Record> search(String query) throws IOException, HttpException { List<Record> results = new ArrayList<>(); if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo")) { HttpGet method = null;//www. java 2s . c o m try { HttpClient client = new DefaultHttpClient(); client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); URIBuilder uriBuilder = new URIBuilder("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"); uriBuilder.addParameter("db", "pubmed"); uriBuilder.addParameter("datetype", "edat"); uriBuilder.addParameter("retmax", "10"); uriBuilder.addParameter("term", query); method = new HttpGet(uriBuilder.build()); // Execute the method. HttpResponse response = client.execute(method); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { throw new RuntimeException("WS call failed: " + statusLine); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); Document inDoc = builder.parse(response.getEntity().getContent()); Element xmlRoot = inDoc.getDocumentElement(); Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList"); List<String> pubmedIDs = XMLUtils.getElementValueList(idList, "Id"); results = getByPubmedIDs(pubmedIDs); } catch (ParserConfigurationException e1) { log.error(e1.getMessage(), e1); } catch (SAXException e1) { log.error(e1.getMessage(), e1); } } catch (Exception e1) { log.error(e1.getMessage(), e1); } finally { if (method != null) { method.releaseConnection(); } } } else { InputStream stream = null; try { File file = new File(ConfigurationManager.getProperty("dspace.dir") + "/config/crosswalks/demo/pubmed-search.xml"); stream = new FileInputStream(file); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document inDoc = builder.parse(stream); Element xmlRoot = inDoc.getDocumentElement(); Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList"); List<String> pubmedIDs = XMLUtils.getElementValueList(idList, "Id"); results = getByPubmedIDs(pubmedIDs); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } } return results; }
From source file:com.activiti.service.activiti.DeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {//from w w w. j ava 2 s .co 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); }
From source file:org.flowable.admin.service.engine.DeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null;/*from ww w . j a v a 2 s . c o m*/ try { builder = new URIBuilder("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:de.dentrassi.pm.jenkins.UploaderV2.java
private URI makeUrl(final String file) throws URIException, IOException { final URI fullUri; try {/*w ww . j a va 2s. c o m*/ final URIBuilder b = new URIBuilder(this.serverUrl); b.setUserInfo("deploy", this.deployKey); b.setPath(b.getPath() + String.format("/api/v2/upload/channel/%s/%s", URIUtil.encodeWithinPath(this.channelId), file)); b.addParameter("jenkins:buildUrl", this.runData.getUrl()); b.addParameter("jenkins:buildId", this.runData.getId()); b.addParameter("jenkins:buildNumber", String.valueOf(this.runData.getNumber())); b.addParameter("jenkins:jobName", this.runData.getFullName()); final Map<String, String> properties = new HashMap<String, String>(); fillProperties(properties); for (final Map.Entry<String, String> entry : properties.entrySet()) { b.addParameter(entry.getKey(), entry.getValue()); } fullUri = b.build(); } catch (final URISyntaxException e) { throw new IOException(e); } return fullUri; }
From source file:com.alibaba.shared.django.DjangoClient.java
protected URI buildURI(String baseUrl, Map<String, String> params, boolean hasAccessToken) { try {//from ww w.j a va 2 s . c om URIBuilder builder = new URIBuilder(baseUrl); if (hasAccessToken) { builder.addParameter(ACCESS_TOKEN_KEY, accessToken()); } for (String paramName : params.keySet()) { builder.addParameter(paramName, params.get(paramName)); } return builder.build(); } catch (URISyntaxException e) { throw new DjangoRequestException(e.getMessage(), e); } }
From source file:org.flowable.admin.service.engine.EventSubscriptionService.java
public JsonNode listEventSubscriptions(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {//from w ww. j a v a 2s .c om builder = new URIBuilder("runtime/event-subscriptions"); } 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.collective.celos.CelosClient.java
public void kill(WorkflowID workflowID, ScheduledTime scheduledTime) throws Exception { URIBuilder uriBuilder = new URIBuilder(address); uriBuilder.setPath(uriBuilder.getPath() + KILL_PATH); uriBuilder.addParameter(ID_PARAM, workflowID.toString()); uriBuilder.addParameter(TIME_PARAM, scheduledTime.toString()); executePost(uriBuilder.build());/*from w w w .ja va2 s . co m*/ }