Example usage for java.net URI getQuery

List of usage examples for java.net URI getQuery

Introduction

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

Prototype

public String getQuery() 

Source Link

Document

Returns the decoded query component of this URI.

Usage

From source file:com.fatwire.dta.sscrawler.handlers.SSUnqualifiedBodyLinkHandler.java

void doLink(final String link, final ResultPage page) {
    log.trace(link);//from w  w w  .  ja  va  2 s .co m
    try {
        // <a
        // href='ssUnqualifiedLink?op=CM_Actualidad_FA&c=Page&op2=1142352029508&paginaActual=0&pagename=ComunidadMadrid%2FEstructura&subMenuP=subMenuPresidenta&language=es&cid=1109266752498'
        final URI uri = new URI(StringEscapeUtils.unescapeXml(link));
        // final URI uri = new URI(link);
        log.trace(uri.getQuery());
        final String[] val = uri.getQuery().split("&");
        final Link map = new Link();
        for (final String v : val) {
            if (v.startsWith("blobcol=")) {
                map.clear();
                break;
            } else {
                final int t = v.indexOf('=');
                map.addParameter(v.substring(0, t), v.substring(t + 1, v.length()));

            }
        }
        if (!map.isOK()) {
            page.addLink(map);
        }
    } catch (final URISyntaxException e) {
        log.error(e);
    }
}

From source file:cn.sinobest.websocket.handler.SimpleClientWebSocketHandler.java

/**
 * ???/*from w ww . j  a  v  a 2s  .com*/
 *
 * @param webSocketSession ?
 * @param key              ???
 * @return ?
 */
private String getAttributes(WebSocketSession webSocketSession, String key) {
    URI uri = webSocketSession.getUri();
    //userid=123&dept=4403
    String query = uri.getQuery();
    if (null != query && !"".equals(query)) {
        //??
        String[] queryArr = query.split("&");
        for (String queryItem : queryArr) {
            //userid=123
            String[] queryItemArr = queryItem.split("=");
            if (2 == queryItemArr.length) {
                if (key.equals(queryItemArr[0]))
                    return queryItemArr[1];
            }
        }
    }
    return null;
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * <p>// ww  w.ja va2 s. c  o m
 * Ensures that the specified {@link URI}'s path component ends with a slash
 * character (<code>/</code>).
 * </p>
 *
 * <p>
 * {@link URI}s that will be resolved against should always have a trailing
 * slash in their path component. For more information, see Sun Java bug
 * 4666701 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4666701).
 * </p>
 *
 * <p>
 * If the specified {@link URI} is opaque, it is returned. If the specified
 * {@link URI} is hierarchical and its path component already ends in a
 * slash, it is returned. Otherwise, a new {@link URI} is returned that is
 * identical to the specified {@link URI} except in its path component,
 * which will have a slash appended on.
 * </p>
 *
 * @param uri
 *        a {@link URI} to check (must not be <code>null</code>)
 * @return a {@link URI} as described above (never <code>null</code>)
 */
public static URI ensurePathHasTrailingSlash(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    if (uri.isOpaque()) {
        return uri;
    }

    String path = uri.getPath();
    if (path != null && path.endsWith("/")) //$NON-NLS-1$
    {
        return uri;
    }

    if (path == null) {
        path = "/"; //$NON-NLS-1$
    } else {
        path = path + "/"; //$NON-NLS-1$
    }

    return newURI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment());
}

From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java

@Test
public void shouldCreateUriWithParameters() throws Exception {
    URI uri = RequestHelper.createUri(URL, RequestParameters.init().set("a", "b"));
    assertThat(uri.getQuery(), is("a=b"));
}

From source file:org.openlmis.fulfillment.service.request.RequestHelperTest.java

@Test
public void shouldCreateUriWithEncodedParameters() throws Exception {
    URI uri = RequestHelper.createUri(URL, RequestParameters.init().set("a", "b c"));
    assertThat(uri.getQuery(), is("a=b c"));
    assertThat(uri.getRawQuery(), is("a=b%20c"));
}

From source file:proci.WebHandler.java

@Override
public void handle(HttpExchange t) throws IOException {
    logger.debug("HttpExchange from: {}", t.getRemoteAddress().getHostString());
    for (Map.Entry entry : t.getRequestHeaders().entrySet()) {
        logger.debug("header: {},{}", entry.getKey(), entry.getValue());
    }/*from  ww  w .  j av a 2s  .  com*/
    URI uri = t.getRequestURI();
    logger.debug("Path: {}", uri.getPath());
    logger.debug("Query: {}", uri.getQuery());
    String page = uri.getPath().replaceAll(App.HTTPCONTEXT, "").substring(1);
    logger.debug("Page: {}", page);
    //
    int code = 0;
    String response;
    JSONObject respJSON = new JSONObject();
    t.getResponseHeaders().add("Content-type:", "application/json");
    // tratto per semplicit allo stesso modo tutti i request method (POST,GET..)
    switch (page) {
    // funzione di status
    case "status":
        respJSON.put("status", "OK");
        respJSON.put("message", "Proci ver.: " + App.VERSION);
        code = 200;
        break;
    // upload immagine (solo se nella funzione)
    case "send":
        StringWriter sw = new StringWriter();
        IOUtils.copy(t.getRequestBody(), sw, "UTF-8");
        String in = sw.toString();
        logger.debug("String in: {}", in);
        JSONParser parser = new JSONParser();
        try {
            JSONObject obj2 = (JSONObject) parser.parse(in);
        } catch (ParseException pe) {
            respJSON.put("status", "ERRORE!");
            respJSON.put("message", "PARSE EXCEPTION: " + pe.getLocalizedMessage());
        }
        code = 200;
        break;
    default:
        respJSON.put("status", "ERRORE!");
        respJSON.put("message", "Pagina non trovata!");
        code = 404;
    }
    // risposta
    response = respJSON.toJSONString();
    t.sendResponseHeaders(code, response.getBytes("UTF-8").length);
    try (OutputStream os = t.getResponseBody()) {
        os.write(response.getBytes());
    }
}

From source file:fr.ippon.wip.http.request.RequestBuilderFactory.java

/**
 * Return a request instance. The request type will be PostRequest if the
 * resource type is POST, GetRequest otherwise.
 * //from www . j  a  v a  2s .  co  m
 * @param requestedURL
 *            request url
 * @param resourceType
 *            resource type, if any
 * @param httpMethod
 *            http method, if any
 * @param originalMap
 *            parameters map, if any
 * @return a implementation of Request
 */
public RequestBuilder getRequest(PortletRequest portletRequest, String requestedURL, ResourceType resourceType,
        HttpMethod httpMethod, Map<String, String[]> originalMap, boolean isMultipart) {
    URI uri = URI.create(requestedURL);
    String query = uri.getQuery();

    Multimap<String, String> parameterMap = ArrayListMultimap.create();
    if (originalMap != null)
        for (Entry<String, String[]> entry : originalMap.entrySet())
            for (String value : entry.getValue())
                parameterMap.put(entry.getKey(), value);

    if (!Strings.isNullOrEmpty(query)) {
        // hack; can't figure why separators are sometime "&" or "&amp;"...
        query = query.replaceAll("amp;", "");

        requestedURL = uri.getScheme() + "://" + uri.getHost()
                + (uri.getPort() == -1 ? "" : ":" + uri.getPort()) + uri.getPath();
        updateParameterMap(parameterMap, query);
    }

    if (isMultipart) {
        try {
            return new MultipartRequestBuilder(requestedURL, resourceType, (ActionRequest) portletRequest,
                    parameterMap);
        } catch (FileUploadException e) {
            e.printStackTrace();
            return null;
        }

    } else if (httpMethod == HttpMethod.POST)
        return new PostRequestBuilder(requestedURL, resourceType, parameterMap);
    else
        return new GetRequestBuilder(requestedURL, resourceType, parameterMap);
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * <p>/*from   ww  w.jav a  2s  . c o m*/
 * Ensures that all the components of the {@link URI} are in lower-case.
 * </p>
 *
 * <p>
 * If the specified {@link URI} is opaque, it is returned. Otherwise, a new
 * {@link URI} is returned that is identical to the specified {@link URI}
 * except that the components (scheme, hostname, path) are converted to
 * their lower case equivalents (in a generic locale.)
 * </p>
 *
 * @param uri
 *        a {@link URI} to check (must not be <code>null</code>)
 * @return a {@link URI} as described above (never <code>null</code>)
 */
public static URI toLowerCase(final URI uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    if (uri.isOpaque()) {
        return uri;
    }

    final String scheme = uri.getScheme() != null ? uri.getScheme().toLowerCase(LocaleUtil.ROOT) : null;
    final String authority = uri.getAuthority() != null ? uri.getAuthority().toLowerCase(LocaleUtil.ROOT)
            : null;
    final String path = uri.getPath() != null ? uri.getPath().toLowerCase(LocaleUtil.ROOT) : null;
    final String query = uri.getQuery() != null ? uri.getQuery().toLowerCase(LocaleUtil.ROOT) : null;
    final String fragment = uri.getFragment() != null ? uri.getFragment().toLowerCase(LocaleUtil.ROOT) : null;

    return newURI(scheme, authority, path, query, fragment);
}

From source file:com.collective.celos.ci.deploy.JScpWorker.java

URI getURIRespectingUsername(URI uri) throws URISyntaxException {

    if (userName != null && uri.getUserInfo() == null) {
        uri = new URI(uri.getScheme(), userName, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
                uri.getFragment());//from   ww  w.j av a 2  s  .c om
    }
    return uri;
}