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.reelfx.model.PostProcessor.java

/**
 * s/*w  ww  . j a  v  a 2 s.  com*/
 * 
 * @param url
 */
private void setPostURI(String url) {
    try {
        URI given = new URI(url);
        String query = given.getQuery() == null ? "" : given.getQuery();
        query = query + (query.isEmpty() ? "" : "&")
                + (Applet.API_KEY.isEmpty() ? "" : "api_key=" + Applet.API_KEY);
        postUrl = new URI(given.getScheme(), given.getAuthority(), given.getPath(), query, given.getFragment());
    } catch (Exception e) {
        logger.error("Error occurred while processing the post URL (received: " + url + ")", e);
        fireProcessUpdate(POST_FAILED);
    }
}

From source file:com.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java

private boolean locateEmbedClickCapture(List<WebElement> embedElements) throws SearchLibException, IOException {
    if (embedElements == null)
        return false;
    for (WebElement embedElement : embedElements) {
        if (!embedElement.isDisplayed())
            continue;
        embedSrc = embedElement.getAttribute("src");
        String flashVars = embedElement.getAttribute("flashvars");
        if (!StringUtils.isEmpty(flashVars)) {
            try {
                URI uri = new URI(embedSrc);
                flashVars = uri.getQuery();
            } catch (URISyntaxException e) {
                Logging.warn(e);//  w ww  .  j  a  va  2  s  .c  om
            }
        }
        String[] params = StringUtils.split(flashVars, '&');
        Map<String, String> paramMap = new TreeMap<String, String>();
        if (params != null) {
            for (String param : params) {
                String[] keyValue = StringUtils.split(param, '=');
                if (keyValue != null && keyValue.length == 2)
                    paramMap.put(keyValue[0].toLowerCase(), URLDecoder.decode(keyValue[1], "UTF-8"));
            }
        }
        if (selector.flashVarsLink != null)
            anchorHref = paramMap.get(selector.flashVarsLink);
        return true;
    }
    return false;
}

From source file:org.opendatakit.aggregate.servlet.MultimodeLoginPageServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    CallingContext cc = ContextFactory.getCallingContext(this, req);

    // Check to make sure we are using the canonical server name.
    // If not, redirect to that name.  This ensures that authentication
    // cookies will have the proper realm(s) established for them.
    String newUrl = cc.getServerURL() + BasicConsts.FORWARDSLASH + ADDR;
    String query = req.getQueryString();
    if (query != null && query.length() != 0) {
        newUrl += "?" + query;
    }/*from   w  w  w.  ja  va 2 s  . c  o  m*/
    URL url = new URL(newUrl);
    if (!url.getHost().equalsIgnoreCase(req.getServerName())) {
        logger.info("Incoming servername: " + req.getServerName() + " expected: " + url.getHost()
                + " -- redirecting.");
        // try to get original destination URL from Spring...
        String redirectUrl = getRedirectUrl(req, ADDR);
        try {
            URI uriChangeable = new URI(redirectUrl);
            URI newUri = new URI(url.getProtocol(), null, url.getHost(), url.getPort(), uriChangeable.getPath(),
                    uriChangeable.getQuery(), uriChangeable.getFragment());
            newUrl = newUri.toString();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        // go to the proper page (we'll most likely be redirected back to here for authentication)
        resp.sendRedirect(newUrl);
        return;
    }

    // OK. We are using the canonical server name.
    String redirectParamString = getRedirectUrl(req, AggregateHtmlServlet.ADDR);
    // we need to appropriately cleanse this string for the OpenID login
    // strip off the server pathname portion
    if (redirectParamString.startsWith(cc.getSecureServerURL())) {
        redirectParamString = redirectParamString.substring(cc.getSecureServerURL().length());
    } else if (redirectParamString.startsWith(cc.getServerURL())) {
        redirectParamString = redirectParamString.substring(cc.getServerURL().length());
    }
    while (redirectParamString.startsWith("/")) {
        redirectParamString = redirectParamString.substring(1);
    }

    // check for XSS attacks. The redirect string is emitted within single and double
    // quotes. It is a URL with :, /, ? and # characters. But it should not contain 
    // quotes, parentheses or semicolons.
    String cleanString = redirectParamString.replaceAll(BAD_PARAMETER_CHARACTERS, "");
    if (!cleanString.equals(redirectParamString)) {
        logger.warn("XSS cleanup -- redirectParamString has forbidden characters: " + redirectParamString);
        redirectParamString = cleanString;
    }

    logger.info("Invalidating login session " + req.getSession().getId());
    // Invalidate session.
    HttpSession s = req.getSession();
    if (s != null) {
        s.invalidate();
    }
    // Display page.
    resp.setContentType(HtmlConsts.RESP_TYPE_HTML);
    resp.setCharacterEncoding(HtmlConsts.UTF8_ENCODE);
    resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    resp.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
    resp.setHeader("Pragma", "no-cache");
    resp.addHeader(HtmlConsts.X_FRAME_OPTIONS, HtmlConsts.X_FRAME_SAMEORIGIN);
    PrintWriter out = resp.getWriter();
    out.print(
            "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
                    + "<html>" + "<head>"
                    + "<meta http-equiv=\"cache-control\" content=\"no-store, no-cache, must-revalidate\"/>"
                    + "<meta http-equiv=\"expires\" content=\"Mon, 26 Jul 1997 05:00:00 GMT\"/>"
                    + "<meta http-equiv=\"pragma\" content=\"no-cache\"/>"
                    + "<link rel=\"icon\" href=\"favicon.ico\"/>" + "<title>Log onto Aggregate</title>"
                    + "<link type=\"text/css\" rel=\"stylesheet\" href=\"AggregateUI.css\">"
                    + "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/button.css\">"
                    + "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/table.css\">"
                    + "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/navigation.css\">"
                    + "<script type=\"text/javascript\">" + "window.onbeforeunload=function() {\n"
                    + "var e=document.getElementById(\"stale\");\n" + "e.value=\"yes\";\n" + "}\n"
                    + "window.onload=function(){\n" + "var e=document.getElementById(\"stale\");\n"
                    + "if(e.value==\"yes\") {window.location.reload(true);}\n" + "}\n" + "</script>" + "</head>"
                    + "<body>" + "<input type=\"hidden\" id=\"stale\" value=\"no\">"
                    + "<table width=\"100%\" cellspacing=\"30\"><tr>"
                    + "<td align=\"LEFT\" width=\"10%\"><img src=\"odk_color.png\" id=\"odk_aggregate_logo\" /></td>"
                    + "<td align=\"LEFT\" width=\"90%\"><font size=\"7\">Log onto Aggregate</font></td></tr></table>"
                    + "<table cellspacing=\"20\">" + "<tr><td valign=\"top\">"
                    + "<form action=\"local_login.html\" method=\"get\">" + "<script type=\"text/javascript\">"
                    + "<!--\n" + "document.write('<input name=\"redirect\" type=\"hidden\" value=\""
                    + redirectParamString + "' + window.location.hash + '\"/>');" + "\n-->" + "</script>"
                    + "<input class=\"gwt-Button\" type=\"submit\" value=\"Sign in with Aggregate password\"/>"
                    + "</form></td>"
                    + "<td valign=\"top\">Click this button to log onto Aggregate using the username "
                    + "and password that have been assigned to you by the Aggregate site administrator.</td></tr>"
                    + "<tr><td valign=\"top\">" + "<script type=\"text/javascript\">" + "<!--\n"
                    + "document.write('<form action=\"" + redirectParamString
                    + "' + window.location.hash + '\" method=\"get\">');"
                    + "document.write('<input class=\"gwt-Button\" type=\"submit\" value=\"Anonymous Access\"/></form>');"
                    + "\n-->" + "</script>" + "</td>"
                    + "<td valign=\"top\">Click this button to access Aggregate without logging in.</td></tr>"
                    + "</table>" + "</body>" + "</html>");
}

From source file:org.apache.shindig.gadgets.servlet.UrlGeneratorTest.java

@Test
public void getIframeUrlTypeUrl() throws Exception {
    String xml = "<Module>" + " <ModulePrefs title='test'/>" + " <Content type='url' href='"
            + StringEscapeUtils.escapeHtml(TYPE_URL_HREF) + "'/>" + " <UserPref name='" + UP_NAME
            + "' datatype='string'/>" + "</Module>";
    GadgetSpec spec = new GadgetSpec(URI.create(SPEC_URL), xml);
    Gadget gadget = new Gadget(context, spec, Collections.<JsLibrary>emptyList());
    fixture.replay();/*www .ja va2s  . c o m*/

    URI iframeUrl = URI.create(urlGenerator.getIframeUrl(gadget));

    assertEquals(TYPE_URL_HREF_HOST, iframeUrl.getAuthority());
    assertEquals(TYPE_URL_HREF_PATH, iframeUrl.getPath());
    StringAssert.assertContains(TYPE_URL_HREF_QUERY, iframeUrl.getQuery());
    StringAssert.assertContains("container=" + CONTAINER, iframeUrl.getQuery());
    StringAssert.assertContains("up_" + UP_NAME + '=' + UP_VALUE, iframeUrl.getQuery());
    StringAssert.assertContains("mid=" + MODULE_ID, iframeUrl.getQuery());
}

From source file:org.apache.nifi.web.ContentViewerController.java

/**
 * @param request request/*from ww w.j  a  va 2  s .  c  o  m*/
 * @return Get the content request context based on the specified request
 */
private ContentRequestContext getContentRequest(final HttpServletRequest request) {
    final String ref = request.getParameter("ref");
    final String clientId = request.getParameter("clientId");

    final URI refUri = URI.create(ref);
    final String query = refUri.getQuery();

    String rawClusterNodeId = null;
    if (query != null) {
        final String[] queryParameters = query.split("&");

        for (int i = 0; i < queryParameters.length; i++) {
            if (queryParameters[0].startsWith("clusterNodeId=")) {
                rawClusterNodeId = StringUtils.substringAfterLast(queryParameters[0], "clusterNodeId=");
            }
        }
    }
    final String clusterNodeId = rawClusterNodeId;

    return new ContentRequestContext() {
        @Override
        public String getDataUri() {
            return ref;
        }

        @Override
        public String getClusterNodeId() {
            return clusterNodeId;
        }

        @Override
        public String getClientId() {
            return clientId;
        }

        @Override
        public String getProxiedEntitiesChain() {
            return null;
        }
    };
}

From source file:org.rhq.enterprise.clientapi.RhqDownloadsScriptSourceProvider.java

@Override
protected Reader doGetScriptSource(URI scriptUri) {
    if (remoteClient == null) {
        return null;
    }// ww w . jav  a2s  . c  o m

    String path = scriptUri.getPath();

    URI remoteUri = remoteClient.getRemoteURI().resolve(URL_PATH_PREFIX + path);

    String replacementScheme = SecurityUtil.isTransportSecure(remoteUri.getScheme()) ? "https" : "http";

    try {
        remoteUri = new URI(replacementScheme, remoteUri.getAuthority(), remoteUri.getPath(),
                remoteUri.getQuery(), remoteUri.getFragment());
    } catch (URISyntaxException e) {
        LOG.error("Failed to copy the RHQ server download URI: " + remoteUri + " to the " + replacementScheme
                + " scheme.");
    }

    try {
        URL downloadUrl = remoteUri.toURL();

        return new InputStreamReader(downloadUrl.openStream());
    } catch (MalformedURLException e) {
        LOG.debug("Failed to download the script from the RHQ server using URL: " + remoteUri, e);
    } catch (IOException e) {
        LOG.debug("Failed to download the script from the RHQ server using URL: " + remoteUri, e);
    }

    return null;
}

From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java

public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters) {
    super();//from  ww w.  j a va  2 s .c  o m
    this.uri = base(uri);
    this.method = method;
    if (parameters != null) {
        this.parameters = parameters;
    } else {
        this.parameters = new ArrayList<NameValuePair>();
    }
    final String query = uri.getQuery();
    if (query != null) {
        final List<NameValuePair> other = URLEncodedUtils.parse(uri, "UTF-8");
        parameters.addAll(other);
    }
}

From source file:org.nuxeo.ecm.restapi.server.jaxrs.resource.wro.ResourceBundleWriter.java

@Override
public void writeTo(ResourceBundleDispatcher arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4,
        MultivaluedMap<String, Object> arg5, OutputStream arg6) throws IOException, WebApplicationException {
    try {/*from   ww w  . j av a  2s. c  o m*/
        URI uri = uriInfo.getRequestUri();
        String path = uri.getPath();
        // remove lead /nuxeo
        path = path.replaceFirst(servletContext.getContextPath(), "");
        // redirect to the wro servlet path
        path = path.replaceFirst("/site/api/", "/wapi/");
        URI dispatch = new URI(null, null, path, uri.getQuery(), uri.getFragment());
        servletContext.getRequestDispatcher(dispatch.toString()).forward(request, response);
    } catch (URISyntaxException | ServletException e) {
        log.error("Error while forwarding to Wro servlet", e);
    }
}

From source file:org.openhab.extensionservice.marketplace.internal.MarketplaceExtensionService.java

private String extractExensionId(URI uri) {
    Matcher idMatcher = EXTENSION_ID_PATTERN.matcher(uri.getQuery());
    String id = null;/*  w  w  w. j ava2s.  c o  m*/
    if (idMatcher.matches() && idMatcher.groupCount() > 1) {
        id = idMatcher.group(1);
    }

    Optional<Node> extensionNode = getExtensionNode(id);

    return extensionNode.isPresent() ? getExtensionId(extensionNode.get()) : null;
}

From source file:com.jgoetsch.eventtrader.source.SocketIOWebSocketMsgSource.java

protected String getTokenUrl() throws IOException, URISyntaxException {
    URI base = new URI(getUrl());
    BufferedReader tokenReader = new BufferedReader(
            new InputStreamReader(new URI("http", base.getUserInfo(), base.getHost(), base.getPort(),
                    base.getPath(), base.getQuery(), base.getFragment()).toURL().openStream()));
    String token = tokenReader.readLine();
    tokenReader.close();//from   w  w w. j a v a 2s. c  o m

    String r[] = token.split(":");
    String comp[] = getUrl().split("\\?");
    if (!comp[0].endsWith("/"))
        comp[0] += '/';
    return comp[0] + "websocket/" + r[0] + (comp.length > 0 ? "?" + comp[1] : "");
}