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:org.hawk.service.emf.impl.HawkResourceFactoryImpl.java

protected HawkModelDescriptor parseHawkURL(URI uri) {
    // construct HawkModelDescriptor from URI on the fly
    final HawkModelDescriptor descriptor = new HawkModelDescriptor();
    final String instanceURL = uri.trimQuery().toString().replaceFirst("hawk[+]", "");
    descriptor.setHawkURL(instanceURL);//from  w w w.j av a 2  s  . c o m

    final List<NameValuePair> pairs = URLEncodedUtils.parse(uri.query(), Charset.forName("UTF-8"));
    for (NameValuePair pair : pairs) {
        final String v = pair.getValue();
        switch (pair.getName()) {
        case URLPARAM_INSTANCE:
            descriptor.setHawkInstance(v);
            break;
        case URLPARAM_FILE_PATTERNS:
            descriptor.setHawkFilePatterns(v.split(","));
            break;
        case URLPARAM_THRIFT_PROTOCOL:
            descriptor.setThriftProtocol(ThriftProtocol.valueOf(v.toUpperCase()));
            break;
        case URLPARAM_REPOSITORY:
            descriptor.setHawkRepository(v);
            break;
        case URLPARAM_LOADING_MODE:
            descriptor.setLoadingMode(LoadingMode.valueOf(v.toUpperCase()));
            break;
        case URLPARAM_SPLIT:
            descriptor.setSplit(Boolean.valueOf(v));
            break;
        case URLPARAM_SUBSCRIBE:
            descriptor.setSubscribed(Boolean.valueOf(v));
            break;
        case URLPARAM_DURABILITY:
            descriptor.setSubscriptionDurability(SubscriptionDurability.valueOf(v.toUpperCase()));
            break;
        case URLPARAM_CLIENTID:
            descriptor.setSubscriptionClientID(v);
            break;
        case URLPARAM_QUERY_LANGUAGE:
            descriptor.setHawkQueryLanguage(v);
            break;
        case URLPARAM_QUERY:
            descriptor.setHawkQuery(v);
            break;
        }
    }
    return descriptor;
}

From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java

private static Map<RyaURI, String> convertUriToTypeMap(final URI typeMapUri) throws SmartUriException {
    final Map<RyaURI, String> map = new HashMap<>();
    java.net.URI uri;/*w  ww .j a  v  a  2 s  .co  m*/
    try {
        final URIBuilder uriBuilder = new URIBuilder(typeMapUri.stringValue());
        uri = uriBuilder.build();
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to parse Rya type map in Smart URI", e);
    }

    final List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8.name());

    for (final NameValuePair param : params) {
        final String name = param.getName();
        final String value = param.getValue();
        final RyaURI type = new RyaURI(name);
        map.put(type, value);
    }
    return map;
}

From source file:com.wikitude.example.CopyOfSimpleARBrowserActivity.java

/**
 * <p>//www.j a v  a  2 s .  com
 * interface method of {@link ArchitectUrlListener} class
 * called when an url with host "architectsdk://" is discovered
 * 
 * can be parsed and allows to react to events triggered in the ARchitect World
 * </p>
 */
//@Override
public boolean urlWasInvoked(String url) {
    //parsing the retrieved url string
    List<NameValuePair> queryParams = URLEncodedUtils.parse(URI.create(url), "UTF-8");

    String id = "";
    // getting the values of the contained GET-parameters
    for (NameValuePair pair : queryParams) {
        if (pair.getName().equals("id")) {
            id = pair.getValue();
        }
    }

    //get the corresponding poi bean for the given id
    PoiBean bean = poiBeanList.get(Integer.parseInt(id));
    //start a new intent for displaying the content of the bean
    Intent intent = new Intent(this, PoiDetailActivity.class);
    intent.putExtra("POI_NAME", bean.getName());
    intent.putExtra("POI_DESC", bean.getDescription());
    this.startActivity(intent);
    return true;
}

From source file:nl.uva.mediamosa.impl.MediaMosaImpl.java

/**
 * @param postRequest//  www  .j  a va2 s .com
 * @param postParams
 * @return
 * @throws IOException
 */
public String doPostRequestString(String postRequest, String postParams) throws IOException {
    HttpPost httpPost = new HttpPost(hostname + postRequest);

    List<NameValuePair> nvps = URLEncodedUtils.parse(postParams, Charset.forName("UTF-8"));
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, Charset.forName("UTF-8")));

    return getXmlTransformedResponse(httpPost);
}

From source file:com.wikitude.example.ARBrowserActivity.java

@Override
public boolean urlWasInvoked(String url) {
    // parsing the retrieved url string
    List<NameValuePair> queryParams = URLEncodedUtils.parse(URI.create(url), "UTF-8");

    String id = "";
    // getting the values of the contained GET-parameters
    for (NameValuePair pair : queryParams) {
        if (pair.getName().equals("id")) {
            id = pair.getValue();//from   ww  w.  j  ava 2 s  . co  m
        }
    }

    return true;
}

From source file:com.hp.autonomy.hod.client.api.authentication.AuthenticationServiceImplTest.java

private void checkCombinedUrl(final SignedRequest request, final List<NameValuePair> expectedParameters)
        throws URISyntaxException {
    final URI uri = new URI(request.getUrl());
    assertThat(uri.getScheme() + "://" + uri.getHost(), is(ENDPOINT));
    assertThat(uri.getPath(), is(COMBINED_PATH));

    final List<NameValuePair> pairs = URLEncodedUtils.parse(uri, "UTF-8");
    assertThat(pairs, containsInAnyOrder(expectedParameters.toArray()));
}

From source file:ddf.security.samlp.SimpleSignTest.java

@Test
public void testSignUriStringWithDsa() throws Exception {

    systemCrypto = new SystemCrypto("dsa-encryption.properties", "dsa-signature.properties", encryptionService);
    simpleSign = new SimpleSign(systemCrypto);
    String deflatedSamlResponse = deflateAndBase64Encode(cannedResponse);

    String queryParams = String.format("SAMLResponse=%s&RelayState=%s",
            URLEncoder.encode(deflatedSamlResponse, "UTF-8"), URLEncoder.encode(RELAY_STATE_VAL, "UTF-8"));
    String idpRequest = SINGLE_SIGN_ON_LOCATION + "?" + queryParams;
    UriBuilder idpUri = new UriBuilderImpl(new URI(idpRequest));
    simpleSign.signUriString(queryParams, idpUri);

    String signatureAlgorithm = URLEncodedUtils.parse(idpUri.build(), "UTF-8").get(2).getValue();
    String signatureString = URLEncodedUtils.parse(idpUri.build(), "UTF-8").get(3).getValue();

    String signedMessage = String.format("%s=%s&%s=%s&%s=%s", SAML_RESPONSE,
            URLEncoder.encode(deflatedSamlResponse, "UTF-8"), RELAY_STATE,
            URLEncoder.encode(RELAY_STATE_VAL, "UTF-8"), SIG_ALG,
            URLEncoder.encode(signatureAlgorithm, "UTF-8"));
    boolean valid = simpleSign.validateSignature(signedMessage, signatureString, dsaCert);
    assertTrue("Signature was expected to be valid", valid);

}

From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java

public static String removeBVParameters(String url) {
    String newUrl = url;/*from  ww  w .  ja va  2 s .  com*/
    if (newUrl.contains("bvstate=")) {
        // Handle usecase with more parameters after bvstate
        newUrl = newUrl.replaceAll(BVConstant.BVSTATE_REGEX_WITH_TRAILING_SEPARATOR, "");

        // Handle usecase where bvstate is the last parameter
        if (newUrl.endsWith("?") | newUrl.endsWith("&")) {
            newUrl = newUrl.substring(0, newUrl.length() - 1);
        }
        if (newUrl.endsWith(BVConstant.ESCAPED_FRAGMENT_MULTIVALUE_SEPARATOR)) {
            newUrl = newUrl.substring(0, newUrl.length() - 3);
        }
    }

    if (hasBVQueryParameters(newUrl)) {
        final URI uri;
        try {
            uri = new URI(newUrl);
        } catch (URISyntaxException e) {
            return newUrl;
        }

        try {
            String newQuery = null;
            if (uri.getQuery() != null && uri.getQuery().length() > 0) {
                List<NameValuePair> newParameters = new ArrayList<NameValuePair>();
                List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(),
                        Charset.forName("UTF-8"));
                for (NameValuePair parameter : parameters) {
                    if (!bvQueryParameters.contains(parameter.getName())) {
                        newParameters.add(parameter);
                    }
                }
                newQuery = newParameters.size() > 0
                        ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8"))
                        : null;
            }

            return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString();
        } catch (URISyntaxException e) {
            return newUrl;
        }
    }
    return newUrl;
}

From source file:org.deviceconnect.message.http.impl.factory.HttpRequestMessageFactory.java

/**
 * HTTP???dConnect???./*from w ww  . j  ava 2 s  .  c  om*/
 * @param dmessage dConnect
 * @param request HTTP
 */
protected void parseRequestQuery(final DConnectMessage dmessage, final HttpRequest request) {

    // parse query
    try {
        List<NameValuePair> query = URLEncodedUtils.parse(new URI(request.getRequestLine().getUri()), "UTF-8");

        if (query != null && query.size() > 0) {
            mLogger.fine("request query size: " + query.size());
            mLogger.fine("request query: " + query);
            for (NameValuePair pair : query) {
                mLogger.fine("request key/value: " + pair.getName() + ", " + pair.getValue());
                try {
                    dmessage.put(pair.getName(), Integer.parseInt(pair.getValue()));
                } catch (NumberFormatException e) {
                    dmessage.put(pair.getName(), pair.getValue());
                }
            }
        }
    } catch (URISyntaxException e) {
        mLogger.warning(e.toString());
    }

}