List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
From source file:org.talend.dataprep.api.service.command.dataset.MoveDataSet.java
/** * Constructor./*from ww w . j ava2 s. c o m*/ * * @param dataSetId the requested dataset id. * @param folderPath the origin folder othe the dataset * @param newFolderPath the new folder path * @param newName the new name (optional) */ public MoveDataSet(String dataSetId, String folderPath, String newFolderPath, String newName) { super(GenericCommand.DATASET_GROUP); execute(() -> { try { URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/move/" + dataSetId); if (StringUtils.isNotEmpty(folderPath)) { uriBuilder.addParameter("folderPath", folderPath); } if (StringUtils.isNotEmpty(newFolderPath)) { uriBuilder.addParameter("newFolderPath", newFolderPath); } if (StringUtils.isNotEmpty(newName)) { uriBuilder.addParameter("newName", newName); } return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }); onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_COPY_DATASET_CONTENT, e, build().put("id", dataSetId))); on(HttpStatus.OK, HttpStatus.BAD_REQUEST).then((httpRequestBase, httpResponse) -> { try { // we transfer status code and content type return new HttpResponse(httpResponse.getStatusLine().getStatusCode(), // IOUtils.toString(httpResponse.getEntity().getContent()), // httpResponse.getStatusLine().getStatusCode() == HttpStatus.BAD_REQUEST.value() ? // APPLICATION_JSON_VALUE : TEXT_PLAIN_VALUE); } catch (IOException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { httpRequestBase.releaseConnection(); } }); }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationReorderStep.java
private HttpRequestBase onExecute(final String preparationId, final String stepId, final String parentStepId) { try {//from w w w. j a v a 2 s .c o m URIBuilder builder = new URIBuilder( preparationServiceUrl + "/preparations/" + preparationId + "/steps/" + stepId + "/order"); if (StringUtils.isNotBlank(parentStepId)) { builder.addParameter("parentStepId", parentStepId); } return new HttpPost(builder.build()); } catch (URISyntaxException e) { throw new TDPException(UNEXPECTED_EXCEPTION, e); } }
From source file:com.github.dziga.orest.client.HttpRestClient.java
private void addQueryParams(URIBuilder b) { for (Map.Entry<String, String> param : queryParams.entrySet()) { b.addParameter(param.getKey(), param.getValue()); }//from ww w .ja v a 2 s. c om }
From source file:com.revo.deployr.client.core.impl.RRepositoryFileImpl.java
public URL diff() throws RClientException, RSecurityException { URL diffURL;// ww w . j a va 2 s . c om if (this.about.version == null) { throw new RClientException( "Repository file diff can only be requested on a version of a file, not on the latest."); } try { String urlPath = liveContext.serverurl + REndpoints.RREPOSITORYFILEDIFF; urlPath = urlPath + ";jsessionid=" + liveContext.httpcookie; URIBuilder builder = new URIBuilder(urlPath); builder.addParameter("filename", this.about.filename); builder.addParameter("directory", this.about.directory); builder.addParameter("author", this.about.latestby); builder.addParameter("version", this.about.version); diffURL = builder.build().toURL(); } catch (Exception uex) { throw new RClientException("Diff url: ex=" + uex.getMessage()); } return diffURL; }
From source file:io.kamax.mxisd.lookup.provider.RemoteIdentityServerFetcher.java
@Override public Optional<SingleLookupReply> find(String remote, SingleLookupRequest request) { log.info("Looking up {} 3PID {} using {}", request.getType(), request.getThreePid(), remote); try {//from w ww. ja v a2 s .c om URIBuilder b = new URIBuilder(remote); b.setPath("/_matrix/identity/api/v1/lookup"); b.addParameter("medium", request.getType()); b.addParameter("address", request.getThreePid()); HttpGet req = new HttpGet(b.build()); try (CloseableHttpResponse res = client.execute(req)) { int statusCode = res.getStatusLine().getStatusCode(); String body = EntityUtils.toString(res.getEntity()); if (statusCode != 200) { log.warn("Remote returned status code {}", statusCode); log.warn("Body: {}", body); return Optional.empty(); } JsonObject obj = GsonUtil.parseObj(body); if (obj.has("address")) { log.debug("Found 3PID mapping: {}", gson.toJson(obj)); return Optional.of(SingleLookupReply.fromRecursive(request, gson.toJson(obj))); } log.info("Empty 3PID mapping from {}", remote); return Optional.empty(); } } catch (IOException e) { log.warn("Error looking up 3PID mapping {}: {}", request.getThreePid(), e.getMessage()); return Optional.empty(); } catch (JsonParseException e) { log.warn("Invalid JSON answer from {}", remote); return Optional.empty(); } catch (URISyntaxException e) { log.warn("Invalid remote address: {}", e.getMessage(), e); return Optional.empty(); } }
From source file:org.dspace.submit.lookup.ArXivService.java
protected List<Record> search(String query, String arxivid, int max_result) throws IOException, HttpException { List<Record> results = new ArrayList<Record>(); HttpGet method = null;// www. j ava2s . c o m try { HttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); try { URIBuilder uriBuilder = new URIBuilder("http://export.arxiv.org/api/query"); uriBuilder.addParameter("id_list", arxivid); uriBuilder.addParameter("search_query", query); uriBuilder.addParameter("max_results", String.valueOf(max_result)); method = new HttpGet(uriBuilder.build()); } catch (URISyntaxException ex) { throw new HttpException(ex.getMessage()); } // Execute the method. HttpResponse response = client.execute(method); StatusLine responseStatus = response.getStatusLine(); int statusCode = responseStatus.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { if (statusCode == HttpStatus.SC_BAD_REQUEST) throw new RuntimeException("arXiv query is not valid"); else throw new RuntimeException("Http call failed: " + responseStatus); } try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder db = factory.newDocumentBuilder(); Document inDoc = db.parse(response.getEntity().getContent()); Element xmlRoot = inDoc.getDocumentElement(); List<Element> dataRoots = XMLUtils.getElementList(xmlRoot, "entry"); for (Element dataRoot : dataRoots) { Record crossitem = ArxivUtils.convertArxixDomToRecord(dataRoot); if (crossitem != null) { results.add(crossitem); } } } catch (Exception e) { throw new RuntimeException("ArXiv identifier is not valid or not exist"); } } finally { if (method != null) { method.releaseConnection(); } } return results; }
From source file:com.epam.ngb.cli.manager.command.handler.http.DatasetListHandler.java
private HttpRequestBase createTreeRequest(Long parentId) { try {/* www .j ava 2 s . c o m*/ URIBuilder builder = new URIBuilder( serverParameters.getServerUrl() + serverParameters.getProjectTreeUrl()); builder.addParameter("parentId", String.valueOf(parentId)); HttpGet get = new HttpGet(builder.build()); setDefaultHeader(get); if (isSecure()) { addAuthorizationToRequest(get); } return get; } catch (URISyntaxException e) { throw new ApplicationException(e.getMessage(), e); } }
From source file:models.Pagination.java
private URI createReference(final String path, final int limit, final int offset, final Map<String, String> conditions) { final URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setPath(path);//from w w w . j a va2 s. c om for (Map.Entry<String, String> entry : conditions.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } uriBuilder.addParameter("limit", String.valueOf(limit)); uriBuilder.addParameter("offset", String.valueOf(offset)); try { return uriBuilder.build(); } catch (final URISyntaxException e) { throw new RuntimeException("Failed building uri", e); } }
From source file:org.cerberus.launchcampaign.executecampaign.ExecuteCampaignDto.java
public URL buildUrl(String urlCerberus) throws MalformedURLException, URISyntaxException { URIBuilder b = new URIBuilder(urlCerberus + "/" + Constantes.URL_ADD_CAMPAIGN_TO_EXECUTION_QUEUE); b.addParameter("screenshot", this.screenshot + ""); b.addParameter("verbose", this.verbose + ""); b.addParameter("timeout", this.timeOut + ""); b.addParameter("pagesource", this.pageSource + ""); b.addParameter("seleniumlog", this.seleniumLog + ""); b.addParameter("retries", this.retries + ""); b.addParameter("manualexecution", "N"); b.addParameter("ss_ip", ss_ip); b.addParameter("ss_p", ss_p); b.addParameter("robot", robot); b.addParameter("environment", environment); b.addParameter("browser", browser); b.addParameter("version", browserVersion); b.addParameter("platform", platform); b.addParameter("campaign", selectedCampaign); b.addParameter("screensize", screensize); // genere a random tag b.addParameter("tag", tagCerberusCampaign); return new URL(b.build().toString()); }
From source file:oracle.custom.ui.servlet.ConfigInputCheck.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//ww w . j a va 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("processing ConfigInputCheck request"); try { PrintWriter out = response.getWriter(); String whichform = request.getParameter("whichform"); String domain = request.getParameter("domain"); String idcsUrl = request.getParameter("idcsUrl"); String myUrl = request.getParameter("myUrl"); String clientId = request.getParameter("clientId"); String clientSecret = request.getParameter("clientSecret"); String appId = request.getParameter("appId"); String appSecret = request.getParameter("appSecret"); switch (whichform) { case "checkOpenID": OpenIdConfiguration openidConf = OpenIdConfiguration.getButDontSave(idcsUrl); URIBuilder builder = new URIBuilder(openidConf.getAuthzEndpoint()); builder.addParameter("client_id", clientId); builder.addParameter("response_type", "code"); builder.addParameter("redirect_uri", myUrl + "atreturn/"); builder.addParameter("scope", "urn:opc:idm:t.user.me openid urn:opc:idm:__myscopes__"); builder.addParameter("nonce", UUID.randomUUID().toString()); URI url = builder.build(); System.out.println("URL: " + url.toString()); // now go get it HttpClient client = ServerUtils.getClient(); HttpGet get = new HttpGet(url); HttpHost host = new HttpHost(url.getHost(), url.getPort(), url.getScheme()); HttpResponse httpResponse = client.execute(host, get); try { // IDCS behavior has changed. // older versions returned 303 with a Location: header // current version returns 200 with HTML if ((httpResponse.getStatusLine().getStatusCode() == 303) || (httpResponse.getStatusLine().getStatusCode() == 200)) { System.out.println("Request seems to have worked"); out.print("Success?"); } else throw new ServletException("Invalid status from OAuth AZ URL. Expected 303, got " + httpResponse.getStatusLine().getStatusCode()); } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } break; default: throw new Exception("Invalid request"); } } catch (Exception e) { e.printStackTrace(); throw new ServletException("Error."); } }