List of usage examples for org.apache.http.client.utils URIBuilder getQueryParams
public List<NameValuePair> getQueryParams()
From source file:com.thoughtworks.go.http.mocks.HttpRequestBuilder.java
private static Map<String, List<String>> splitQuery(URIBuilder builder) { Map<String, List<String>> params = new LinkedHashMap<>(); for (NameValuePair nameValuePair : builder.getQueryParams()) { if (!params.containsKey(nameValuePair.getName())) { params.put(nameValuePair.getName(), new ArrayList<>()); }/* w ww .j av a 2s .c om*/ params.get(nameValuePair.getName()).add(nameValuePair.getValue()); } return params; }
From source file:it.txt.ens.core.util.parser.ENSResourceURIParser.java
public static ENSResource parse(URI ensResourceURI, ENSResourceFactory factory) throws URIParseException, IllegalArgumentException { // LOGGER.fine("1.1"); URIBuilder builder = new URIBuilder(ensResourceURI); // LOGGER.fine("1.2"); String scheme = builder.getScheme(); // LOGGER.fine("1.3"); if (ENSResource.URI_SCHEME.equals(scheme)) { // LOGGER.fine("1.4"); List<NameValuePair> parameters = builder.getQueryParams(); // LOGGER.fine("1.5"); if (parameters.size() == NUMBER_OF_QUERY_PARAMETERS) { // LOGGER.fine("1.6"); String namespace;//from w w w .j av a 2 s. c o m String pattern; NameValuePair param1 = parameters.get(0); // LOGGER.fine("1.7"); NameValuePair param2 = parameters.get(1); // LOGGER.fine("1.8"); if (ENSResource.NAMESPACE_PARAMETER_NAME.equals(param1.getName())) { // LOGGER.fine("1.8.1.1"); namespace = param1.getValue(); // LOGGER.fine("1.8.1.2"); } else if (ENSResource.NAMESPACE_PARAMETER_NAME.equals(param2.getName())) { // LOGGER.fine("1.8.2.1"); namespace = param2.getValue(); // LOGGER.fine("1.8.2.2"); } else throw new URIParseException( MessageFormat.format(MESSAGES.getString("URIParser.parse.missingQueryParameter"), ENSResource.NAMESPACE_PARAMETER_NAME)); // LOGGER.fine("1.9"); if (ENSResource.PATTERN_PARAMETER_NAME.equals(param1.getName())) { // LOGGER.fine("1.9.1.1"); pattern = param1.getValue(); // LOGGER.fine("1.9.1.2"); } else if (ENSResource.PATTERN_PARAMETER_NAME.equals(param2.getName())) { // LOGGER.fine("1.9.2.1"); pattern = param2.getValue(); // LOGGER.fine("1.9.2.2"); } else throw new URIParseException( MessageFormat.format(MESSAGES.getString("URIParser.parse.missingQueryParameter"), ENSResource.PATTERN_PARAMETER_NAME)); try { // LOGGER.fine("1.10"); builder.getHost(); // LOGGER.fine("1.11"); builder.getPath(); // LOGGER.fine("1.12"); return factory.create(builder.getHost(), builder.getPath(), namespace, pattern); } catch (URIBuildingException e) { throw new URIParseException("An unexpected exception occurred while creating the ENS resource", e); } } else throw new URIParseException( MessageFormat.format(MESSAGES.getString("URIParser.parse.unexpectedNumberOfQueryParams"), parameters.size(), NUMBER_OF_QUERY_PARAMETERS)); } else throw new URIParseException(MessageFormat.format(MESSAGES.getString("URIParser.parse.unexpectedScheme"), scheme, ENSResource.URI_SCHEME)); }
From source file:com.askfast.askfastapi.util.HttpUtil.java
/** * Retrieve the query parameters from given url * /* w w w. j a v a 2 s . c o m*/ * @param url * Url containing query parameters * @return params Map with query parameters * @throws IOException * Errors in connecting to the given URL */ static public Map<String, String> getQueryParams(String url) throws IOException { Map<String, String> params = new HashMap<String, String>(); try { url = url.replace(" ", "%20"); URIBuilder uriBuilder = new URIBuilder(new URI(url)); for (NameValuePair nameValue : uriBuilder.getQueryParams()) { params.put(nameValue.getName(), nameValue.getValue()); } } catch (Exception e) { e.printStackTrace(); } return params; }
From source file:org.wso2.carbon.identity.captcha.util.CaptchaUtil.java
public static String getOnFailRedirectUrl(String referrerUrl, List<String> onFailRedirectUrls, Map<String, String> attributes) { if (StringUtils.isBlank(referrerUrl) || onFailRedirectUrls.isEmpty()) { return getErrorPage("Human Verification Failed.", "Something went wrong. Please try again."); }/*from w w w . j a v a 2 s . c om*/ URIBuilder uriBuilder; try { uriBuilder = new URIBuilder(referrerUrl); } catch (URISyntaxException e) { return getErrorPage("Human Verification Failed.", "Something went wrong. Please try again."); } for (String url : onFailRedirectUrls) { if (!StringUtils.isBlank(url) && url.equalsIgnoreCase(uriBuilder.getPath())) { for (NameValuePair pair : uriBuilder.getQueryParams()) { attributes.put(pair.getName(), pair.getValue()); } return getUpdatedUrl(url, attributes); } } return getErrorPage("Human Verification Failed.", "Something went wrong. Please try again."); }
From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java
public static Entity deserializeUriEntity(final URI uri) throws SmartUriException { final String uriString = uri.stringValue(); final int fragmentPosition = uriString.indexOf("#"); String prefix = uriString.substring(0, fragmentPosition + 1); if (fragmentPosition == -1) { prefix = uriString.split("\\?", 2)[0]; }//from ww w . j a v a2 s . c o m final String fragment = uriString.substring(fragmentPosition + 1, uriString.length()); java.net.URI queryUri; URIBuilder uriBuilder = null; try { if (fragmentPosition > -1) { queryUri = new java.net.URI("urn://" + fragment); } else { queryUri = new java.net.URI(uriString); } uriBuilder = new URIBuilder(queryUri); } catch (final URISyntaxException e) { throw new SmartUriException("Unable to deserialize Smart URI", e); } final RyaURI subject = findSubject(uri.stringValue()); final List<NameValuePair> parameters = uriBuilder.getQueryParams(); Map<RyaURI, String> entityTypeMap = new LinkedHashMap<>(); Map<String, RyaURI> invertedEntityTypeMap = new LinkedHashMap<>(); final Map<RyaURI, Map<URI, Value>> fullMap = new LinkedHashMap<>(); for (final NameValuePair pair : parameters) { final String keyString = pair.getName(); final String valueString = pair.getValue(); final URI keyUri = new URIImpl(prefix + keyString); final String decoded; try { decoded = URLDecoder.decode(valueString, Charsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new SmartUriException("", e); } final URI type = TypeDeterminer.determineType(decoded); if (type == XMLSchema.ANYURI) { if (keyString.equals(RYA_TYPES_URI.getLocalName())) { entityTypeMap = convertUriToTypeMap(new URIImpl(decoded)); invertedEntityTypeMap = HashBiMap.create(entityTypeMap).inverse(); } } else { final int keyPrefixLocation = keyString.indexOf("."); final String keyPrefix = keyString.substring(0, keyPrefixLocation); final RyaURI keyCorrespondingType = invertedEntityTypeMap.get(keyPrefix); final String keyName = keyString.substring(keyPrefixLocation + 1, keyString.length()); final RyaType ryaType = new RyaType(type, valueString); final Value value = RyaToRdfConversions.convertValue(ryaType); final String formattedKeyUriString = removeTypePrefixFromUri(keyUri.stringValue(), keyPrefix); final URI formattedKeyUri = new URIImpl(formattedKeyUriString); final Map<URI, Value> map = fullMap.get(keyCorrespondingType); if (map == null) { final Map<URI, Value> subMap = new HashMap<>(); subMap.put(formattedKeyUri, value); fullMap.put(keyCorrespondingType, subMap); } else { map.put(formattedKeyUri, value); fullMap.put(keyCorrespondingType, map); } } } final Entity entity = convertMapToEntity(subject, fullMap); return entity; }
From source file:net.javacrumbs.restfire.httpcomponents.HttpComponentsRequestBuilder.java
private void copyParamsIfNeeded(URIBuilder newUriBuilder) { if (newUriBuilder.getQueryParams().isEmpty() && !uriBuilder.getQueryParams().isEmpty()) { //there were parameters set which would be overwritten for (NameValuePair param : uriBuilder.getQueryParams()) { newUriBuilder.addParameter(param.getName(), param.getValue()); }//from w w w.ja va 2s . c o m } }
From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java
/** * Deserializes a URI into a map of URI's to values. * @param uri the {@link URI}.//from w w w .j a v a 2 s. c o m * @return the {@link Map} of {@link URI}s to {@link Value}s. * @throws SmartUriException */ public static Map<URI, Value> deserializeUri(final URI uri) throws SmartUriException { final String uriString = uri.stringValue(); final int fragmentPosition = uriString.indexOf("#"); String prefix = uriString.substring(0, fragmentPosition + 1); if (fragmentPosition == -1) { prefix = uriString.split("\\?", 2)[0]; } final String fragment = uriString.substring(fragmentPosition + 1, uriString.length()); java.net.URI queryUri; URIBuilder uriBuilder = null; try { if (fragmentPosition > -1) { queryUri = new java.net.URI("urn://" + fragment); } else { queryUri = new java.net.URI(uriString); } uriBuilder = new URIBuilder(queryUri); } catch (final URISyntaxException e) { throw new SmartUriException("Unable to deserialize Smart URI", e); } final Map<URI, Value> map = new HashMap<>(); final RyaURI subject = findSubject(uri.stringValue()); final List<NameValuePair> parameters = uriBuilder.getQueryParams(); Map<RyaURI, String> entityTypeMap = new LinkedHashMap<>(); Map<String, RyaURI> invertedEntityTypeMap = new LinkedHashMap<>(); final Map<RyaURI, Map<URI, Value>> fullMap = new LinkedHashMap<>(); for (final NameValuePair pair : parameters) { final String keyString = pair.getName(); final String valueString = pair.getValue(); final URI keyUri = new URIImpl(prefix + keyString); final String decoded; try { decoded = URLDecoder.decode(valueString, Charsets.UTF_8.name()); } catch (final UnsupportedEncodingException e) { throw new SmartUriException("", e); } final URI type = TypeDeterminer.determineType(decoded); if (type == XMLSchema.ANYURI) { if (keyString.equals(RYA_TYPES_URI.getLocalName())) { entityTypeMap = convertUriToTypeMap(new URIImpl(decoded)); invertedEntityTypeMap = HashBiMap.create(entityTypeMap).inverse(); } } else { final int keyPrefixLocation = keyString.indexOf("."); final String keyPrefix = keyString.substring(0, keyPrefixLocation); final RyaURI keyCorrespondingType = invertedEntityTypeMap.get(keyPrefix); final String keyName = keyString.substring(keyPrefixLocation + 1, keyString.length()); final RyaType ryaType = new RyaType(type, valueString); final Value value = RyaToRdfConversions.convertValue(ryaType); final String formattedKeyUriString = removeTypePrefixFromUri(keyUri.stringValue(), keyPrefix); final URI formattedKeyUri = new URIImpl(formattedKeyUriString); map.put(formattedKeyUri, value); } } return map; }
From source file:org.outermedia.solrfusion.adapter.solr.DefaultSolrAdapterTest.java
@Test public void testHttpClientUriTools() throws IOException, URISyntaxException { String url = "http://141.39.229.20:9002/te/select?q=23"; URIBuilder ub = new URIBuilder(url); Assert.assertEquals("", "[q=23]", ub.getQueryParams().toString()); ub.setParameter("q", "*:*"); Assert.assertEquals("", "[q=*:*]", ub.getQueryParams().toString()); }
From source file:eu.esdihumboldt.hale.io.wfs.ui.AbstractWFSSource.java
/** * @return a custom filter for the URI history *//* ww w.j ava 2 s . co m*/ @Nullable protected Predicate<? super URI> createHistoryURIFilter() { return new Predicate<URI>() { @Override public boolean apply(URI input) { String expectedRequest = getWFSRequestValue(); URIBuilder uri = new URIBuilder(input); for (NameValuePair param : uri.getQueryParams()) { if ("request".equalsIgnoreCase(param.getName()) && expectedRequest.equals(param.getValue())) { return true; } } return false; } }; }
From source file:com.askfast.askfastapi.util.HttpUtil.java
/** * Append query parameters to given url/* ww w . j a v a 2 s . co m*/ * * @param url * Url as string * @param params * Map with query parameters * @return url Url with query parameters appended * @throws IOException * Errors in connecting to the given URL */ static public String appendQueryParams(String url, Map<String, String> params) throws IOException { if (params != null) { for (String param : params.keySet()) { try { url = url.replace(" ", "%20"); URIBuilder uriBuilder = new URIBuilder(new URI(url)); URIBuilder returnResult = new URIBuilder(new URI(url)).removeQuery(); //avoid double decoding String queryValue = params.get(param); //replace + with encoded version. it will be replaced by space otherwise queryValue = queryValue.replace("+", URLEncoder.encode("+", "UTF-8")); String decodedQueryParam = URLDecoder.decode(queryValue, "UTF-8"); //queryValue is already encoded if after decoded its not the same if (!decodedQueryParam.equals(queryValue)) { queryValue = decodedQueryParam; } returnResult.addParameter(param, queryValue); for (NameValuePair nameValue : uriBuilder.getQueryParams()) { if (!nameValue.getName().equals(queryValue)) { returnResult.addParameter(nameValue.getName(), nameValue.getValue()); } } url = returnResult.toString(); } catch (Exception e) { e.printStackTrace(); } } } return url; }