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:eu.roschi.obdkinesis.webserver.GetCountsServlet.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 www .j  a  va2  s .  com*/
    }

    // 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<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>();
    HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount();
    hashKey.setResource(resource);
    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));

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

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

From source file:com.ankang.report.resolver.AbstractReportResolver.java

protected void resolverParamter(HttpServletRequest request, String key) {

    if (null == request) {
        return;//  w w w  . j av  a2s. co m
    }

    if (null != (params = sessionCache.get(request.getServletPath() + request.getQueryString() + key))) {
        return;
    }

    String parameter = getParameter(request, key);

    if (null == parameter) {
        return;
    }
    if (this.getClass().isAssignableFrom(XmlProtocolResolver.class)) {
        XMLSerializer xs = new XMLSerializer();
        parameter = xs.read(parameter).toString();
    }
    params = JSONObject.parseObject(parameter);
    sessionCache.put(request.getServletPath() + request.getQueryString() + key, params);

}

From source file:com.alertlogic.aws.kinesis.test1.webserver.GetCountsServlet.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   w w  w  . j  ava 2 s  .co 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<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>();
    HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount();
    hashKey.setResource(resource);
    query.setHashKeyValues(hashKey);

    Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT)
            .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime)));
    query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates));

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

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

From source file:org.mocksy.rules.http.HttpProxyRule.java

protected HttpRequestBase getProxyMethod(HttpServletRequest request) {
    String proxyUrl = this.proxyUrl;
    proxyUrl += request.getPathInfo();/*from   ww w. ja va2 s  .c o m*/
    if (request.getQueryString() != null) {
        proxyUrl += "?" + request.getQueryString();
    }
    HttpRequestBase method = null;
    if ("GET".equals(request.getMethod())) {
        method = new HttpGet(proxyUrl);
        method.addHeader("Cache-Control", "no-cache");
        method.addHeader("Pragma", "no-cache");
    } else if ("POST".equals(request.getMethod())) {
        method = new HttpPost(proxyUrl);

        Map<String, String[]> paramMap = request.getParameterMap();
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        for (String paramName : paramMap.keySet()) {
            String[] values = paramMap.get(paramName);
            for (String value : values) {
                NameValuePair param = new BasicNameValuePair(paramName, value);
                params.add(param);
            }
        }

        try {
            ((HttpPost) method).setEntity(new UrlEncodedFormEntity(params));
        } catch (UnsupportedEncodingException e) {
            // don't worry, this won't happen
        }
    }

    Enumeration headers = request.getHeaderNames();
    while (headers.hasMoreElements()) {
        String header = (String) headers.nextElement();
        if ("If-Modified-Since".equals(header) || "Content-Length".equals(header)
                || "Transfer-Encoding".equals(header))
            continue;
        Enumeration values = request.getHeaders(header);
        while (values.hasMoreElements()) {
            String value = (String) values.nextElement();
            method.addHeader(header, value);
        }
    }

    return method;
}

From source file:psiprobe.controllers.jsp.DiscardCompiledJspController.java

@Override
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    getContainerWrapper().getTomcatContainer().discardWorkDir(context);
    return new ModelAndView(
            new RedirectView(request.getContextPath() + getViewName() + "?" + request.getQueryString()));
}

From source file:org.openmrs.module.openhmis.cashier.web.controller.BillAddEditController.java

private String buildUrlModelAttribute(HttpServletRequest request) {
    return UrlUtil.formUrl(CashierWebConstants.BILL_PAGE)
            + ((request.getQueryString() != null) ? "?" + request.getQueryString() : "");
}

From source file:com.thorpora.module.core.error.ErrorLogger.java

public void logServletError(Logger logger, HttpServletRequest request, HttpServletResponse response) {
    String requestFullpath = request.getRequestURI();
    if (request.getQueryString() != null) {
        requestFullpath += "?" + request.getQueryString();
    }/*from  ww w . ja v  a 2s.  com*/
    String msg = String.format("Servlet error [%s] : %s (will forward to /error)", response.getStatus(),
            requestFullpath);
    if (response.getStatus() >= 500) {
        logger.error(msg);
    } else {
        logger.info(msg);
    }
}

From source file:com.bitranger.parknshop.admin.CtrlIndex.java

@RequestMapping(value = "/redirect/ad/detail", method = RequestMethod.GET)
public void redAd(HttpServletRequest request, HttpServletResponse resp) {

    //      detail?id=????
    System.out.println("CtrlIndex.red()");
    System.out.println(request.getRequestURI());
    System.out.println(request.getQueryString());

}

From source file:com.jnj.b2b.storefront.filters.StorefrontFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final HttpSession session = httpRequest.getSession();
    final String queryString = httpRequest.getQueryString();

    if (isSessionNotInitialized(session, queryString)) {
        initDefaults(httpRequest);/*from  w w  w.  jav a  2 s . co m*/

        markSessionInitialized(session);
    }

    // For secure requests ensure that the JSESSIONID cookie is visible to insecure requests
    if (isRequestSecure(httpRequest)) {
        fixSecureHttpJSessionIdCookie(httpRequest, (HttpServletResponse) response);
    }

    if (isGetMethod(httpRequest)) {
        if (StringUtils.isBlank(httpRequest.getHeader(AJAX_REQUEST_HEADER_NAME))) {
            session.setAttribute(ORIGINAL_REFERER, httpRequest.getRequestURL().toString());
        }

        getBrowseHistory().addBrowseHistoryEntry(new BrowseHistoryEntry(httpRequest.getRequestURI(), null));
    }

    chain.doFilter(request, response);
}

From source file:com.bluexml.side.Framework.alfresco.shareLanguagePicker.CustomWebScriptServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Processing request (" + req.getMethod() + ") " + req.getRequestURL()
                + (req.getQueryString() != null ? "?" + req.getQueryString() : ""));
    }//from w ww .  j av  a2s . c om

    if (req.getCharacterEncoding() == null) {
        req.setCharacterEncoding("UTF-8");
    }
    // initialize the request context
    RequestContext context = null;
    try {
        context = FrameworkHelper.initRequestContext(req);
    } catch (Exception ex) {
        throw new ServletException(ex);
    }
    LanguageSetter.setLanguageFromLayoutParam(req, context);

    WebScriptServletRuntime runtime = new WebScriptServletRuntime(container, authenticatorFactory, req, res,
            serverProperties);
    runtime.executeScript();
}