List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder(final URI uri)
From source file:com.linemetrics.monk.api.RestClient.java
public URI buildURI(String path, Map<String, String> params) throws URISyntaxException { URIBuilder ub = new URIBuilder(uri); ub.setPath(ub.getPath() + path);/*from ww w . jav a2 s . c om*/ if (params != null) { for (Map.Entry<String, String> ent : params.entrySet()) ub.addParameter(ent.getKey(), ent.getValue()); } return ub.build(); }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationCopy.java
private HttpRequestBase onExecute(final String preparationId, final String destination, final String newName) { try {//from ww w . ja v a 2 s.c o m URIBuilder uriBuilder = new URIBuilder( preparationServiceUrl + "/preparations/" + preparationId + "/copy"); if (StringUtils.isNotBlank(destination)) { uriBuilder.addParameter("destination", destination); } if (StringUtils.isNotBlank(newName)) { uriBuilder.addParameter("name", newName); } return new HttpPost(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationListByFolder.java
/** * Private constructor used to construct the generic command used to list of preparations matching name. * * @param folderId the folder id where to look for preparations. * @param sort how to sort the preparations. * @param order the order to apply to the sort. *//*from w w w .j a v a 2s .co m*/ private PreparationListByFolder(final String folderId, final Sort sort, final Order order) { super(GenericCommand.PREPARATION_GROUP); execute(() -> { try { final URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/search"); uriBuilder.addParameter("folderId", folderId); uriBuilder.addParameter("sort", sort.camelName()); uriBuilder.addParameter("order", order.camelName()); return new HttpGet(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }); onError(e -> new TDPException(UNABLE_TO_RETRIEVE_PREPARATION_LIST, e)); on(NO_CONTENT, ACCEPTED).then(emptyStream()); on(OK).then(pipeStream()); }
From source file:net.oneandone.shared.artifactory.SearchByGav.java
URI buildSearchURI(String repositoryName, Gav gav) { final URIBuilder uriBuilder = new URIBuilder(baseUri.resolve("api/search/gavc")) .addParameter("repos", repositoryName).addParameter("g", gav.getGroupId()) .addParameter("a", gav.getArtifactId()).addParameter("v", gav.getVersion()); return Utils.toUri(uriBuilder, "Could not build URI from " + baseUri + " using repositoryName=" + repositoryName + ", gav=" + gav); }
From source file:client.ClientBase.java
/** * Creates a URIBuilder with the base path and a relative path resolved. * * @param relativePath the relative path * @return a new {@link URIBuilder}/*from ww w. j av a 2s. co m*/ */ protected URIBuilder uriBuilder(final String relativePath) { final URI tokenUri; try { tokenUri = new URI(_baseUrl).resolve(relativePath); } catch (final URISyntaxException e) { LOGGER.error(String.format("Unable to parse baseURL; baseURL=%s", _baseUrl), e); throw Throwables.propagate(e); } return new URIBuilder(tokenUri); }
From source file:org.mitre.openid.connect.client.service.impl.PlainAuthRequestUrlBuilder.java
@Override public String buildAuthRequestUrl(ServerConfiguration serverConfig, RegisteredClient clientConfig, String redirectUri, String nonce, String state, Map<String, String> options, String loginHint) { try {/*from ww w . j a v a 2 s. c o m*/ URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri()); uriBuilder.addParameter("response_type", "code"); uriBuilder.addParameter("client_id", clientConfig.getClientId()); uriBuilder.addParameter("scope", Joiner.on(" ").join(clientConfig.getScope())); uriBuilder.addParameter("redirect_uri", redirectUri); uriBuilder.addParameter("nonce", nonce); uriBuilder.addParameter("state", state); // Optional parameters: for (Entry<String, String> option : options.entrySet()) { uriBuilder.addParameter(option.getKey(), option.getValue()); } // if there's a login hint, send it if (!Strings.isNullOrEmpty(loginHint)) { uriBuilder.addParameter("login_hint", loginHint); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e); } }
From source file:eu.dime.userresolver.client.ResolverClient.java
public void searchAll(String token, String name) { HttpGet httpGet;/*from w w w. j a va 2s. co m*/ try { URIBuilder builder = new URIBuilder(serviceEnpoint + "/search"); builder.setParameter("like", name); httpGet = new HttpGet(builder.build()); } catch (URISyntaxException e) { throw new RuntimeException(e); } httpGet.setHeader("Authorization", "Bearer " + token); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { String jsonResponse = IOUtils.toString(entity.getContent()); LOG.debug("Search response: {}", jsonResponse); } } catch (IOException e) { LOG.debug("Unable to search", e); } }
From source file:org.talend.dataprep.api.service.command.dataset.MoveDataSet.java
/** * Constructor./*from ww w . j a v a 2s .co 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:it.smartcommunitylab.aac.oauth.ExtOAuth2SuccessHandler.java
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { OAuth2Authentication oauth = (OAuth2Authentication) authentication; @SuppressWarnings("unchecked") Map<String, Object> details = (Map<String, Object>) oauth.getUserAuthentication().getDetails(); details = preprocess(details);/* www .j a va 2 s . co m*/ try { URIBuilder builder = new URIBuilder(getDefaultTargetUrl()); for (String key : details.keySet()) { builder.addParameter(key, details.get(key).toString()); request.setAttribute(key, details.get(key)); } request.getRequestDispatcher(builder.build().toString()).forward(request, response); // response.sendRedirect("forward:"+builder.build().toString()); // getRedirectStrategy().sendRedirect(request, response, builder.build().toString()); } catch (URISyntaxException e) { throw new ServletException(e.getMessage()); } }
From source file:com.revo.deployr.client.core.impl.RProjectResultImpl.java
public InputStream download() throws RClientException, RSecurityException { try {/*from ww w . ja v a 2 s .c om*/ String urlBase = this.liveContext.serverurl + REndpoints.RPROJECTEXECUTERESULTDOWNLOAD; String urlPath = urlBase + ";jsessionid=" + liveContext.httpcookie; URIBuilder builder = new URIBuilder(urlPath); builder.addParameter("project", this.project.id); builder.addParameter("filename", this.about.filename); return liveContext.executor.download(builder); } catch (Exception ex) { throw new RClientException("Download failed: " + ex.getMessage()); } }