Refine search
public static Map<String, List<String>> parseQueryString( String queryString ) { Map<String, List<String>> mapOfLists = new HashMap<String, List<String>>(); if ( ( queryString == null ) || ( queryString.length() == 0 ) ) { return mapOfLists; } List<NameValuePair> list = URLEncodedUtils.parse( URI.create( "http://localhost/?" + queryString ), "UTF-8" ); for ( NameValuePair pair : list ) { List<String> values = mapOfLists.get( pair.getName() ); if ( values == null ) { values = new ArrayList<String>(); mapOfLists.put( pair.getName(), values ); } if ( pair.getValue() != null ) { values.add( pair.getValue() ); } } return mapOfLists; } }
public static HttpRequestBody form(Map<String,Object> params, String encoding){ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.size()); for (Map.Entry<String, Object> entry : params.entrySet()) { nameValuePairs.add(new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue()))); } try { return new HttpRequestBody(URLEncodedUtils.format(nameValuePairs, encoding).getBytes(encoding), ContentType.FORM, encoding); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("illegal encoding " + encoding, e); } }
private String getCanonicalQuery(URI uri) { String query = uri.getQuery(); if(query == null || query.isEmpty()) { return ""; } List<NameValuePair> params = URLEncodedUtils.parse(query, StandardCharsets.UTF_8); Collections.sort(params, new Comparator<NameValuePair>() { @Override public int compare(NameValuePair l, NameValuePair r) { return l.getName().compareToIgnoreCase(r.getName()); } }); return URLEncodedUtils.format(params, StandardCharsets.UTF_8); }
/** * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an * {@link HttpEntity}. The encoding is taken from the entity's * Content-Encoding header. * <p> * This is typically used while parsing an HTTP POST. * * @param entity * The entity to parse * @throws IOException * If there was an exception getting the entity's data. */ public static List <NameValuePair> parse ( final HttpEntity entity) throws IOException { List <NameValuePair> result = Collections.emptyList(); if (isEncoded(entity)) { final String content = EntityUtils.toString(entity); final Header encoding = entity.getContentEncoding(); if (content != null && content.length() > 0) { result = new ArrayList <NameValuePair>(); parse(result, new Scanner(content), encoding != null ? encoding.getValue() : null); } } return result; }
public void process(HttpRequest request, HttpContext ctx) throws HttpException, IOException { try { HttpHost host = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST); final URI requestURI = new URI(host.toURI()).resolve(request.getRequestLine().getUri()); OAuthRequest oauthRequest = new OAuthRequest(verb, requestURI.toString(), null); this.service = (OAuth10aService) getOauthService(isOAuth1, addEmptyTokenToBaseString); HttpEntity entity = ((EntityEnclosingRequestWrapper) request).getEntity(); if (entity != null) { List<NameValuePair> params = URLEncodedUtils.parse(entity); for (NameValuePair param : params) { String value = param.getValue() == null ? "" : param.getValue(); oauthRequest.addBodyParameter(param.getName(), value);
try { pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8"); } catch (URISyntaxException e) { throw new ServletException("Unexpected URI parsing error on " + queryString, e); params.put(pair.getName(), pair.getValue()); URI targetUriObj; try { targetUriObj = new URI(newTargetUri); } catch (Exception e) { throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri,e);
private List<NameValuePair> parseQueryParamsFromRequestLine(String requestLine) throws URISyntaxException { // Extract the URL part from the HTTP request line String[] chunks = requestLine.split("\\s", -1); String url = chunks[1]; return URLEncodedUtils.parse(new URI(url), Charset.forName("UTF-8")); }
List<NameValuePair> httpGetParams = URLEncodedUtils.parse(request.getURI().getRawQuery(), Charsets.UTF_8); List<Pair> javaParams = new ArrayList<Pair>(httpGetParams.size()); for (NameValuePair params : httpGetParams) { Pair tuple = new Pair(UrlCodec.encode(params.getName()), UrlCodec.encode(params.getValue())); javaParams.add(tuple); List<NameValuePair> httpPostParams = URLEncodedUtils.parse(postParams, Charsets.UTF_8); Pair tuple = new Pair(UrlCodec.encode(params.getName()), UrlCodec.encode(params.getValue())); javaParams.add(tuple); ); int port = request.getURI().getPort(); if (port <= 0) { if (request.getURI().getScheme().equalsIgnoreCase(HttpConstants.HTTP_SCHEME)) { port = HttpConstants.DEFAULT_HTTP_PORT; } else if (request.getURI().getScheme().equalsIgnoreCase(HttpConstants.HTTPS_SCHEME)) {
public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters) throws UnsupportedEncodingException, URISyntaxException { super(); this.uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); this.method = method; final String query = uri.getQuery(); if(query != null) { parameters.addAll(URLEncodedUtils.parse(uri, "UTF-8")); } this.parameters = parameters; }
public HttpUriRequest getHttpRequest() throws IllegalArgumentException, URISyntaxException, UnsupportedEncodingException { if("GET".equalsIgnoreCase(method)) { final String query = URLEncodedUtils.format(parameters, "UTF-8"); final URI uri = URIUtils.createURI(this.uri.getScheme(), this.uri.getHost(), this.uri.getPort(), this.uri.getPath(), query, null); return new HttpGet(uri); } else if("POST".equalsIgnoreCase(method)) { final HttpPost post = new HttpPost(uri); post.setEntity(new UrlEncodedFormEntity(parameters)); return post; } else { throw new IllegalArgumentException(method + " is not a supported HTTP method."); } }
public static void markForumAsRead(IHttpClient httpClient, CharSequence forumId) throws Throwable { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("act", "login")); qparams.add(new BasicNameValuePair("CODE", "04")); qparams.add(new BasicNameValuePair("f", forumId.toString())); qparams.add(new BasicNameValuePair("fromforum", forumId.toString())); URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php", URLEncodedUtils.format(qparams, "UTF-8"), null); httpClient.performGet(uri.toString()); } }
private Map<String, List<String>> parseUrlEncodedBody() { try (InputStream inputStream = getInputStream()) { Map<String, List<String>> listMap = new HashMap<>(); String body = IOUtils.toString(inputStream); List<NameValuePair> pairs = URLEncodedUtils .parse(body, getCharacterEncoding() == null ? null : Charset.forName(getCharacterEncoding())); for (NameValuePair pair : pairs) { List<String> values = listMap.computeIfAbsent(pair.getName(), k -> new ArrayList<>()); values.add(pair.getValue()); } return listMap; } catch (IOException e) { throw new IllegalStateException("", e); } }
if (!configKey.getScheme().equals(getScheme())) { throw new ConfigStoreCreationException(configKey, "Config key URI must have scheme " + getScheme()); for (NameValuePair param : URLEncodedUtils.parse(configKey, "UTF-8")) { factoryProps.setProperty(param.getName(), param.getValue()); FileSystem zipFs = FileSystems.newFileSystem(Paths.get(uris[0].getPath()), null);
/** * Constructs a new {@link UrlEncodedFormEntity} with the list * of parameters in the specified encoding. * * @param parameters list of name/value pairs * @param charset encoding the name/value pairs be encoded with * @throws UnsupportedEncodingException if the encoding isn't supported */ public UrlEncodedFormEntity ( final List <? extends NameValuePair> parameters, final String charset) throws UnsupportedEncodingException { super(URLEncodedUtils.format(parameters, charset != null ? charset : HTTP.DEF_CONTENT_CHARSET.name()), ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset)); }
private List<YoutubeTrackFormat> loadTrackFormatsFromAdaptive(String adaptiveFormats) throws Exception { List<YoutubeTrackFormat> tracks = new ArrayList<>(); for (String formatString : adaptiveFormats.split(",")) { Map<String, String> format = convertToMapLayout(URLEncodedUtils.parse(formatString, Charset.forName(CHARSET))); tracks.add(new YoutubeTrackFormat( ContentType.parse(format.get("type")), Long.parseLong(format.get("bitrate")), Long.parseLong(format.get("clen")), format.get("url"), format.get("s"), format.getOrDefault("sp", DEFAULT_SIGNATURE_KEY) )); } return tracks; }
@Test(groups = {"Integration","Broken"}) public void testInteractionOfSecurityFilterAndFormMapProvider() throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); try { Server server = useServerForTest(baseLauncher() .forceUseOfDefaultCatalogWithJavaClassPath(true) .withoutJsgui() .start()); String appId = startAppAtNode(server); String entityId = getTestEntityInApp(server, appId); HttpClient client = HttpTool.httpClientBuilder() .uri(getBaseUriRest()) .build(); List<? extends NameValuePair> nvps = Lists.newArrayList( new BasicNameValuePair("arg", "bar")); String effector = String.format("/applications/%s/entities/%s/effectors/identityEffector", appId, entityId); HttpToolResponse response = HttpTool.httpPost(client, URI.create(getBaseUriRest() + effector), ImmutableMap.of(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.getMimeType()), URLEncodedUtils.format(nvps, Charsets.UTF_8).getBytes()); LOG.info("Effector response: {}", response.getContentAsString()); assertTrue(HttpTool.isStatusCodeHealthy(response.getResponseCode()), "response code=" + response.getResponseCode()); } finally { LOG.info("testInteractionOfSecurityFilterAndFormMapProvider complete in " + Time.makeTimeStringRounded(stopwatch)); } }