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:ai.baby.util.Parameter.java

public String toURL() {
    try {/*from   w w  w  .j  a  v  a  2 s.c  om*/
        final URL url = new URL(parameterString.getObjectAsValid());
        final URI returnVal = new URI(url.getProtocol(), null, url.getHost(), 80, url.getPath(), url.getQuery(),
                null);
        return returnVal.toString();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.brightcove.com.zartan.verifier.video.StreamingFLVURLVerifier.java

@ZartanCheck(value = "Primary Rendition has no billing params")
public ResultEnum assertPrimaryRenditionBillingCorrect(UploadData upData) throws Throwable {
    URL u = getPrimaryRenditionUrl(upData);
    assertTrue("Primary Rendition should have no billing params",
            !u.getQuery().contains("pubId=" + upData.getmAccount().getId()));
    return ResultEnum.PASS;
}

From source file:com.tc.admin.UpdateCheckRequestTest.java

private URL getURL() throws MalformedURLException {
    URL url = constructCheckURL(ProductInfo.getInstance(), 0);
    return new URL("http://localhost:" + fPort + "/test?" + url.getQuery());
}

From source file:gov.loc.ndmso.proxyfilter.RequestProxy.java

private static HttpMethod setupProxyRequest(final HttpServletRequest hsRequest, final URL targetUrl)
        throws IOException {
    final String methodName = hsRequest.getMethod();
    final HttpMethod method;
    if ("POST".equalsIgnoreCase(methodName)) {
        PostMethod postMethod = new PostMethod();
        InputStreamRequestEntity inputStreamRequestEntity = new InputStreamRequestEntity(
                hsRequest.getInputStream());
        postMethod.setRequestEntity(inputStreamRequestEntity);
        method = postMethod;/*from w  w w .j  a  v a 2s .c om*/
    } else if ("GET".equalsIgnoreCase(methodName)) {
        method = new GetMethod();
    } else {
        // log.warn("Unsupported HTTP method requested: " + hsRequest.getMethod());
        return null;
    }

    method.setFollowRedirects(false);
    method.setPath(targetUrl.getPath());
    method.setQueryString(targetUrl.getQuery());

    @SuppressWarnings("unchecked")
    Enumeration<String> e = hsRequest.getHeaderNames();
    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = e.nextElement();
            if ("host".equalsIgnoreCase(headerName)) {
                //the host value is set by the http client
                continue;
            } else if ("content-length".equalsIgnoreCase(headerName)) {
                //the content-length is managed by the http client
                continue;
            } else if ("accept-encoding".equalsIgnoreCase(headerName)) {
                //the accepted encoding should only be those accepted by the http client.
                //The response stream should (afaik) be deflated. If our http client does not support
                //gzip then the response can not be unzipped and is delivered wrong.
                continue;
            } else if (headerName.toLowerCase().startsWith("cookie")) {
                //fixme : don't set any cookies in the proxied request, this needs a cleaner solution
                continue;
            }

            @SuppressWarnings("unchecked")
            Enumeration<String> values = hsRequest.getHeaders(headerName);
            while (values.hasMoreElements()) {
                String headerValue = values.nextElement();
                // log.info("setting proxy request parameter:" + headerName + ", value: " + headerValue);
                method.addRequestHeader(headerName, headerValue);
            }
        }
    }

    // add rs5/tomcat5 request header for ML
    method.addRequestHeader("X-Via", "tomcat5");

    // log.info("proxy query string " + method.getQueryString());
    return method;
}

From source file:com.comcast.cdn.traffic_control.traffic_router.core.request.HTTPRequest.java

public void applyUrl(final URL url) {
    setPath(url.getPath());/*from w w w.j ava2s  .  c  om*/
    setQueryString(url.getQuery());
    setHostname(url.getHost());
    setRequestedUrl(url.toString());
}

From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.CRLDistributionPointRevocationChecker.java

private void addURL(final List<URL> list, final String uriString) {
    try {//from w w  w  .j a v a 2  s  .  co m
        // Build URI by components to facilitate proper encoding of querystring
        // e.g. http://example.com:8085/ca?action=crl&issuer=CN=CAS Test User CA
        final URL url = new URL(uriString);
        final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null);
        list.add(uri.toURL());
    } catch (final Exception e) {
        log.warn(uriString + " is not a valid distribution point URI.");
    }
}

From source file:com.digitalpebble.storm.crawler.filtering.basic.BasicURLNormalizer.java

/**
 * Basic filter to remove query parameters from urls so parameters that
 * don't change the content of the page can be removed. An example would be
 * a google analytics query parameter like "utm_campaign" which might have
 * several different values for a url that points to the same content.
 *//*from w w  w .ja v a2  s  . c o m*/
private String filterQueryElements(String urlToFilter) {
    try {
        // Handle illegal characters by making a url first
        // this will clean illegal characters like |
        URL url = new URL(urlToFilter);

        if (StringUtils.isEmpty(url.getQuery())) {
            return urlToFilter;
        }

        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        URLEncodedUtils.parse(pairs, new Scanner(url.getQuery()), "UTF-8");
        Iterator<NameValuePair> pairsIterator = pairs.iterator();
        while (pairsIterator.hasNext()) {
            NameValuePair param = pairsIterator.next();
            if (queryElementsToRemove.contains(param.getName())) {
                pairsIterator.remove();
            }
        }

        StringBuilder newFile = new StringBuilder();
        if (url.getPath() != null) {
            newFile.append(url.getPath());
        }
        if (!pairs.isEmpty()) {
            Collections.sort(pairs, comp);
            String newQueryString = URLEncodedUtils.format(pairs, StandardCharsets.UTF_8);
            newFile.append('?').append(newQueryString);
        }
        if (url.getRef() != null) {
            newFile.append('#').append(url.getRef());
        }

        return new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile.toString()).toString();
    } catch (MalformedURLException e) {
        LOG.warn("Invalid urlToFilter {}. {}", urlToFilter, e);
        return null;
    }
}

From source file:com.predic8.membrane.core.interceptor.WSDLInterceptor.java

private String getCompletePath(URL url) {
    if (url.getQuery() == null)
        return url.getPath();

    return url.getPath() + "?" + url.getQuery();
}

From source file:org.deegree.portal.standard.csw.control.FullMetadataSetListener.java

/**
 * @param cswAddress//ww  w .j ava 2s. co  m
 * @return
 */
@SuppressWarnings("unchecked")
private XMLFragment performQuery(String request) throws Exception {
    LOG.logDebug("GetRecordById: ", request);
    Enumeration<String> en = ((HttpServletRequest) getRequest()).getHeaderNames();
    Map<String, String> map = new HashMap<String, String>();
    while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        if (!name.equalsIgnoreCase("accept-encoding") && !name.equalsIgnoreCase("content-length")
                && !name.equalsIgnoreCase("user-agent")) {
            map.put(name, ((HttpServletRequest) getRequest()).getHeader(name));
        }
    }
    URL url = new URL(request);
    map = KVP2Map.toMap(url.getQuery());
    StringBuilder sb = new StringBuilder(url.toExternalForm().split("\\?")[0]);
    sb.append('?');
    Iterator<String> iter = map.keySet().iterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        sb.append(key).append('=')
                .append(URLEncoder.encode(map.get(key), Charset.defaultCharset().displayName()));
        if (iter.hasNext()) {
            sb.append('&');
        }
    }
    HttpMethod method = HttpUtils.performHttpGet(sb.toString(), null, 60000, null, null, map);
    XMLFragment xml = new XMLFragment();
    xml.load(method.getResponseBodyAsStream(), request);
    if (LOG.getLevel() == ILogger.LOG_DEBUG) {
        LOG.logDebug("GetRecordById result: ", xml.getAsPrettyString());
    }
    return xml;
}

From source file:org.glyspace.registry.security.janrain.JanrainService.java

private JanrainAuthenticationToken parseJanrainAuthenticationToken(InputStream content)
        throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
    Document document = parseContent(content);
    logger.debug(document.toString());//from   ww w  .  jav  a  2  s  . c o m
    XPath xPath = createXPath();
    if (!getStringValue(document, xPath, "//rsp/@stat").equals("ok")) {
        return null;
    }
    String identifier = getStringValue(document, xPath, "//rsp/profile/identifier");
    String providerName = getStringValue(document, xPath, "//rsp/profile/providerName");
    String name = getStringValue(document, xPath, "//rsp/profile/name/formatted");
    String email = getStringValue(document, xPath, "//rsp/profile/email");
    String verifiedEmail = getStringValue(document, xPath, "//rsp/profile/verifiedEmail");

    String providerSpecifier = getStringValue(document, xPath, "//rsp/profile/providerSpecifier");

    // twitter specific      
    if (null != providerSpecifier && providerSpecifier.equals("twitter")) {
        if (null == email || email.isEmpty())
            email = getStringValue(document, xPath, "//rsp/profile/url");

        //http://twitter.com/account/profile?user_id=2832353642

        URL twiturl = new URL(identifier);
        identifier = providerSpecifier + twiturl.getQuery();
    }
    logger.debug("identifier:>" + identifier + "<");
    logger.debug("providerName:>" + providerName + "<");
    logger.debug("name:>" + name + "<");
    logger.debug("email:>" + email + "<");
    logger.debug("verifiedEmail:>" + verifiedEmail + "<");
    logger.debug("providerSpecifier:>" + providerSpecifier + "<");

    return new JanrainAuthenticationToken(identifier, verifiedEmail, email, providerName, name);
}