org.apache.http.client.utils.URLEncodedUtils Java Examples
The following examples show how to use
org.apache.http.client.utils.URLEncodedUtils.
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: HwYunMsgSender.java From WePush with MIT License | 6 votes |
/** * 构造请求Body体 * * @param sender * @param receiver * @param templateId * @param templateParas * @param statusCallbackUrl * @param signature | 签名名称,使用国内短信通用模板时填写 * @return */ static String buildRequestBody(String sender, String receiver, String templateId, String templateParas, String statusCallbackUrl, String signature) { if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() || templateId.isEmpty()) { System.out.println("buildRequestBody(): sender, receiver or templateId is null."); return null; } List<NameValuePair> keyValues = new ArrayList<>(); keyValues.add(new BasicNameValuePair("from", sender)); keyValues.add(new BasicNameValuePair("to", receiver)); keyValues.add(new BasicNameValuePair("templateId", templateId)); if (null != templateParas && !templateParas.isEmpty()) { keyValues.add(new BasicNameValuePair("templateParas", templateParas)); } if (null != statusCallbackUrl && !statusCallbackUrl.isEmpty()) { keyValues.add(new BasicNameValuePair("statusCallback", statusCallbackUrl)); } if (null != signature && !signature.isEmpty()) { keyValues.add(new BasicNameValuePair("signature", signature)); } return URLEncodedUtils.format(keyValues, Charset.forName("UTF-8")); }
Example #2
Source File: CaseModelsResource.java From flowable-engine with Apache License 2.0 | 6 votes |
@GetMapping(produces = "application/json") public ResultListDataRepresentation getCaseModels(HttpServletRequest request) { // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing. String filter = null; String excludeId = null; List<NameValuePair> params = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8")); if (params != null) { for (NameValuePair nameValuePair : params) { if ("filter".equalsIgnoreCase(nameValuePair.getName())) { filter = nameValuePair.getValue(); } else if ("excludeId".equalsIgnoreCase(nameValuePair.getName())) { excludeId = nameValuePair.getValue(); } } } return caseService.getCases(filter, excludeId); }
Example #3
Source File: HttpUtil.java From anyline with Apache License 2.0 | 6 votes |
public static HttpResult get(CloseableHttpClient client, Map<String, String> headers, String url, String encode, List<NameValuePair> pairs) { if(null == client){ if(url.contains("https://")){ client = defaultSSLClient(); }else{ client = defaultClient(); } } if(url.startsWith("//")){ url = "http:" + url; } HttpResult result = new HttpResult(); if (null != pairs && !pairs.isEmpty()) { String params = URLEncodedUtils.format(pairs,encode); if (url.contains("?")) { url += "&" + params; } else { url += "?" + params; } } HttpGet method = new HttpGet(url); setHeader(method, headers); result = exe(client, method, encode); return result; }
Example #4
Source File: HttpUtil.java From anyline with Apache License 2.0 | 6 votes |
public static HttpResult delete(CloseableHttpClient client, Map<String, String> headers, String url, String encode, List<NameValuePair> pairs) { if(null == client){ if(url.contains("https://")){ client = defaultSSLClient(); }else{ client = defaultClient(); } } if(url.startsWith("//")){ url = "http:" + url; } HttpResult result = new HttpResult(); if (null != pairs) { String params = URLEncodedUtils.format(pairs,encode); if (url.contains("?")) { url += "&" + params; } else { url += "?" + params; } } HttpDelete method = new HttpDelete(url); setHeader(method, headers); result = exe(client, method, encode); return result; }
Example #5
Source File: UriUtils.java From cosmic with Apache License 2.0 | 6 votes |
public static boolean cifsCredentialsPresent(final URI uri) { final List<NameValuePair> args = URLEncodedUtils.parse(uri, "UTF-8"); boolean foundUser = false; boolean foundPswd = false; for (final NameValuePair nvp : args) { final String name = nvp.getName(); if (name.equals("user")) { foundUser = true; s_logger.debug("foundUser is" + foundUser); } else if (name.equals("password")) { foundPswd = true; s_logger.debug("foundPswd is" + foundPswd); } } return (foundUser && foundPswd); }
Example #6
Source File: HttpClientUtil.java From charging_pile_cloud with MIT License | 6 votes |
/** * 封装HTTP GET方法 * * @param * @param * @return */ public static String get(String url, Map<String, String> paramMap) throws ClientProtocolException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(); List<NameValuePair> formparams = setHttpParams(paramMap); String param = URLEncodedUtils.format(formparams, "UTF-8"); httpGet.setURI(URI.create(url + "?" + param)); HttpResponse response = httpClient.execute(httpGet); String httpEntityContent = getHttpEntityContent(response); httpGet.abort(); return httpEntityContent; }
Example #7
Source File: Entry.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
public JSONArray getParams(ResourceTimings e) { JSONArray paramList = new JSONArray(); try { List<NameValuePair> params = URLEncodedUtils.parse(new URI(e.name), "UTF-8"); for (NameValuePair pair : params) { JSONObject jsonPair = new JSONObject(); jsonPair.put("name", pair.getName()); jsonPair.put("value", pair.getValue()); paramList.add(jsonPair); } } catch (Exception ex) { return paramList; } return paramList; }
Example #8
Source File: JavaScriptResponseHandlerImpl.java From smockin with Apache License 2.0 | 6 votes |
Map<String, String> extractAllRequestParams(final Request req) { // Java Spark does not provide a convenient way of extracting form based request parameters, // so have to parse these manually. if (req.contentType() != null && (req.contentType().contains(MediaType.APPLICATION_FORM_URLENCODED_VALUE) || req.contentType().contains(MediaType.MULTIPART_FORM_DATA_VALUE))) { return URLEncodedUtils.parse(req.body(), Charset.defaultCharset()) .stream() .collect(HashMap::new, (m, v) -> m.put(v.getName(), v.getValue()), HashMap::putAll); } return req.queryParams() .stream() .collect(Collectors.toMap(k -> k, k -> req.queryParams(k))); }
Example #9
Source File: UrlEncodingUtils.java From vertx-s3-client with Apache License 2.0 | 6 votes |
public static String addParamsSortedToUrl(String url, Map<String, String> params) { checkNotNull(url, "url must not be null"); checkNotNull(!url.isEmpty(), "url must not be empty"); checkNotNull(params, "params must not be null"); checkNotNull(!params.isEmpty(), "params must not be empty"); final String baseUrl = extractBaseUrl(url); final String urlParams = baseUrl.equals(url) ? "" : url.replace(baseUrl + "?", ""); final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(urlParams, Charsets.UTF_8); for (Map.Entry<String, String> paramToUrlEncode : params.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).collect(Collectors.toList())) { nameValuePairs.add(new BasicNameValuePair(paramToUrlEncode.getKey(), paramToUrlEncode.getValue())); } return baseUrl + "?" + URLEncodedUtils.format(nameValuePairs, Charsets.UTF_8); }
Example #10
Source File: GeneralUtils.java From smockin with Apache License 2.0 | 6 votes |
public static Map<String, String> extractAllRequestParams(final Request req) { final Map<String, String> allParams = req.queryMap() .toMap() .entrySet() .stream() .collect(HashMap::new, (m,v) -> m.put(v.getKey(), (v.getValue() != null && v.getValue().length != 0) ? v.getValue()[0] : null), HashMap::putAll); if (req.contentType() != null && (req.contentType().contains(MediaType.APPLICATION_FORM_URLENCODED_VALUE) || req.contentType().contains(MediaType.MULTIPART_FORM_DATA_VALUE))) { if (req.body() != null) { allParams.putAll(URLEncodedUtils.parse(req.body(), Charset.defaultCharset()) .stream() .collect(HashMap::new, (m,v) -> m.put(v.getName(), v.getValue()), HashMap::putAll)); } } return allParams; }
Example #11
Source File: UrlParametersExtractor.java From AuTe-Framework with Apache License 2.0 | 6 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public Map<String, Object> extractQueryParameters(URL url) { if (url == null) { return Collections.emptyMap(); } List<NameValuePair> parameters = URLEncodedUtils.parse(url.getQuery(), StandardCharsets.UTF_8); Map<String, Object> result = new LinkedHashMap<>(); for (NameValuePair parameter : parameters) { if (result.containsKey(parameter.getName())) { Object currentValue = result.get(parameter.getName()); if (currentValue instanceof List) { ((List) currentValue).add(parameter.getValue()); } else { List<Object> values = new ArrayList<>(); values.add(currentValue); values.add(parameter.getValue()); result.put(parameter.getName(), values); } } else { result.put(parameter.getName(), parameter.getValue()); } } return result; }
Example #12
Source File: AbstractTransport.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
private String genAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) { if (addressWithoutSchema == null || pairs == null || pairs.isEmpty()) { return addressWithoutSchema; } int idx = addressWithoutSchema.indexOf('?'); if (idx == -1) { addressWithoutSchema += "?"; } else { addressWithoutSchema += "&"; } String encodedQuery = URLEncodedUtils.format(pairs.entrySet().stream().map(entry -> { return new BasicNameValuePair(entry.getKey(), entry.getValue()); }).collect(Collectors.toList()), StandardCharsets.UTF_8.name()); addressWithoutSchema += encodedQuery; return addressWithoutSchema; }
Example #13
Source File: Application.java From dr-elephant with Apache License 2.0 | 6 votes |
/** * Parses the request for the queryString * * @return URL Encoded String of Parameter Value Pair */ public static String getQueryString() { List<BasicNameValuePair> fields = new LinkedList<BasicNameValuePair>(); final Set<Map.Entry<String, String[]>> entries = request().queryString().entrySet(); for (Map.Entry<String, String[]> entry : entries) { final String key = entry.getKey(); final String value = entry.getValue()[0]; if (!key.equals(PAGE)) { fields.add(new BasicNameValuePair(key, value)); } } if (fields.isEmpty()) { return null; } else { return URLEncodedUtils.format(fields, "utf-8"); } }
Example #14
Source File: HuaweiSMSUtil.java From xnx3 with Apache License 2.0 | 6 votes |
/** * 构造请求Body体 * @param sender * @param receiver * @param templateId * @param templateParas * @param statusCallbackUrl * @param signature | 签名名称,使用国内短信通用模板时填写 * @return */ static String buildRequestBody(String sender, String receiver, String templateId, String templateParas, String statusCallbackUrl, String signature) { if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() || templateId.isEmpty()) { System.out.println("buildRequestBody(): sender, receiver or templateId is null."); return null; } List<NameValuePair> keyValues = new ArrayList<NameValuePair>(); keyValues.add(new BasicNameValuePair("from", sender)); keyValues.add(new BasicNameValuePair("to", receiver)); keyValues.add(new BasicNameValuePair("templateId", templateId)); if (null != templateParas && !templateParas.isEmpty()) { keyValues.add(new BasicNameValuePair("templateParas", templateParas)); } if (null != statusCallbackUrl && !statusCallbackUrl.isEmpty()) { keyValues.add(new BasicNameValuePair("statusCallback", statusCallbackUrl)); } if (null != signature && !signature.isEmpty()) { keyValues.add(new BasicNameValuePair("signature", signature)); } return URLEncodedUtils.format(keyValues, Charset.forName("UTF-8")); }
Example #15
Source File: BridgeWebSocketServer.java From webapp-hardware-bridge with MIT License | 6 votes |
@Override public void onOpen(WebSocket connection, ClientHandshake handshake) { try { String descriptor = handshake.getResourceDescriptor(); URI uri = new URI(descriptor); String channel = uri.getPath(); List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8); String token = getToken(params); if (settingService.getSetting().getAuthenticationEnabled() && (token == null || !token.equals(settingService.getSetting().getAuthenticationToken()))) { connection.close(CloseFrame.REFUSE, "Token Mismatch"); return; } connection.setAttachment(new ConnectionAttachment(channel, params, token)); addSocketToChannel(channel, connection); logger.info(connection.getRemoteSocketAddress().toString() + " connected to " + channel); } catch (URISyntaxException e) { logger.error(connection.getRemoteSocketAddress().toString() + " error", e); connection.close(); } }
Example #16
Source File: HttpUtil.java From Shour with MIT License | 6 votes |
private static HttpGet buildGet(String url, Map<String, String> params) { StringBuilder sb = new StringBuilder(url); if (params != null && params.size() > 0) { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); Iterator iterator = params.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> entry = (Map.Entry) iterator.next(); nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } sb.append("?"); sb.append(URLEncodedUtils.format(nameValuePairs, DEFAULT_CHARSET)); } HttpGet httpGet = new HttpGet(sb.toString()); httpGet.setHeader("Accept-Encoding", ""); return httpGet; }
Example #17
Source File: APKExpansionPolicy.java From vpn-over-dns with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Map<String, String> decodeExtras(String extras) { Map<String, String> results = new HashMap<String, String>(); try { URI rawExtras = new URI("?" + extras); List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8"); for (NameValuePair item : extraList) { String name = item.getName(); int i = 0; while (results.containsKey(name)) { name = item.getName() + ++i; } results.put(name, item.getValue()); } } catch (URISyntaxException e) { Log.w(TAG, "Invalid syntax error while decoding extras data from server."); } return results; }
Example #18
Source File: HttpUtil.java From common-project with Apache License 2.0 | 6 votes |
public static Map<String, String> paraseURI(String uri) { try { if (!uri.startsWith("?")) { uri = "?".concat(uri); } HashMap<String, String> map = new HashMap<String, String>(); List<NameValuePair> parse = URLEncodedUtils.parse(new URI(uri), CHARSET_NAME); for (NameValuePair nameValuePair : parse) { map.put(nameValuePair.getName(), nameValuePair.getValue()); } return map; } catch (Exception e) { logger.error("parase uri error", e); } return null; }
Example #19
Source File: APKExpansionPolicy.java From text_converter with GNU General Public License v3.0 | 6 votes |
private Map<String, String> decodeExtras(String extras) { Map<String, String> results = new HashMap<String, String>(); try { URI rawExtras = new URI("?" + extras); List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8"); for (NameValuePair item : extraList) { String name = item.getName(); int i = 0; while (results.containsKey(name)) { name = item.getName() + ++i; } results.put(name, item.getValue()); } } catch (URISyntaxException e) { Log.w(TAG, "Invalid syntax error while decoding extras data from server."); } return results; }
Example #20
Source File: GitLabSecurityRealm.java From gitlab-oauth-plugin with MIT License | 6 votes |
public HttpResponse doCommenceLogin(StaplerRequest request, @QueryParameter String from, @Header("Referer") final String referer) throws IOException { // 2. Requesting authorization : // http://doc.gitlab.com/ce/api/oauth2.html String redirectOnFinish; if (from != null && Util.isSafeToRedirectTo(from)) { redirectOnFinish = from; } else if (referer != null && (referer.startsWith(Jenkins.getInstance().getRootUrl()) || Util.isSafeToRedirectTo(referer))) { redirectOnFinish = referer; } else { redirectOnFinish = Jenkins.getInstance().getRootUrl(); } List<NameValuePair> parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("redirect_uri", buildRedirectUrl(request, redirectOnFinish))); parameters.add(new BasicNameValuePair("response_type", "code")); parameters.add(new BasicNameValuePair("client_id", clientID)); return new HttpRedirect(gitlabWebUri + "/oauth/authorize?" + URLEncodedUtils.format(parameters, StandardCharsets.UTF_8)); }
Example #21
Source File: NicoAudioTrack.java From kyoko with MIT License | 6 votes |
private String loadPlaybackUrl(HttpInterface httpInterface) throws IOException { HttpGet request = new HttpGet("http://flapi.nicovideo.jp/api/getflv/" + trackInfo.identifier); try (CloseableHttpResponse response = httpInterface.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { throw new IOException("Unexpected status code from playback parameters page: " + statusCode); } String text = EntityUtils.toString(response.getEntity()); Map<String, String> format = convertToMapLayout(URLEncodedUtils.parse(text, StandardCharsets.UTF_8)); String url = format.get("url"); try (CloseableHttpResponse testResponse = httpInterface.execute(new HttpGet(url))) { int testStatusCode = testResponse.getStatusLine().getStatusCode(); if (testStatusCode != 200) { url = url.replace("/smile?v=", "/smile?m="); url += "low"; } } return url; } }
Example #22
Source File: HarborClient.java From harbor-java-client with Apache License 2.0 | 6 votes |
/** * Let user see the recent operation logs of the projects which he is member * of.</br> * <b>URL</b>: /logs</br> * <b>Method</b>: GET * * @param lines * (The number of logs to be shown, default is 10 if lines, * start_time, end_time are not provided) * @param startTime * (The start time of logs to be shown in unix timestap) * @param endTime * (The end time of logs to be shown in unix timestap) * @return required logs. * @throws IOException * @throws HarborClientException */ public List<Log> getLogs(String lines, String startTime, String endTime) throws IOException, HarborClientException { logger.debug("get logs lines %s, start time %s, end time %s", lines, startTime, endTime); List<NameValuePair> qparams = new ArrayList<>(); qparams.add(new BasicNameValuePair("lines", lines)); qparams.add(new BasicNameValuePair("start_time", startTime)); qparams.add(new BasicNameValuePair("end_time", endTime)); qparams.removeIf(o -> Objects.isNull(o.getValue())); String url = getBaseUrl() + "/logs?" + URLEncodedUtils.format(qparams, "UTF-8"); Request request = new Request.Builder().url(url).get().build(); Response response = okhttpClient.newCall(request).execute(); logger.debug(String.format(REQUEST_RESPONSE_INFO, request, response)); if (response.code() != 200) { throw new HarborClientException(String.valueOf(response.code()), response.message()); } return mapper.readValue(response.body().string(), new TypeReference<List<Log>>() { }); }
Example #23
Source File: RequestPredicateImpl.java From bobcat with Apache License 2.0 | 6 votes |
@Override public boolean accepts(HttpRequest request) { boolean result = false; URI uri = URI.create(request.getUri()); String path = uri.getPath(); if (path != null && path.startsWith(urlPrefix)) { String query = uri.getQuery(); if (expectedParams.isEmpty() && StringUtils.isEmpty(query)) { result = true; } else if (StringUtils.isNotEmpty(query)) { List<NameValuePair> params = URLEncodedUtils.parse(query, Charsets.UTF_8); result = hasAllExpectedParams(expectedParams, params); } } return result; }
Example #24
Source File: APKExpansionPolicy.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
private Map<String, String> decodeExtras(String extras) { Map<String, String> results = new HashMap<String, String>(); try { URI rawExtras = new URI("?" + extras); List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8"); for (NameValuePair item : extraList) { String name = item.getName(); int i = 0; while (results.containsKey(name)) { name = item.getName() + ++i; } results.put(name, item.getValue()); } } catch (URISyntaxException e) { Log.w(TAG, "Invalid syntax error while decoding extras data from server."); } return results; }
Example #25
Source File: SolrSearcher.java From q with Apache License 2.0 | 6 votes |
public String getUrlForGettingDoc(String q, List<String> languages, String dataSetId) { List<NameValuePair> parameters = Lists.newArrayList(); parameters.add(new BasicNameValuePair("q", getPhraseQueryString(q))); parameters.add(new BasicNameValuePair("defType", "edismax")); parameters.add(new BasicNameValuePair("lowercaseOperators", "false")); parameters.add(new BasicNameValuePair("rows", "100000")); parameters.add(new BasicNameValuePair("qs", "10")); parameters.add(new BasicNameValuePair("fl", Properties.idField.get() + ", " + Properties.titleFields.get().get(0) + "_en")); parameters.add(new BasicNameValuePair("sort", Properties.idField.get() + " DESC")); parameters.add(new BasicNameValuePair("qf", getQueryFields(languages))); parameters.add(new BasicNameValuePair("fq", Properties.docTypeFieldName.get() + ":" + dataSetId)); parameters.add(new BasicNameValuePair("wt", "json")); return getServerUrl() + "/select?" + URLEncodedUtils.format(parameters, BaseIndexer.ENCODING); }
Example #26
Source File: QQOauthPlugin.java From java-platform with Apache License 2.0 | 6 votes |
@Override public String getAccessToken(String code) { Assert.hasText(code); Map<String, Object> parameterMap = new HashMap<>(); parameterMap.put("grant_type", "authorization_code"); parameterMap.put("client_id", getClientId()); parameterMap.put("client_secret", getClientSecret()); parameterMap.put("code", code); parameterMap.put("redirect_uri", getRedirectUri()); String responseString = get("https://graph.qq.com/oauth2.0/token", parameterMap); List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(responseString, Charset.forName("utf-8")); Map<String, Object> result = new HashMap<>(); for (NameValuePair nameValuePair : nameValuePairs) { result.put(nameValuePair.getName(), nameValuePair.getValue()); } return getParameter(nameValuePairs, "access_token"); }
Example #27
Source File: DelegationTokenAuthenticationFilter.java From hadoop with Apache License 2.0 | 5 votes |
@VisibleForTesting static String getDoAs(HttpServletRequest request) { List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET); if (list != null) { for (NameValuePair nv : list) { if (DelegationTokenAuthenticatedURL.DO_AS. equalsIgnoreCase(nv.getName())) { return nv.getValue(); } } } return null; }
Example #28
Source File: QueryParamsAssertion.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private List<NameValuePair> parseNameValuePairsFromQuery(LoggedRequest actual) { String queryParams = URI.create(actual.getUrl()).getQuery(); if (StringUtils.isEmpty(queryParams)) { return Collections.emptyList(); } return URLEncodedUtils.parse(queryParams, StandardCharsets.UTF_8); }
Example #29
Source File: TFSRestConnection.java From FortifyBugTrackerUtility with MIT License | 5 votes |
private String getIssueId(TargetIssueLocator targetIssueLocator) { String id = targetIssueLocator.getId(); if ( StringUtils.isBlank(id) ) { String deepLink = targetIssueLocator.getDeepLink(); @SuppressWarnings("deprecation") List<NameValuePair> params = URLEncodedUtils.parse(URI.create(deepLink), "UTF-8"); for (NameValuePair param : params) { if ( "id".equals(param.getName()) ) { return param.getValue(); } } } return id; }
Example #30
Source File: HttpServerUtilities.java From Repeat with Apache License 2.0 | 5 votes |
public static Map<String, String> parseGetParameters(String url) { try { List<NameValuePair> paramList = URLEncodedUtils.parse(new URI(url), StandardCharsets.UTF_8); Map<String, String> params = new HashMap<>(); for (NameValuePair param : paramList) { params.put(param.getName(), param.getValue()); } return params; } catch (URISyntaxException e) { LOGGER.log(Level.WARNING, "Exception when parsing URL.", e); return null; } }