Example usage for java.net URL getQuery

List of usage examples for java.net URL getQuery

Introduction

In this page you can find the example usage for java.net URL getQuery.

Prototype

public String getQuery() 

Source Link

Document

Gets the query part of this URL .

Usage

From source file:com.google.zxing.client.android.result.ClickVURIResultHandler.java

public void registerClickV(String uri) {

    String host = "http://lit-taiga-5566.herokuapp.com/";
    String query = null, path = null;
    String telId = getTelNumber() == null ? getMacAddress() : getTelNumber();

    try {//from  w  ww.j  a  va2 s  .c o  m
        URL url = new URL(uri.replaceAll("clickv://", host));
        query = url.getQuery();
        path = url.getProtocol() + "://" + url.getHost() + "/" + url.getPath();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    Toast.makeText(getActivity(), "???  :: " + query, Toast.LENGTH_SHORT).show();

    try {

        new ServerConnenctionTask().execute(path, query, telId);

        Toast.makeText(getActivity(), "" + uri, Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), "?." + uri, Toast.LENGTH_SHORT).show();
    }

}

From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java

/**
 * Splits links of the form target or text|target where target is
 * //from  w w w .  jav  a2  s .  c  o m
 * PageName wiki:PageName PageName#fragment wiki:PageName#fragment
 * A String representing an absolute URI scheme://valid/absolute/uri
 * Any character not in the `unreserved`, `punct`, `escaped`, or `other` categories (RFC 2396),
 * and not equal '/' or '@', is %-encoded. 
 * 
 * @param in The String to split
 * @return The split LinkParts
 */
LinkParts split(final String in) {
    String target = StringUtils.trimToEmpty(StringUtils.substringBefore(in, "|"));
    String text = StringUtils.trimToNull(StringUtils.substringAfter(in, "|"));
    if (target == null) {
        target = "";
    }
    if (text == null) {
        text = target;
    }
    // Link target can be PageName, wiki:PageName or a URL.
    URI uri = null;
    try {
        URL url = new URL(target);

        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (uri.getPath() == null || !uri.isAbsolute()) {
            uri = null;
        }
    } catch (URISyntaxException e) {
        // uri remains null
    } catch (MalformedURLException e) {
        // uri remains null
    }

    if (uri != null) {
        return new LinkParts(text, uri);
    } else {
        // Split into wiki:pageName
        String[] parts = target.split(":", 2);
        String wiki = null;
        String pageName = target;
        if (parts.length == 2) {
            wiki = parts[0];
            pageName = parts[1];
        }

        // Split into pageName#fragment
        parts = pageName.split("#", 2);
        String fragment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            fragment = parts[1];
        }

        // Split into pageName/attachment
        parts = pageName.split("/", 2);
        String attachment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            attachment = parts[1];
        }

        return new LinkParts(text, wiki, pageName, fragment, attachment);
    }
}

From source file:com.dianping.cosmos.monitor.HttpClientService.java

private HttpUriRequest getGetRequest(String url, boolean useURI) throws Exception {
    HttpUriRequest request;// w  w w  .  j a v a 2  s .c  om
    if (useURI) {
        URL requestURL = new URL(url);
        URI uri = new URI(requestURL.getProtocol(), null, requestURL.getHost(), requestURL.getPort(),
                requestURL.getPath(), requestURL.getQuery(), null);
        request = new HttpGet(uri);
    } else {
        request = new HttpGet(url);
    }
    return request;
}

From source file:org.squidy.manager.scanner.PackageScanner.java

/**
 * TODO: out-source me to a FileUtility or FileUtils helper class.
 * //from  ww w .  java2  s.c om
 * @param url
 * @return
 */
private static File urlToFile(URL url) {
    URI uri;
    try {
        // this is the step that can fail, and so
        // it should be this step that should be fixed
        uri = url.toURI();
    } catch (URISyntaxException e) {
        // OK if we are here, then obviously the URL did
        // not comply with RFC 2396. This can only
        // happen if we have illegal unescaped characters.
        // If we have one unescaped character, then
        // the only automated fix we can apply, is to assume
        // all characters are unescaped.
        // If we want to construct a URI from unescaped
        // characters, then we have to use the component
        // constructors:
        try {
            uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                    url.getQuery(), url.getRef());
        } catch (URISyntaxException e1) {
            // The URL is broken beyond automatic repair
            throw new IllegalArgumentException("broken URL: " + url);
        }

    }
    return new File(uri);
}

From source file:net.datacrow.onlinesearch.amazon.SignedRequestsHelper.java

public synchronized String sign(URL url) {
    String server = url.getHost();
    String query = url.getQuery();

    Map<String, String> params = createParameterMap(query);

    // remove old signature information
    params.remove("AWSAccessKeyId");
    params.remove("Timestamp");
    params.remove("Signature");

    return sign(server, params);
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Appends to the path of the URL//w  w w  .ja v a 2 s .c o m
 * @param url the URL
 * @param append the path to append
 * @return the final URL version 
 */
protected static URL appendUrlPath(URL url, String append) throws MalformedURLException {
    return new URL(url.getProtocol() + "://" + url.getAuthority() + url.getPath() + append
            + (url.getQuery() != null ? "?" + url.getQuery() : ""));
}

From source file:de.thischwa.pmcms.tool.Link.java

public void init(final String link) {
    try {//  w  w  w.  j  av  a2  s .  com
        URI uri = new URI(link);
        String schema = uri.getScheme();
        if (schema != null) {
            if (schema.equalsIgnoreCase("file")) {
                isFile = true;
            } else if (schema.equalsIgnoreCase("javascript")) {
                isExternal = true;
            } else if (schema.equalsIgnoreCase("mailto")) {
                isMailto = true;
                isExternal = true;
            } else if (schema.equalsIgnoreCase("http") && uri.getHost() != null
                    && uri.getHost().equalsIgnoreCase(host)) {
                isExternal = false;
            } else if (schema.equalsIgnoreCase("http") || schema.equalsIgnoreCase("https")
                    || schema.equalsIgnoreCase("ftp") || schema.equalsIgnoreCase("ftps"))
                isExternal = true;
        }
        path = uri.getPath();
    } catch (Exception e) {
        logger.warn("While trying to get the URI: " + e.getMessage(), e);
    }

    try {
        URL url = new URL(link);
        if (path == null)
            path = url.getPath();
        String query = url.getQuery();
        if (query != null) {
            String[] parameterPairs = StringUtils.split(query, "&");
            for (String parameterPair : parameterPairs) {
                if (StringUtils.isNotBlank(parameterPair)) {
                    KeyValue kv = new KeyValue(parameterPair);
                    String val = decodeQuietly(kv.val);
                    parameters.put(kv.key, val);
                }
            }
        }
    } catch (Exception e) {
        if (path == null)
            throw new IllegalArgumentException(e);
    }
}

From source file:nl.b3p.viewer.stripes.ProxyActionBean.java

private Resolution proxyWMS() throws IOException {

    HttpServletRequest request = getContext().getRequest();

    if (!"GET".equals(request.getMethod())) {
        return new ErrorResolution(HttpServletResponse.SC_FORBIDDEN);
    }/*  w  w w . ja v  a  2  s  . c om*/

    List allowedParams = new ArrayList<String>();
    allowedParams.add("VERSION");
    allowedParams.add("SERVICE");
    allowedParams.add("REQUEST");
    allowedParams.add("UPDATESEQUENCE");
    allowedParams.add("LAYERS");
    allowedParams.add("LAYER");
    allowedParams.add("STYLES");
    allowedParams.add("SRS");
    allowedParams.add("BBOX");
    allowedParams.add("FORMAT");
    allowedParams.add("WIDTH");
    allowedParams.add("HEIGHT");
    allowedParams.add("TRANSPARENT");
    allowedParams.add("BGCOLOR");
    allowedParams.add("EXCEPTIONS");
    allowedParams.add("TIME");
    allowedParams.add("ELEVATION");
    allowedParams.add("QUERY_LAYERS");
    allowedParams.add("X");
    allowedParams.add("Y");
    allowedParams.add("INFO_FORMAT");
    allowedParams.add("FEATURE_COUNT");
    allowedParams.add("SLD");
    allowedParams.add("SLD_BODY");
    //vendor
    allowedParams.add("MAP");

    URL theUrl = new URL(url);

    String query = theUrl.getQuery();
    //only WMS request param's allowed
    String[] params = query.split("&");
    StringBuilder sb = new StringBuilder();
    for (String param : params) {
        if (allowedParams.contains((param.split("=")[0]).toUpperCase())) {
            sb.append(param + "&");
        }
    }
    theUrl = new URL("http", theUrl.getHost(), theUrl.getPort(), theUrl.getPath() + "?" + sb.toString());

    //TODO: Check if response is a getFeatureInfo response.
    final URLConnection connection = theUrl.openConnection();
    return new StreamingResolution(connection.getContentType()) {
        @Override
        protected void stream(HttpServletResponse response) throws IOException {
            IOUtils.copy(connection.getInputStream(), response.getOutputStream());
        }
    };
}

From source file:org.echocat.nodoodle.server.BaseUrlsDiscovery.java

public String selectIdFrom(URL url) throws IllegalBaseUrlException {
    if (url == null) {
        throw new NullPointerException("No preferredBaseUrl given.");
    }/*w  ww.jav a  2 s  .c  o m*/
    if (!isEmpty(url.getQuery())) {
        throw new IllegalBaseUrlException("The given preferredBaseUrl (" + url + ") contains a query.");
    }
    final Iterator<URL> i = _baseUrls.iterator();
    String result = null;
    while (i.hasNext() && result == null) {
        final URL baseUrl = i.next();
        if (baseUrl.getProtocol().equals(url.getProtocol()) && baseUrl.getHost().equals(url.getHost())
                && baseUrl.getPort() == url.getPort()) {
            final String plainBaseUrlPath = baseUrl.getPath();
            final String baseUrlPath = plainBaseUrlPath
                    + (plainBaseUrlPath.endsWith("/") ? "" : plainBaseUrlPath + "/");
            final String preferredBaseUrlPath = url.getPath();
            if (preferredBaseUrlPath.startsWith(baseUrlPath)
                    && preferredBaseUrlPath.length() > baseUrlPath.length()) {
                final String leftPreferredBasePath = preferredBaseUrlPath.substring(baseUrlPath.length());
                final int lastSlash = leftPreferredBasePath.indexOf('/');
                result = lastSlash > 0 ? leftPreferredBasePath.substring(0, lastSlash) : leftPreferredBasePath;
            }
        }
    }
    return result;
}

From source file:org.imsglobal.lti.toolProvider.ToolConsumer.java

public static String addSignature(String endpoint, String consumerKey, String consumerSecret, String data,
        String method, String type) {
    List<Entry<String, String>> oparams = new ArrayList<Entry<String, String>>();
    Map<String, List<String>> params = new HashMap<String, List<String>>();
    URL url;
    Map<String, List<String>> queryParams = new HashMap<String, List<String>>();
    List<Entry<String, String>> headers = new ArrayList<Entry<String, String>>();
    try {/*  ww w .  ja v a  2  s  .c  om*/
        url = new URL(endpoint);
        queryParams = OAuthUtil.parse_parameters(url.getQuery());
        params.putAll(queryParams);

        // Calculate body hash
        MessageDigest md = MessageDigest.getInstance("SHA1");
        byte[] sha1 = md.digest(data.getBytes());
        String hash = Base64.encodeBase64String(sha1);
        List<String> hashList = new ArrayList<String>();
        hashList.add(hash);
        params.put("oauth_body_hash", hashList);

        oparams = convert(params);

        // Add OAuth signature
        OAuthMessage message = doSignature(endpoint, oparams, consumerKey, consumerSecret, method);

        // Remove parameters being passed on the query string
        oparams = removeQueryParams(message.getParameters(), queryParams);

        headers = message.getHeaders();
        if (StringUtils.isEmpty(data)) {
            if (type != null) {
                headers = addHeader(headers, "Accept", type);
            }
        } else if (StringUtils.isNotEmpty(type)) {
            headers = addHeader(headers, "Content-Type", type);
            headers = addHeader(headers, "Content-Length", String.valueOf(data.length()));
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (OAuthException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    return convertHeader(headers);
}