Java Code Examples for com.google.common.net.UrlEscapers#urlFormParameterEscaper()
The following examples show how to use
com.google.common.net.UrlEscapers#urlFormParameterEscaper() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DaxTrackerServerApi.java From Runescape-Web-Walker-Engine with Apache License 2.0 | 6 votes |
public ListSearch sourcesOnline(String propertyName, String user, Period period) { ServerResponse serverResponse; Escaper escaper = UrlEscapers.urlFormParameterEscaper(); try { serverResponse = IOHelper.get( TRACKER_ENDPOINT + "/tracker/sources/online?propertyName=" + escaper.escape(propertyName) + "&user=" + escaper.escape(user) + (period != null ? "&period=" + period : ""), daxCredentialsProvider ); } catch (IOException e) { e.printStackTrace(); return null; } if (serverResponse.getCode() != HttpURLConnection.HTTP_OK) { log("ERROR: " + new JsonParser().parse(serverResponse.getContents()).getAsJsonObject().get("message").getAsString()); return null; } return new Gson().fromJson(serverResponse.getContents(), ListSearch.class); }
Example 2
Source File: DaxTrackerServerApi.java From Runescape-Web-Walker-Engine with Apache License 2.0 | 6 votes |
public ListSearch usersOnline(String propertyName, Period period) { ServerResponse serverResponse; Escaper escaper = UrlEscapers.urlFormParameterEscaper(); try { serverResponse = IOHelper.get( TRACKER_ENDPOINT + "/tracker/users/online?" + (propertyName != null ? "&propertyName=" + escaper.escape(propertyName) : "") + (period != null ? "&period=" + period : ""), daxCredentialsProvider ); } catch (IOException e) { e.printStackTrace(); return null; } if (serverResponse.getCode() != HttpURLConnection.HTTP_OK) { log("ERROR: " + new JsonParser().parse(serverResponse.getContents()).getAsJsonObject().get("message").getAsString()); return null; } return new Gson().fromJson(serverResponse.getContents(), ListSearch.class); }
Example 3
Source File: DaxTrackerServerApi.java From Runescape-Web-Walker-Engine with Apache License 2.0 | 6 votes |
public SourceHighScore topSources(String user, String propertyName, Period period) { ServerResponse serverResponse; Escaper escaper = UrlEscapers.urlFormParameterEscaper(); try { serverResponse = IOHelper.get( TRACKER_ENDPOINT + "/tracker/sources/top?propertyName=" + escaper.escape(propertyName) + "&user=" + user + (period != null ? "&period=" + period : ""), daxCredentialsProvider ); } catch (IOException e) { e.printStackTrace(); return null; } if (serverResponse.getCode() != HttpURLConnection.HTTP_OK) { log("ERROR: " + new JsonParser().parse(serverResponse.getContents()).getAsJsonObject().get("message").getAsString()); return null; } return new Gson().fromJson(serverResponse.getContents(), SourceHighScore.class); }
Example 4
Source File: DaxTrackerServerApi.java From Runescape-Web-Walker-Engine with Apache License 2.0 | 6 votes |
public UserHighScore topUsers(String propertyName, Period period) { ServerResponse serverResponse; Escaper escaper = UrlEscapers.urlFormParameterEscaper(); try { serverResponse = IOHelper.get( TRACKER_ENDPOINT + "/tracker/users/top?propertyName=" + escaper.escape(propertyName) + (period != null ? "&period=" + period : ""), daxCredentialsProvider ); } catch (IOException e) { e.printStackTrace(); return null; } if (serverResponse.getCode() != HttpURLConnection.HTTP_OK) { log("ERROR: " + new JsonParser().parse(serverResponse.getContents()).getAsJsonObject().get("message").getAsString()); return null; } return new Gson().fromJson(serverResponse.getContents(), UserHighScore.class); }
Example 5
Source File: DaxTrackerServerApi.java From Runescape-Web-Walker-Engine with Apache License 2.0 | 6 votes |
public PropertyStats getStats(String user, String source, String propertyName) { ServerResponse serverResponse; Escaper escaper = UrlEscapers.urlFormParameterEscaper(); try { serverResponse = IOHelper.get( TRACKER_ENDPOINT + "/tracker/data?user=" + escaper.escape(user) + "&propertyName=" + escaper.escape(propertyName) + (source != null ? "&source=" + escaper.escape(source) : ""), daxCredentialsProvider ); } catch (IOException e) { return null; } if (serverResponse.getCode() != HttpURLConnection.HTTP_OK) { log("ERROR: " + new JsonParser().parse(serverResponse.getContents()).getAsJsonObject().get("message").getAsString()); return null; } return new Gson().fromJson(serverResponse.getContents(), PropertyStats.class); }
Example 6
Source File: BinanceHistoryFilter.java From java-binance-api with MIT License | 6 votes |
public String getAsQuery() { StringBuffer sb = new StringBuffer(); Escaper esc = UrlEscapers.urlFormParameterEscaper(); if (!Strings.isNullOrEmpty(asset)) { sb.append("&asset=").append(esc.escape(asset)); } if (startTime != null) { sb.append("&startTime=").append(startTime.getTime()); } if (endTime != null) { sb.append("&endTime=").append(endTime.getTime()); } String s = sb.toString(); return s.length() > 1 ? s.substring(1) : s; // skipping the first & }
Example 7
Source File: DefaultDockerCmdExecFactory.java From docker-java with Apache License 2.0 | 6 votes |
@Override public InvocationBuilder request() { String resource = StringUtils.join(path, "/"); if (!resource.startsWith("/")) { resource = "/" + resource; } if (!queryParams.isEmpty()) { Escaper urlFormParameterEscaper = UrlEscapers.urlFormParameterEscaper(); resource = queryParams.asMap().entrySet().stream() .flatMap(entry -> { return entry.getValue().stream().map(s -> { return entry.getKey() + "=" + urlFormParameterEscaper.escape(s); }); }) .collect(Collectors.joining("&", resource + "?", "")); } return new DefaultInvocationBuilder( dockerHttpClient, objectMapper, resource ); }
Example 8
Source File: HttpRequest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
public String getPathAndQuery() { String url = this.path; boolean isFirst = true; for (Map.Entry<String, String> queryParameter : this.queryParameters.entries()) { if (isFirst) { url += "?"; isFirst = false; } else { url += "&"; } Escaper escaper = UrlEscapers.urlFormParameterEscaper(); url += escaper.escape(queryParameter.getKey()) + "=" + escaper.escape(queryParameter.getValue()); } return url; }
Example 9
Source File: HttpRequest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
public String getPathAndQuery() { String url = this.path; boolean isFirst = true; for (Map.Entry<String, String> queryParameter : this.queryParameters.entries()) { if (isFirst) { url += "?"; isFirst = false; } else { url += "&"; } Escaper escaper = UrlEscapers.urlFormParameterEscaper(); url += escaper.escape(queryParameter.getKey()) + "=" + escaper.escape(queryParameter.getValue()); } return url; }
Example 10
Source File: UrlFunctions.java From presto with Apache License 2.0 | 5 votes |
@Description("Escape a string for use in URL query parameter names and values") @ScalarFunction @LiteralParameters({"x", "y"}) @Constraint(variable = "y", expression = "min(2147483647, x * 12)") @SqlType("varchar(y)") public static Slice urlEncode(@SqlType("varchar(x)") Slice value) { Escaper escaper = UrlEscapers.urlFormParameterEscaper(); return slice(escaper.escape(value.toStringUtf8())); }
Example 11
Source File: UDFUrlEncode.java From hive-third-functions with Apache License 2.0 | 5 votes |
public Text evaluate(String value) { if (value == null) { return null; } Escaper escaper = UrlEscapers.urlFormParameterEscaper(); result.set(escaper.escape(value)); return result; }
Example 12
Source File: BugReportCommandHandler.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@VisibleForTesting static String formatReportUrl() { String body = MessageFormat.format(BODY_TEMPLATE, CloudToolsInfo.getToolsVersion(), getCloudSdkVersion(), getCloudSdkManagementOption(), CloudToolsInfo.getEclipseVersion(), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("java.version")); Escaper escaper = UrlEscapers.urlFormParameterEscaper(); return BUG_REPORT_URL + "?body=" + escaper.escape(body); }
Example 13
Source File: AdminCollectionController.java From tds with BSD 3-Clause "New" or "Revised" License | 4 votes |
@PostConstruct public void afterPropertiesSet() { Escaper urlParamEscaper = UrlEscapers.urlFormParameterEscaper(); DebugCommands.Category debugHandler = debugCommands.findCategory("Collections"); DebugCommands.Action act; act = new DebugCommands.Action("showCollection", "Show Collections") { public void doAction(DebugCommands.Event e) { // get sorted list of collections List<FeatureCollectionRef> fcList = dataRootManager.getFeatureCollections(); Collections.sort(fcList, (o1, o2) -> o1.getCollectionName().compareTo(o2.getCollectionName())); for (FeatureCollectionRef fc : fcList) { String uriParam = Escape.uriParam(fc.getCollectionName()); String url = tdsContext.getContextPath() + PATH + "/" + SHOW_COLLECTION + "?" + COLLECTION + "=" + uriParam; e.pw.printf("<p/><a href='%s'>%s</a> (%s)%n", url, fc.getCollectionName(), fc.getName()); FeatureCollectionConfig config = fc.getConfig(); if (config != null) e.pw.printf("%s%n", config.spec); } String url = tdsContext.getContextPath() + PATH + "/" + SHOW; e.pw.printf("<p/><a href='%s'>Show All Collection Status</a>%n", url); url = tdsContext.getContextPath() + PATH + "/" + SHOW_CSV; e.pw.printf("<p/><a href='%s'>Collection Status CSV</a>%n", url); url = tdsContext.getContextPath() + PATH + "/" + DOWNLOAD_ALL; e.pw.printf("<p/><a href='%s'>Download All top-level collection indices</a>%n", url); } }; debugHandler.addAction(act); act = new DebugCommands.Action("sched", "Show FeatureCollection update scheduler") { public void doAction(DebugCommands.Event e) { org.quartz.Scheduler scheduler = collectionUpdater.getScheduler(); if (scheduler == null) return; try { e.pw.println(scheduler.getMetaData()); List<String> groups = scheduler.getJobGroupNames(); List<String> triggers = scheduler.getTriggerGroupNames(); // enumerate each job group for (String group : scheduler.getJobGroupNames()) { e.pw.println("Group " + group); // enumerate each job in group for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.<JobKey>groupEquals(group))) { e.pw.println(" Job " + jobKey.getName()); e.pw.println(" " + scheduler.getJobDetail(jobKey)); } // enumerate each trigger in group for (TriggerKey triggerKey : scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(group))) { e.pw.println(" Trigger " + triggerKey.getName()); e.pw.println(" " + scheduler.getTrigger(triggerKey)); } } } catch (Exception e1) { e.pw.println("Error on scheduler " + e1.getMessage()); log.error("Error on scheduler " + e1.getMessage()); } } }; debugHandler.addAction(act); }
Example 14
Source File: BinanceOrderPlacement.java From java-binance-api with MIT License | 4 votes |
public String getAsQuery() throws BinanceApiException { StringBuffer sb = new StringBuffer(); Escaper esc = UrlEscapers.urlFormParameterEscaper(); if (symbol == null) { throw new BinanceApiException("Order Symbol is not set"); } sb.append("&symbol=").append(symbol.toString()); if (side == null) { throw new BinanceApiException("Order side is not set"); } sb.append("&side=").append(side.toString()); if (type == null) { throw new BinanceApiException("Order type is not set"); } sb.append("&type=").append(type.toString()); if (quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) { throw new BinanceApiException("Order quantity should be bigger than zero"); } sb.append("&quantity=").append(quantity.toString()); if (type == BinanceOrderType.MARKET) { // price should be skipped for a market order, we are accepting market price // so should timeInForce } else { if (timeInForce == null) { throw new BinanceApiException("Order timeInForce is not set"); } sb.append("&timeInForce=").append(timeInForce.toString()); if (price == null || price.compareTo(BigDecimal.ZERO) <= 0) { throw new BinanceApiException("Order price should be bigger than zero"); } sb.append("&price=").append(price.toString()); } if (!Strings.isNullOrEmpty(newClientOrderId)) { sb.append("&newClientOrderId=").append(esc.escape(newClientOrderId)); } if (stopPrice != null) { sb.append("&stopPrice=").append(stopPrice.toString()); } if (icebergQty != null) { sb.append("&icebergQty=").append(icebergQty.toString()); } return sb.toString().substring(1); // skipping the first & }
Example 15
Source File: UrlUtils.java From short-url with Apache License 2.0 | 4 votes |
public static String encodeQuery(String query) { Escaper escaper = UrlEscapers.urlFormParameterEscaper(); StringBuilder sb = new StringBuilder(); Iterable<String> keyValueIterable = querySplitter.split(query); Iterator<String> iterator = keyValueIterable.iterator(); while(iterator.hasNext()) { String keyValue = iterator.next(); if (keyValue.isEmpty()) { if (iterator.hasNext()) { sb.append("&"); } continue; } if (keyValue.equals("=")) { sb.append(keyValue); if (iterator.hasNext()) { sb.append("&"); } continue; } int index = keyValue.indexOf('='); if (index == -1) { keyValue = escaper.escape(keyValue); sb.append(keyValue); if (iterator.hasNext()) { sb.append("&"); } continue; } String key = keyValue.substring(0, index); if (index == 0) { key = ""; } String value = ""; if (index + 1 < keyValue.length()) { value = keyValue.substring(index + 1, keyValue.length()); } if (!key.isEmpty()) { key = escaper.escape(key); sb.append(key); sb.append("="); } if (!value.isEmpty()) { value = escaper.escape(value); sb.append(value); if (iterator.hasNext()) { sb.append("&"); } } } return sb.toString(); }
Example 16
Source File: RqFormFakeTest.java From takes with MIT License | 4 votes |
/** * RqFormFake can create fake forms with parameters list. * @throws Exception If something goes wrong. */ @Test public void createsFormRequestWithParams() throws Exception { final String key = "key"; final String akey = "anotherkey"; final String value = "value"; final String avalue = "a&b"; final String aavalue = "againanothervalue"; final Escaper escaper = UrlEscapers.urlFormParameterEscaper(); final RqForm req = new RqFormFake( new RqFake( Arrays.asList( "GET /form", "Host: www.example5.com", String.format( RqFormFakeTest.HEADER, escaper.escape(key).length() + 1 + escaper.escape(value).length() + 1 + escaper.escape(key).length() + 1 + escaper.escape(avalue).length() + 1 + escaper.escape(akey).length() + 1 + escaper.escape(aavalue).length() ) ), "" ), key, value, key, avalue, akey, aavalue ); MatcherAssert.assertThat( req.param(key), Matchers.hasItems(value, avalue) ); MatcherAssert.assertThat( req.param(akey), Matchers.hasItems(aavalue) ); MatcherAssert.assertThat( req.names(), Matchers.hasItems(key, akey) ); }