Example usage for javax.servlet.http HttpServletRequest getQueryString

List of usage examples for javax.servlet.http HttpServletRequest getQueryString

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getQueryString.

Prototype

public String getQueryString();

Source Link

Document

Returns the query string that is contained in the request URL after the path.

Usage

From source file:net.duckling.ddl.web.interceptor.access.VWBDenyListener.java

private String getRequestURL(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    if (url.endsWith("/")) {
        url = url.substring(0, url.length() - 1);
    }//from  www.  jav a 2  s .  com

    if (request.getQueryString() != null) {
        url = url + "?" + request.getQueryString();

    }
    return url;
}

From source file:com.ibm.sbt.service.basic.ProxyEndpointService.java

@Override
protected String getRequestURLQueryString(HttpServletRequest request) throws ServletException {
    String queryargs = request.getQueryString();
    String proxyqueryargs = endpoint.getProxyQueryArgs();
    if (proxyqueryargs != null) {
        if (queryargs == null)
            return proxyqueryargs;
        else//w w  w .j  av a2s . c  o  m
            return queryargs + "&" + proxyqueryargs;
    }
    return queryargs;
}

From source file:com.tbodt.jswerve.servlet.JSwerveServlet.java

private URI extractUri(HttpServletRequest req) throws ServletException {
    try {//from   www .  j  av  a 2s  .c  o  m
        return new URI(req.getScheme(), UrlUtils.decode(req.getServerName()),
                UrlUtils.decode(req.getRequestURI()), UrlUtils.decode(req.getQueryString()), null);
    } catch (URISyntaxException ex) {
        throw new ServletException("Damn! URI syntax!", ex);
    }
}

From source file:com.predic8.membrane.servlet.embedded.RStudioMembraneServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String queryString = req.getQueryString() == null ? "" : "?" + req.getQueryString();

    Router router;/*ww w. ja v  a2 s.  com*/

    // For websockets, the following paths are used by JupyterHub:
    //  /(user/[^/]*)/(api/kernels/[^/]+/channels|terminals/websocket)/?
    // forward to ws(s)://servername:port_number
    //<LocationMatch "/mypath/(user/[^/]*)/(api/kernels/[^/]+/channels|terminals/websocket)(.*)">
    //    ProxyPassMatch ws://localhost:8999/mypath/$1/$2$3
    //    ProxyPassReverse ws://localhost:8999 # this may be superfluous
    //</LocationMatch>
    //        ProxyPass /api/kernels/ ws://192.168.254.23:8888/api/kernels/
    //        ProxyPassReverse /api/kernels/ http://192.168.254.23:8888/api/kernels/
    List<NameValuePair> pairs;
    try {
        //note: HttpClient 4.2 lets you parse the string without building the URI
        pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8");
    } catch (URISyntaxException e) {
        throw new ServletException("Unexpected URI parsing error on " + queryString, e);
    }
    LinkedHashMap<String, String> params = new LinkedHashMap<>();
    for (NameValuePair pair : pairs) {
        params.put(pair.getName(), pair.getValue());
    }

    String externalIp = Ip.getHost(req.getRequestURL().toString());

    StringBuffer urlBuf = new StringBuffer("http://localhost:");

    String ctxPath = req.getRequestURI();

    int x = ctxPath.indexOf("/rstudio");
    int firstSlash = ctxPath.indexOf('/', x + 1);
    int secondSlash = ctxPath.indexOf('/', firstSlash + 1);
    String portString = ctxPath.substring(firstSlash + 1, secondSlash);
    Integer targetPort;
    try {
        targetPort = Integer.parseInt(portString);
    } catch (NumberFormatException ex) {
        logger.error("Invalid target port in the URL: " + portString);
        return;
    }
    urlBuf.append(portString);

    String newTargetUri = urlBuf.toString() + req.getRequestURI();

    StringBuilder newQueryBuf = new StringBuilder();
    newQueryBuf.append(newTargetUri);
    newQueryBuf.append(queryString);

    URI targetUriObj = null;
    try {
        targetUriObj = new URI(newQueryBuf.toString());
    } catch (Exception e) {
        throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e);
    }
    ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(externalIp, "*", "*", -1), "localhost", targetPort);
    //    ServiceProxy sp = new ServiceProxy(
    //            new ServiceProxyKey(
    //                    externalIp, "*", "*", -1),
    //            "localhost", targetPort);
    sp.setTargetURL(newQueryBuf.toString());
    // only set external hostname in case admin console is used
    try {
        router = new HopsRouter(targetUriObj);
        router.add(sp);
        router.init();
        ProxyRule proxy = new ProxyRule(new ProxyRuleKey(-1));
        router.getRuleManager().addProxy(proxy, RuleManager.RuleDefinitionSource.MANUAL);
        router.getRuleManager().addProxy(sp, RuleManager.RuleDefinitionSource.MANUAL);
        new HopsServletHandler(req, resp, router.getTransport(), targetUriObj).run();
    } catch (Exception ex) {
        Logger.getLogger(RStudioMembraneServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.kinesis.datavis.servlet.GetBidRqCountsServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    MultiMap<String> params = new MultiMap<>();
    UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8");

    // We need both parameters to properly query for counts
    if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;/*from   ww  w  .j  a v a2  s. c o  m*/
    }

    // Parse query string as a single integer - the number of seconds since "now" to query for new counts
    String resource = params.getString(PARAMETER_RESOURCE);
    int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS));

    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, -1 * rangeInSeconds);
    Date startTime = c.getTime();
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Querying for counts of resource %s since %s", resource,
                DATE_FORMATTER.get().format(startTime)));
    }

    DynamoDBQueryExpression<BidRequestCount> query = new DynamoDBQueryExpression<>();

    BidRequestCount hashKey = new BidRequestCount();
    hashKey.setHashKey(Ticker.getInstance().hashKey());

    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    //        Condition attrFilter =
    //                new Condition().
    //                        withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(resource));

    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));
    //        query.setQueryFilter(Collections.singletonMap("wh", attrFilter));

    List<BidRequestCount> counts = mapper.query(BidRequestCount.class, query);

    //        System.out.println(counts.size());
    // Return the counts as JSON
    resp.setContentType("application/json");
    resp.setStatus(HttpServletResponse.SC_OK);
    JSON.writeValue(resp.getWriter(), counts);
}

From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter writer = response.getWriter();

    if (request.getQueryString() != null && request.getQueryString().equals("wsdl")) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("text/xml");
        writeWsdl(writer);//from  w  w  w  .j  a v  a  2s .  com
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.setContentType("text/html");
        writer.append("404: page not found");
    }

    writer.flush();
    writer.close();
}

From source file:org.sakaiproject.imagegallery.integration.standalone.ImageStreamingController.java

/**
 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*www . ja v a2 s.  c om*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    if (log.isInfoEnabled())
        log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo()
                + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL="
                + request.getRequestURL() + ", servlet=" + request.getServletPath());
    String fileId = request.getPathInfo().substring(1);
    ImageFile imageFile = fileLibraryService.getImageFile(fileId);
    response.setContentType(imageFile.getContentType());
    FileStreamer fileStreamer = (FileStreamer) fileLibraryService;
    fileStreamer.streamImage(fileId, response.getOutputStream());
    return null;
}

From source file:com.apress.progwt.server.web.controllers.ErrorController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse arg1)
        throws Exception {

    log.error("\nErrorController reqServ " + req.getServletPath() + " PathInfo:" + req.getPathInfo()
            + " Param: " + req.getParameterNames().toString() + " Q: " + req.getQueryString() + "</>");

    //        if(log.isDebugEnabled()){
    //            for(Object s :req.getParameterMap().keySet()){
    //                log.debug("param "+s);
    //            }
    //            Enumeration attrs = req.getAttributeNames();
    //            while(attrs.hasMoreElements()){
    //                String attr = (String) attrs.nextElement();
    //                log.debug("attr: "+attr+" "+req.getAttribute(attr));
    //            }
    //        }/*from w w  w. ja v a2 s. c om*/

    ModelAndView m = super.handleRequestInternal(req, arg1);
    String code = req.getParameter("code");
    if (code != null) {
        Object uri = req.getAttribute("javax.servlet.error.request_ uri");
        m.addObject("message", code + " error for page " + uri);
    }
    return m;
}

From source file:info.jtrac.web.RestMultiActionController.java

public void itemSearchGet(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String queryString = request.getQueryString();
    logger.debug("parsing queryString: " + queryString);
    ValueMap map = new ValueMap();
    RequestUtils.decodeParameters(queryString, map);
    logger.debug("decoded: " + map);
    User user = (User) request.getAttribute("user");
    PageParameters params = new PageParameters(map);
    ItemSearch itemSearch = ItemListPage.getItemSearch(jtrac, user, params);
    initXmlResponse(response);/* w  ww . j  av  a 2  s  .c om*/
    jtrac.writeAsXml(itemSearch, response.getWriter());
}

From source file:com.meetme.plugins.jira.gerrit.adminui.AdminServlet.java

private URI getUri(final HttpServletRequest request) {
    StringBuffer builder = request.getRequestURL();

    if (request.getQueryString() != null) {
        builder.append("?");
        builder.append(request.getQueryString());
    }/*from w w  w. j a  v a  2 s  .com*/

    return URI.create(builder.toString());
}