Example usage for org.apache.http.client.utils URLEncodedUtils parse

List of usage examples for org.apache.http.client.utils URLEncodedUtils parse

Introduction

In this page you can find the example usage for org.apache.http.client.utils URLEncodedUtils parse.

Prototype

public static List<NameValuePair> parse(final String s, final Charset charset) 

Source Link

Document

Returns a list of NameValuePair NameValuePairs as parsed from the given string using the given character encoding.

Usage

From source file:com.cloud.utils.UriUtils.java

public static boolean cifsCredentialsPresent(URI uri) {
    List<NameValuePair> args = URLEncodedUtils.parse(uri, "UTF-8");
    boolean foundUser = false;
    boolean foundPswd = false;
    for (NameValuePair nvp : args) {
        String name = nvp.getName();
        if (name.equals("user")) {
            foundUser = true;//from  ww  w .j a  va2s. c  o m
            s_logger.debug("foundUser is" + foundUser);
        } else if (name.equals("password")) {
            foundPswd = true;
            s_logger.debug("foundPswd is" + foundPswd);
        }
    }
    return (foundUser && foundPswd);
}

From source file:com.gsma.mobileconnect.utils.HttpUtils.java

/**
 * Extract the parameters from the passed URL.
 *
 * @param url The URL to extract the parameters from.
 * @return The list of parameters, as a list of NameValuePairs.
 * @throws URISyntaxException/*from  w  w w.jav a2  s. c om*/
 */
public static List<NameValuePair> extractParameters(String url) throws URISyntaxException {
    if (StringUtils.isNullOrEmpty(url)) {
        return new ArrayList<NameValuePair>(0);
    }
    URI uri = new URI(url);
    return URLEncodedUtils.parse(uri.getQuery(), null);
}

From source file:com.jaeksoft.searchlib.util.LinkUtils.java

public final static Map<String, String> getUniqueQueryParameters(final URI uri, final String charset) {
    final Map<String, String> map = new TreeMap<String, String>();
    final List<NameValuePair> parameters = URLEncodedUtils.parse(uri, "UTF-8");
    for (NameValuePair parameter : parameters)
        map.put(parameter.getName(), parameter.getValue());
    return map;/*  ww  w . j  av a  2s  .c  o  m*/
}

From source file:com.android.vending.licensing.i.java

private Map<String, String> d(String paramString) {
    HashMap localHashMap = new HashMap();
    try {//  w  w w .  j  a  v  a2s  .c  o  m
        Iterator localIterator = URLEncodedUtils.parse(new URI("?" + paramString), "UTF-8").iterator();
        while (true) {
            if (!localIterator.hasNext())
                return localHashMap;
            NameValuePair localNameValuePair = (NameValuePair) localIterator.next();
            localHashMap.put(localNameValuePair.getName(), localNameValuePair.getValue());
        }
    } catch (URISyntaxException localURISyntaxException) {
        Log.w("ServerManagedPolicy", "Invalid syntax error while decoding extras data from server.");
    }
    return localHashMap;
}

From source file:com.pliu.powerbiembed.ReportController.java

private String ComputeJWTToken(String workspaceCollection, String workspaceId, String resourceId,
        String accessKey, String embedUrl, String username, String roles) throws Exception {
    List<NameValuePair> params = URLEncodedUtils.parse(new URI(embedUrl), "UTF-8");
    String reportId = "";
    for (NameValuePair param : params) {
        if (param.getName().equals("reportId")) {
            reportId = param.getValue();
            break;
        }//from  w  ww.ja  v a  2 s  . c  o m
    }

    int unixTimestamp = (int) (System.currentTimeMillis() / 1000L) + 2 * 24 * 60 * 60; //expire in 2 days
    String pbieKey1 = "{\"typ\":\"JWT\",\"alg\":\"HS256\"}";
    String pbieKey2 = String.format(
            "{\"wid\":\"%s\",\"rid\":\"%s\",\"wcn\":\"%s\",\"iss\":\"PowerBISDK\",\"ver\":\"0.2.0\","
                    + "\"aud\":\"%s\",\"exp\":%d,\"username\":\"%s\",\"roles\":\"%s\"}",
            workspaceId, reportId, workspaceCollection, resourceId, unixTimestamp, username, roles);
    String pbieKey1n2ToBase64 = Base64UrlEncode(pbieKey1) + "." + Base64UrlEncode(pbieKey2);
    String pbieKey3 = HMAC256EncryptBase64UrlEncode(pbieKey1n2ToBase64, accessKey);

    return pbieKey1n2ToBase64 + "." + pbieKey3;
}

From source file:org.mitre.dsmiley.httpproxy.URITemplateProxyServlet.java

@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {

    //First collect params
    /*/*from  ww  w. j  a  v  a2 s  .c o  m*/
     * Do not use servletRequest.getParameter(arg) because that will
     * typically read and consume the servlet InputStream (where our
     * form data is stored for POST). We need the InputStream later on.
     * So we'll parse the query string ourselves. A side benefit is
     * we can keep the proxy parameters in the query string and not
     * have to add them to a URL encoded form attachment.
     */
    String queryString = "?" + servletRequest.getQueryString();//no "?" but might have "#"
    int hash = queryString.indexOf('#');
    if (hash >= 0) {
        queryString = queryString.substring(0, hash);
    }
    List<NameValuePair> pairs;
    try {
        //note: HttpClient 4.2 lets you parse the string without building the URI
        pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8");
    } catch (URISyntaxException e) {
        throw new ServletException("Unexpected URI parsing error on " + queryString, e);
    }
    LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
    for (NameValuePair pair : pairs) {
        params.put(pair.getName(), pair.getValue());
    }

    //Now rewrite the URL
    StringBuffer urlBuf = new StringBuffer();//note: StringBuilder isn't supported by Matcher
    Matcher matcher = TEMPLATE_PATTERN.matcher(targetUriTemplate);
    while (matcher.find()) {
        String arg = matcher.group(1);
        String replacement = params.remove(arg);//note we remove
        if (replacement == null) {
            throw new ServletException("Missing HTTP parameter " + arg + " to fill the template");
        }
        matcher.appendReplacement(urlBuf, replacement);
    }
    matcher.appendTail(urlBuf);
    String newTargetUri = urlBuf.toString();
    servletRequest.setAttribute(ATTR_TARGET_URI, newTargetUri);
    URI targetUriObj;
    try {
        targetUriObj = new URI(newTargetUri);
    } catch (Exception e) {
        throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e);
    }
    servletRequest.setAttribute(ATTR_TARGET_HOST, URIUtils.extractHost(targetUriObj));

    //Determine the new query string based on removing the used names
    StringBuilder newQueryBuf = new StringBuilder(queryString.length());
    for (Map.Entry<String, String> nameVal : params.entrySet()) {
        if (newQueryBuf.length() > 0)
            newQueryBuf.append('&');
        newQueryBuf.append(nameVal.getKey()).append('=');
        if (nameVal.getValue() != null)
            newQueryBuf.append(nameVal.getValue());
    }
    servletRequest.setAttribute(ATTR_QUERY_STRING, newQueryBuf.toString());

    super.service(servletRequest, servletResponse);
}

From source file:org.craftercms.studio.impl.v1.web.http.MultiReadHttpServletRequestWrapper.java

private Iterable<NameValuePair> decodeParams(String body) {
    List<NameValuePair> params = new ArrayList<>(URLEncodedUtils.parse(body, UTF8_CHARSET));
    try {/*from  w w  w. j  a va 2s  . c  o m*/
        String cts = getContentType();
        if (cts != null) {
            ContentType ct = ContentType.parse(cts);
            if (ct.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
                List<NameValuePair> postParams = URLEncodedUtils.parse(IOUtils.toString(getReader()),
                        UTF8_CHARSET);
                CollectionUtils.addAll(params, postParams);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return params;
}

From source file:com.tripit.auth.OAuthCredential.java

public boolean validateSignature(URI requestUri)
        throws URISyntaxException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException {
    List<NameValuePair> argList = URLEncodedUtils.parse(requestUri, "UTF-8");
    SortedMap<String, String> args = new TreeMap<String, String>();
    for (NameValuePair arg : argList) {
        args.put(arg.getName(), arg.getValue());
    }//from ww w. j  av a2  s.c  om

    String signature = args.remove("oauth_signature");

    String baseUrl = new URI(requestUri.getScheme(), requestUri.getUserInfo(), requestUri.getAuthority(),
            requestUri.getPort(), requestUri.getPath(), null, requestUri.getFragment()).toString();

    return (signature != null && signature.equals(generateSignature(baseUrl, args)));
}

From source file:org.flowable.ui.modeler.service.FlowableModelQueryService.java

public ResultListDataRepresentation getModels(String filter, String sort, Integer modelType,
        HttpServletRequest request) {//from w  ww .jav  a2  s .  c  o m

    // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing.
    String filterText = null;
    List<NameValuePair> params = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8"));
    if (params != null) {
        for (NameValuePair nameValuePair : params) {
            if ("filterText".equalsIgnoreCase(nameValuePair.getName())) {
                filterText = nameValuePair.getValue();
            }
        }
    }

    List<ModelRepresentation> resultList = new ArrayList<>();
    List<Model> models = null;

    String validFilter = makeValidFilterText(filterText);

    if (validFilter != null) {
        models = modelRepository.findByModelTypeAndFilter(modelType, validFilter, sort);

    } else {
        models = modelRepository.findByModelType(modelType, sort);
    }

    if (CollectionUtils.isNotEmpty(models)) {
        List<String> addedModelIds = new ArrayList<>();
        for (Model model : models) {
            if (!addedModelIds.contains(model.getId())) {
                addedModelIds.add(model.getId());
                ModelRepresentation representation = createModelRepresentation(model);
                resultList.add(representation);
            }
        }
    }

    ResultListDataRepresentation result = new ResultListDataRepresentation(resultList);
    return result;
}