List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:org.wso2.carbon.identity.captcha.util.CaptchaUtil.java
public static String getErrorPage(String status, String statusMsg) { try {// w w w. j a v a 2 s . c o m URIBuilder uriBuilder = new URIBuilder(CaptchaConstants.ERROR_PAGE); uriBuilder.addParameter("status", status); uriBuilder.addParameter("statusMsg", statusMsg); return uriBuilder.build().toString(); } catch (URISyntaxException e) { if (log.isDebugEnabled()) { log.debug("Error occurred while building URL.", e); } return CaptchaConstants.ERROR_PAGE; } }
From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.RepositoryHelper.java
@NotNull public static Map<PluginId, List<Pair<String, IdeaPluginDescriptor>>> loadPluginsFromChannels( @Nullable BuildNumber buildnumber, @Nullable ProgressIndicator indicator) throws IOException { Map<PluginId, List<Pair<String, IdeaPluginDescriptor>>> result = new LinkedHashMap<PluginId, List<Pair<String, IdeaPluginDescriptor>>>(); String url;//from w w w.ja va 2s. c o m try { URIBuilder uriBuilder = new URIBuilder(ApplicationInfoImpl.getShadowInstance().getChannelsListUrl()); uriBuilder.addParameter("build", (buildnumber != null ? buildnumber.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion())); url = uriBuilder.build().toString(); } catch (URISyntaxException e) { throw new IOException(e); } boolean forceHttps = IdeaApplication.isLoaded() && UpdateSettings.getInstance().canUseSecureConnection(); List<String> channelList = HttpRequests.request(url).forceHttps(forceHttps) .connect(new HttpRequests.RequestProcessor<List<String>>() { @Override public List<String> process(@NotNull HttpRequests.Request request) throws IOException { //{"channels":["alpha","eap","ideadev","nightly"]} return (List<String>) JsonUtil.nextObject(new JsonReaderEx(request.getReader().readLine())) .get("channels"); } }); for (String channel : channelList) { List<IdeaPluginDescriptor> channelPlugins = loadPlugins(null, buildnumber, channel, forceHttps, indicator); for (IdeaPluginDescriptor plugin : channelPlugins) { PluginId pluginId = plugin.getPluginId(); List<Pair<String, IdeaPluginDescriptor>> pluginChannelDescriptors = result.get(pluginId); if (pluginChannelDescriptors == null) { pluginChannelDescriptors = new SmartList<Pair<String, IdeaPluginDescriptor>>(); result.put(pluginId, pluginChannelDescriptors); } pluginChannelDescriptors.add(Pair.create(channel, plugin)); } } return result; }
From source file:com.meltmedia.cadmium.cli.HistoryCommand.java
/** * Retrieves the history of a Cadmium site. * // ww w. j a va 2 s .c o m * @param siteUri The uri of a cadmium site. * @param limit The maximum number of history entries to retrieve or if set to -1 tells the site to retrieve all history. * @param filter If true filters out the non revertable history entries. * @param token The Github API token to pass to the Cadmium site for authentication. * * @return A list of {@link HistoryEntry} Objects that are populated with the history returned from the Cadmium site. * * @throws URISyntaxException * @throws IOException * @throws ClientProtocolException * @throws Exception */ public static List<HistoryEntry> getHistory(String siteUri, int limit, boolean filter, String token) throws URISyntaxException, IOException, ClientProtocolException, Exception { if (!siteUri.endsWith("/system/history")) { siteUri += "/system/history"; } List<HistoryEntry> history = null; HttpClient httpClient = httpClient(); HttpGet get = null; try { URIBuilder uriBuilder = new URIBuilder(siteUri); if (limit > 0) { uriBuilder.addParameter("limit", limit + ""); } if (filter) { uriBuilder.addParameter("filter", filter + ""); } URI uri = uriBuilder.build(); get = new HttpGet(uri); addAuthHeader(token, get); HttpResponse resp = httpClient.execute(get); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = resp.getEntity(); if (entity.getContentType().getValue().equals("application/json")) { String responseContent = EntityUtils.toString(entity); Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { @Override public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) throws JsonParseException { return new Date(json.getAsLong()); } }).create(); history = gson.fromJson(responseContent, new TypeToken<List<HistoryEntry>>() { }.getType()); } else { System.err .println("Invalid response content type [" + entity.getContentType().getValue() + "]"); System.exit(1); } } else { System.err.println("Request failed due to a [" + resp.getStatusLine().getStatusCode() + ":" + resp.getStatusLine().getReasonPhrase() + "] response from the remote server."); System.exit(1); } } finally { if (get != null) { get.releaseConnection(); } } return history; }
From source file:org.wso2.carbon.identity.captcha.util.CaptchaUtil.java
public static String getUpdatedUrl(String url, Map<String, String> attributes) { try {/*from ww w .j av a2 s . c o m*/ URIBuilder uriBuilder = new URIBuilder(url); for (Map.Entry<String, String> entry : attributes.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { if (log.isDebugEnabled()) { log.debug("Error occurred while building URL.", e); } return url; } }
From source file:de.bmarwell.j9kwsolver.util.RequestToURI.java
/** * Converts a request object for retrieving the captcha image * to an URI for 9kw API.//from w ww . j a va2 s .c o m * @param cs the CaptchaShow request. * @return the URI for the API request. */ public static URI captchaShowToURI(final CaptchaShow cs) { URI uri = null; if (cs == null) { return null; } URI apiURI = stringToURI(cs.getUrl()); URIBuilder builder = new URIBuilder(apiURI).addParameter("id", cs.getId()) .addParameter("action", cs.getAction()).addParameter("apikey", cs.getApikey()) .addParameter("source", cs.getSource()) .addParameter("debug", BooleanUtils10.toIntegerString(cs.isDebug())) .addParameter("base64", BooleanUtils10.toIntegerString(cs.isBase64())); try { uri = builder.build(); } catch (URISyntaxException e) { LOG.error("Konnte URI nicht erstellen!", e); } return uri; }
From source file:azkaban.utils.RestfulApiClient.java
/** helper function to build a valid URI. * @param host host name.// w ww . j a v a2 s. c o m * @param port host port. * @param path extra path after host. * @param isHttp indicates if whether Http or HTTPS should be used. * @param params extra query parameters. * @return the URI built from the inputs. * @throws IOException * */ public static URI buildUri(String host, int port, String path, boolean isHttp, Pair<String, String>... params) throws IOException { URIBuilder builder = new URIBuilder(); builder.setScheme(isHttp ? "http" : "https").setHost(host).setPort(port); if (null != path && path.length() > 0) { builder.setPath(path); } if (params != null) { for (Pair<String, String> pair : params) { builder.setParameter(pair.getFirst(), pair.getSecond()); } } URI uri = null; try { uri = builder.build(); } catch (URISyntaxException e) { throw new IOException(e); } return uri; }
From source file:com.meli.client.controller.AppController.java
private static void doApiCalls(String query, String countryCode) { List<Item> items = new ArrayList<Item>(); Random r = new Random(); Meli meliOb = new Meli(2072832875526076L, "1VZEFfhbSCy3vDDrh0Dp96NkfgNOWPGq"); try {//from ww w .ja v a2 s .c o m FluentStringsMap params = new FluentStringsMap(); params.add("q", query); String path = countryCode.isEmpty() ? "/sites/MLA/search/" : "/sites/" + countryCode + "/search"; Response response = meliOb.get(path, params); ObjectMapper objectMapper = new ObjectMapper(); JsonNode rootNode = objectMapper.readTree(response.getResponseBody()); JsonNode resultNode = rootNode.findPath("results"); if (resultNode.size() > 0) { JsonNode currNode = null; JsonNode dupNode = null; boolean dupNodeVal = false; CloseableHttpClient httpClient = HttpClientBuilder.create().build(); Item item = null; int randomMins; String checkDupsUrl = null; HttpGet get = null; URIBuilder builder = null; URI uri = null; for (int i = 0; i < resultNode.size(); i++) { currNode = resultNode.get(i); builder = new URIBuilder(); builder.setScheme("http").setHost(apiUrl).setPath("/api/proxy/check") .setParameter("host", "test").setParameter("itemID", currNode.get("id").asText()); uri = builder.build(); get = new HttpGet(uri); get.addHeader("accept", "application/json"); CloseableHttpResponse res = httpClient.execute(get); BufferedReader br = new BufferedReader(new InputStreamReader(res.getEntity().getContent())); String content = "", line; while ((line = br.readLine()) != null) { content = content + line; } if (!content.isEmpty()) { dupNode = objectMapper.readTree(content); dupNodeVal = Boolean.parseBoolean(dupNode.get("isDuplicate").asText()); if (dupNodeVal && !allowDuplicates) continue; item = new Item(query, currNode.get("id").asText(), "", //currNode.get("host").asText(),?? currNode.get("site_id").asText(), currNode.get("title").asText(), currNode.get("permalink").asText(), currNode.get("category_id").asText(), currNode.get("seller").get("id").asText(), "", //currNode.get("seller").get("name").asText() "", //currNode.get("seller").get("link").asText() "", //currNode.get("seller").get("email").asText() currNode.get("price").asText(), "", //currNode.get("auction_price").asText(), "", //currNode.get("currency_id").asText(), currNode.get("thumbnail").asText()); items.add(item); } randomMins = (int) (Math.random() * (maxWaitTime - minWaitTime)) + minWaitTime; Thread.sleep(randomMins); } if (!items.isEmpty()) { HttpPost post = new HttpPost(apiUrl + "/proxy/add"); StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(items)); post.setEntity(stringEntity); post.setHeader("Content-type", "application/json"); CloseableHttpResponse postResponse = httpClient.execute(post); System.out.println("this is the reponse of the final request: " + postResponse.getStatusLine().getStatusCode()); } } } catch (MeliException ex) { Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java
private static Map<RyaURI, String> convertUriToTypeMap(final URI typeMapUri) throws SmartUriException { final Map<RyaURI, String> map = new HashMap<>(); java.net.URI uri;//from ww w . jav a 2s .com try { final URIBuilder uriBuilder = new URIBuilder(typeMapUri.stringValue()); uri = uriBuilder.build(); } catch (final URISyntaxException e) { throw new SmartUriException("Unable to parse Rya type map in Smart URI", e); } final List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8.name()); for (final NameValuePair param : params) { final String name = param.getName(); final String value = param.getValue(); final RyaURI type = new RyaURI(name); map.put(type, value); } return map; }
From source file:org.wso2.carbon.apimgt.authenticator.oidc.ui.common.Util.java
/** * Building authentication request//from ww w .j av a 2s . c o m * @param nonce cryptographically random nonce * @param state cryptographically random state * @return url */ public static String buildAuthRequestUrl(String nonce, String state) { try { log.debug("Building Authentication request..."); URIBuilder uriBuilder = new URIBuilder(authorizationEndpointURI); uriBuilder.addParameter(OIDCConstants.PARAM_RESPONSE_TYPE, responseType); uriBuilder.addParameter(OIDCConstants.PARAM_CLIENT_ID, clientId); uriBuilder.addParameter(OIDCConstants.PARAM_SCOPE, scope); uriBuilder.addParameter(OIDCConstants.PARAM_REDIRECT_URI, redirectURI); uriBuilder.addParameter(OIDCConstants.PARAM_NONCE, nonce); uriBuilder.addParameter(OIDCConstants.PARAM_STATE, state); return uriBuilder.build().toString(); } catch (URISyntaxException e) { log.error("Build Auth Request Failed", e); } return null; }
From source file:org.wuspba.ctams.ui.server.DataUtils.java
protected static CTAMSDocument getBandRegistration(HttpServletRequest request) { BandRegistration registration = new BandRegistration(); URIBuilder builder = new URIBuilder().setScheme(ServerUtils.PROTOCOL).setHost(ServerUtils.HOST) .setPort(ServerUtils.PORT).setParameter("name", request.getParameter("band")) .setPath(ServerUtils.URI + "/band"); try {//ww w. j a v a2 s . c om String xml = ServerUtils.get(builder.build()); CTAMSDocument bands = XMLUtils.unmarshal(xml); registration.setBand(bands.getBands().get(0)); } catch (IOException ex) { LOG.error("Error finding band", ex); } catch (URISyntaxException uex) { LOG.error("Invalide URI", uex); } registration.setId(request.getParameter("id")); try { registration.setEnd(dateParser.parse(request.getParameter("end"))); } catch (ParseException ex) { LOG.error("Cannot parse date", ex); } try { Date date = dateParser.parse(request.getParameter("start")); registration.setStart(date); } catch (ParseException ex) { LOG.error("Cannot parse date", ex); } registration.setGrade(Grade.valueOf(request.getParameter("grade"))); registration.setSeason(Integer.parseInt(request.getParameter("season"))); CTAMSDocument doc = new CTAMSDocument(); doc.getBandRegistrations().add(registration); return doc; }