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.zextras.zimbradrive.BackendUtils.java

public static Map<String, String> getJsonRequestParams(HttpServletRequest httpServletRequest)
        throws IOException {
    String body = IOUtils.toString(httpServletRequest.getReader());
    List<NameValuePair> requestParameters = URLEncodedUtils.parse(body, StandardCharsets.UTF_8);

    Map<String, String> paramsMap = new HashMap<String, String>();
    for (NameValuePair item : requestParameters) {
        paramsMap.put(item.getName(), item.getValue());
    }//from w  w  w.ja  va  2 s  .com
    return paramsMap;
}

From source file:com.playhaven.android.diagnostic.test.PluginIdentifierTest.java

@MediumTest
public void testPermutations() throws Throwable {
    Launcher launcher = doActivityTestSetup();
    Context ctx = getTargetContext();

    for (Plugin plugin : Plugin.values()) {
        clearPreferences();//w  w  w .  j a  va2s .c  o m
        PlayHaven.setVendorCompat(ctx, new VendorCompat(plugin.requested));
        configurePlayHaven();

        TestOpenRequest req = new TestOpenRequest();
        String url = req.getUrl(ctx);
        String value = null;
        for (NameValuePair pair : URLEncodedUtils.parse(new URI(url), "UTF-8")) {
            if (!PARAM_NAME.equals(pair.getName()))
                continue;
            value = pair.getValue();
            break;
        }

        assertEquals(plugin.corrected, value);
    }

    launcher.finish();
}

From source file:com.vmware.photon.controller.api.frontend.filter.NetworkToSubnetRedirectionFilter.java

private void redirectNetworkToSubnet(ContainerRequestContext requestContext, UriInfo uriInfo, URI oldRequestURI,
        String oldPath) {/*from  ww w.j  a v  a 2 s.  c o m*/
    String newPath = oldPath.replace("/networks", "/subnets");
    List<NameValuePair> params = URLEncodedUtils.parse(oldRequestURI, "UTF-8");

    UriBuilder uriBuilder = uriInfo.getBaseUriBuilder().path(newPath);
    for (NameValuePair pair : params) {
        uriBuilder.queryParam(pair.getName(), pair.getValue());
    }

    URI newRequestURI = uriBuilder.build();
    requestContext.setRequestUri(newRequestURI);
    logger.info("Redirecting {} to {}", oldRequestURI.toString(), newRequestURI.toString());
}

From source file:com.thoughtworks.go.agent.service.TokenRequesterTest.java

@Test
public void shouldGetTokenFromServer() throws Exception {
    final ArgumentCaptor<HttpRequestBase> argumentCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
    final CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);

    when(agentRegistry.uuid()).thenReturn("agent-uuid");
    when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
    when(httpResponse.getEntity()).thenReturn(new StringEntity("token-from-server"));
    when(httpResponse.getStatusLine())/*from www.jav a 2s. co  m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), SC_OK, null));

    final String token = tokenRequester.getToken();

    verify(httpClient).execute(argumentCaptor.capture());

    final HttpRequestBase requestBase = argumentCaptor.getValue();
    final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(requestBase.getURI(),
            StandardCharsets.UTF_8.name());

    assertThat(token, is("token-from-server"));
    assertThat(findParam(nameValuePairs, "uuid").getValue(), is("agent-uuid"));
}

From source file:nl.armatiek.xslweb.web.servlet.XSLWebHttpServletRequest.java

public XSLWebHttpServletRequest(ServletContext context, String path) {
    this.context = context;
    this.session = new XSLWebHttpSession(context);
    String[] parts = path.split("\\?");
    if (parts.length > 1) {
        this.pathInfo = parts[0];
        this.queryString = parts[1];
        Map<String, ArrayList<String>> paramMap = new HashMap<String, ArrayList<String>>();
        List<NameValuePair> params = URLEncodedUtils.parse(queryString, Charset.forName("UTF-8"));
        for (NameValuePair param : params) {
            ArrayList<String> values = (ArrayList<String>) paramMap.get(param.getName());
            if (values == null) {
                values = new ArrayList<String>();
            }// w ww .ja  v a  2  s.c  o m
            values.add(param.getValue());
            paramMap.put(param.getName(), values);
        }
        for (Map.Entry<String, ArrayList<String>> entry : paramMap.entrySet()) {
            ArrayList<String> values = entry.getValue();
            parameters.put(entry.getKey(), values.toArray(new String[values.size()]));
        }
    } else {
        this.pathInfo = path;
    }

}

From source file:org.cloudfoundry.identity.uaa.db.DatabaseParametersTests.java

public String getUrlParameter(String name) throws URISyntaxException {
    String dburl = getDataSource().getUrl();
    URI uri = URI.create("http://localhost" + dburl.substring(dburl.indexOf("?")));
    List<NameValuePair> pairs = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
    for (NameValuePair p : pairs) {
        if (name.equals(p.getName())) {
            return p.getValue();
        }//from   w  w  w .j a v a 2  s.  c om
    }
    return null;
}

From source file:org.apache.marmotta.ldclient.provider.phpbb.PHPBBPostProvider.java

/**
 * Return a mapping table mapping from RDF properties to XPath Value Mappers. Each entry in the
 * map is evaluated//  ww w. ja v a  2s  .  c o m
 * in turn; in case the XPath expression yields a result, the property is added for the
 * processed resource.
 * 
 * @return
 * @param requestUrl
 */
@Override
protected Map<String, JSoupMapper> getMappings(String resource, String requestUrl) {
    URI uri = null;
    try {
        uri = new URI(requestUrl);
        Map<String, String> params = new HashMap<String, String>();
        for (NameValuePair p : URLEncodedUtils.parse(uri, "UTF-8")) {
            params.put(p.getName(), p.getValue());
        }

        if (params.containsKey("p")) {
            // mappings for a reply that has directly been addressed using the ?p=... parameter
            // to viewtopic.php, e.g. http://www.carving-ski.de/phpBB/viewtopic.php?p=119208
            Map<String, JSoupMapper> commentMappings = new HashMap<String, JSoupMapper>();
            commentMappings.put(Namespaces.NS_DC + "title", new CssTextLiteralMapper(
                    String.format("div#pagecontent table:has(a[name=p%s]) td.gensmall div", params.get("p"))) {
                @Override
                public List<Value> map(String resourceUri, Element elem, ValueFactory factory) {
                    final String val = elem.ownText().replaceFirst("^\\s*:", "").replaceAll("&nbsp;", " ")
                            .trim();
                    if (datatype != null)
                        return Collections.singletonList((Value) factory.createLiteral(val,
                                factory.createURI(Namespaces.NS_XSD + datatype)));
                    else
                        return Collections.singletonList((Value) factory.createLiteral(val));
                }

                @Override
                public Elements select(Element htmlDoc) {
                    final Element first = super.select(htmlDoc).first();
                    return first != null ? new Elements(first) : new Elements();
                }
            });
            commentMappings.put(Namespaces.NS_DC + "creator", new CssTextLiteralMapper(
                    String.format("div#pagecontent table:has(a[name=p%s]) .postauthor", params.get("p"))));
            commentMappings.put(Namespaces.NS_DC + "description", new CssTextLiteralMapper(
                    String.format("div#pagecontent table:has(a[name=p%s]) div.postbody", params.get("p"))));
            commentMappings.put(Namespaces.NS_DC + "date", new PHPBBDateMapper(
                    String.format("div#pagecontent td.gensmall:has(a[name=p%s]) div", params.get("p"))) {
                @Override
                public Elements select(Element htmlDoc) {
                    final Elements sel = super.select(htmlDoc);
                    if (sel.size() > 0) {
                        final Element e = sel.get(1);
                        if (e != null)
                            return new Elements(e);
                    }
                    return new Elements();
                }
            });

            return commentMappings;
        } else
            throw new RuntimeException(
                    "the requested resource does not seem to identify a PHPBB Post (p=... parameter missing)");

    } catch (URISyntaxException e) {
        throw new RuntimeException(
                "the requested resource does not seem to identify a PHPBB Post (URI syntax error)");
    }

}

From source file:org.apache.hadoop.security.AuthenticationWithProxyUserFilter.java

/**
 * Get proxy user from query string.//from   w  w w .  j  ava2 s. c om
 * @param request the request object
 * @return proxy user
 */
public static String getDoAs(HttpServletRequest request) {
    String queryString = request.getQueryString();
    if (queryString == null) {
        return null;
    }
    List<NameValuePair> list = URLEncodedUtils.parse(queryString, UTF8_CHARSET);
    if (list != null) {
        for (NameValuePair nv : list) {
            if (DO_AS.equalsIgnoreCase(nv.getName())) {
                return nv.getValue();
            }
        }
    }
    return null;
}