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.wso2.carbon.apimgt.hostobjects.oidc.OIDCRelyingPartyObject.java
/** * Building authentication request URL. This URL allows to redirect in to OIDC server and authenticate. * @param cx - Context//from w w w .j a va 2 s .c o m * @param thisObj - This Object * @param args - takes nonce and state parameters * @param funObj - Function * @return URL which redirects to OIDC server and allow to authenticate * @throws Exception */ public static String jsFunction_buildAuthRequestUrl(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { int argLength = args.length; if (argLength != 2 || !(args[0] instanceof String) || !(args[1] instanceof String)) { throw new ScriptException("Invalid argument. Nonce or State not set properly"); } String nonce = (String) args[0]; String state = (String) args[1]; OIDCRelyingPartyObject relyingPartyObject = (OIDCRelyingPartyObject) thisObj; try { log.debug(" Building auth request Url"); URIBuilder uriBuilder = new URIBuilder( relyingPartyObject.getOIDCProperty(OIDCConstants.AUTHORIZATION_ENDPOINT_URI)); uriBuilder.addParameter(OIDCConstants.RESPONSE_TYPE, relyingPartyObject.getOIDCProperty(OIDCConstants.RESPONSE_TYPE)); uriBuilder.addParameter(OIDCConstants.CLIENT_ID, relyingPartyObject.getOIDCProperty(OIDCConstants.CLIENT_ID)); uriBuilder.addParameter(OIDCConstants.SCOPE, relyingPartyObject.getOIDCProperty(OIDCConstants.SCOPE)); uriBuilder.addParameter(OIDCConstants.REDIRECT_URI, relyingPartyObject.getOIDCProperty(OIDCConstants.REDIRECT_URI)); uriBuilder.addParameter(OIDCConstants.NONCE, nonce); uriBuilder.addParameter(OIDCConstants.STATE, state); // Optional parameters: //for (Map.Entry<String, String> option : options.entrySet()) { // uriBuilder.addParameter(option.getKey(), option.getValue()); //} //uriBuilder.addParameter("requestURI", requestURI); return uriBuilder.build().toString(); } catch (URISyntaxException e) { log.error("Build Auth Request Failed", e); throw new Exception("Build Auth Request Failed", e); } }
From source file:de.ii.xtraplatform.ogc.csw.client.CSWAdapter.java
public static URI parseAndCleanWfsUrl(String url) throws URISyntaxException { URI inUri = new URI(url.trim()); URIBuilder outUri = new URIBuilder(inUri).removeQuery(); if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) { for (String inParam : inUri.getQuery().split("&")) { String[] param = inParam.split("="); if (!CSW.hasKVPKey(param[0].toUpperCase())) { outUri.addParameter(param[0], param[1]); }//from w w w .j av a2s .c om } } return outUri.build(); }
From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.RepositoryHelper.java
@NotNull public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, @Nullable BuildNumber buildnumber, @Nullable String channel, boolean forceHttps, @Nullable final ProgressIndicator indicator) throws IOException { String url;//from w w w. j a v a 2s . co m final File pluginListFile; final String host; try { URIBuilder uriBuilder; if (repositoryUrl == null) { uriBuilder = new URIBuilder(ApplicationInfoImpl.getShadowInstance().getPluginsListUrl()); pluginListFile = new File(PathManager.getPluginsPath(), channel == null ? PLUGIN_LIST_FILE : channel + "_" + PLUGIN_LIST_FILE); if (pluginListFile.length() > 0) { uriBuilder.addParameter("crc32", Files.hash(pluginListFile, Hashing.crc32()).toString()); } } else { uriBuilder = new URIBuilder(repositoryUrl); pluginListFile = null; } if (!URLUtil.FILE_PROTOCOL.equals(uriBuilder.getScheme())) { uriBuilder.addParameter("build", (buildnumber != null ? buildnumber.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion())); if (channel != null) uriBuilder.addParameter("channel", channel); } host = uriBuilder.getHost(); url = uriBuilder.build().toString(); } catch (URISyntaxException e) { throw new IOException(e); } if (indicator != null) { indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", host)); } RequestBuilder request = HttpRequests.request(url).forceHttps(forceHttps); return process(repositoryUrl, request.connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() { @Override public List<IdeaPluginDescriptor> process(@NotNull HttpRequests.Request request) throws IOException { if (indicator != null) { indicator.checkCanceled(); } URLConnection connection = request.getConnection(); if (pluginListFile != null && pluginListFile.length() > 0 && connection instanceof HttpURLConnection && ((HttpURLConnection) connection) .getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { return loadPluginList(pluginListFile); } if (indicator != null) { indicator.checkCanceled(); indicator.setText2(IdeBundle.message("progress.downloading.list.of.plugins", host)); } if (pluginListFile != null) { synchronized (RepositoryHelper.class) { FileUtil.ensureExists(pluginListFile.getParentFile()); request.saveToFile(pluginListFile, indicator); return loadPluginList(pluginListFile); } } else { return parsePluginList(request.getReader()); } } })); }
From source file:org.kie.smoke.wb.util.RestUtil.java
public static <T, G> T getQuery(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user, String password, Map<String, String> queryParams, Class... responseTypes) { URIBuilder uriBuilder = null; try {// w w w . j a v a2s . c om String uriStr = createBaseUriString(deploymentUrl, relativeUrl); uriBuilder = new URIBuilder(uriStr); } catch (URISyntaxException urise) { logAndFail("Invalid uri :" + deploymentUrl.toString(), urise); } for (Entry<String, String> paramEntry : queryParams.entrySet()) { uriBuilder.addParameter(paramEntry.getKey(), paramEntry.getValue()); } URI uri = null; String uriStr = null; try { uri = uriBuilder.build(); uriStr = uri.toString(); } catch (URISyntaxException urise) { logAndFail("Invalid uri!", urise); } ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes); // @formatter:off Request request = Request.Get(uri).addHeader(HttpHeaders.ACCEPT, mediaType.toString()) .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password)); // @formatter:off Response resp = null; try { logOp("GET", uriStr); resp = request.execute(); } catch (Exception e) { logAndFail("[GET] " + uriStr, e); } try { return resp.handleResponse(rh); } catch (Exception e) { logAndFail("Failed retrieving response from [GET] " + uriStr, e); } // never happens return null; }
From source file:org.kie.remote.tests.base.RestUtil.java
public static <T, G> T getQuery(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user, String password, Map<String, String> queryParams, Class... responseTypes) { URIBuilder uriBuilder = null; try {// w ww .ja v a2 s .c o m String uriStr = createBaseUriString(deploymentUrl, relativeUrl); uriBuilder = new URIBuilder(uriStr); } catch (URISyntaxException urise) { failAndLog("Invalid uri :" + deploymentUrl.toString(), urise); } for (Entry<String, String> paramEntry : queryParams.entrySet()) { String param = paramEntry.getKey(); String value = paramEntry.getValue(); uriBuilder.addParameter(paramEntry.getKey(), paramEntry.getValue()); } URI uri = null; String uriStr = null; try { uri = uriBuilder.build(); uriStr = uri.toString(); } catch (URISyntaxException urise) { failAndLog("Invalid uri!", urise); } ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes); // @formatter:off Request request = Request.Get(uri).addHeader(HttpHeaders.ACCEPT, mediaType.toString()) .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password)); // @formatter:off Response resp = null; try { logOp("GET", uriStr); resp = request.execute(); } catch (Exception e) { failAndLog("[GET] " + uriStr, e); } try { return resp.handleResponse(rh); } catch (Exception e) { failAndLog("Failed retrieving response from [GET] " + uriStr, e); } // never happens return null; }
From source file:de.ii.xtraplatform.ogc.api.wfs.client.WFSAdapter.java
private static URI parseAndCleanWfsUrl(URI inUri) throws URISyntaxException { URIBuilder outUri = new URIBuilder(inUri).removeQuery(); if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) { for (String inParam : inUri.getQuery().split("&")) { String[] param = inParam.split("="); if (!WFS.hasKVPKey(param[0].toUpperCase())) { outUri.addParameter(param[0], param[1]); }// w w w . j a v a 2 s . c o m } } return outUri.build(); }
From source file:org.restcomm.connect.java.sdk.http.Request.java
public void addGetParameters(String a, String b) throws MalformedURLException, URISyntaxException { URIBuilder urib = new URIBuilder(Url); urib.addParameter(a, b); urib.build();/* w w w .j a v a 2s. c o m*/ Url = new URL(urib.toString()).toString(); }
From source file:org.fao.geonet.harvester.wfsfeatures.worker.OwsUtils.java
public String getDescribeFeatureTypeUrl(final String wfsUrl, final String featureType, final String version) throws Exception { URIBuilder builder = new URIBuilder(wfsUrl); builder.addParameter("request", "DescribeFeatureType"); builder.addParameter("service", "WFS"); builder.addParameter("version", version); builder.addParameter("TYPENAME", featureType); String url = builder.build().toURL().toString(); return url;/*ww w .java 2 s . c o m*/ }
From source file:com.revo.deployr.client.core.impl.RProjectResultImpl.java
public InputStream download() throws RClientException, RSecurityException { try {//from w ww . j a v a 2 s .c o m 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()); } }
From source file:org.talend.dataprep.api.service.command.folder.CreateChildFolder.java
private HttpRequestBase onExecute(final String parentId, final String path) { try {// w ww . j a va2 s . c o m URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/folders"); uriBuilder.addParameter("parentId", parentId); uriBuilder.addParameter("path", path); return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }