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:cz.jirutka.spring.exhandler.handlers.AbstractRestExceptionHandler.java

/**
 * Logs the exception; on ERROR level when status is 5xx, otherwise on INFO level without stack
 * trace, or DEBUG level with stack trace. The logger name is
 * {@code cz.jirutka.spring.exhandler.handlers.RestExceptionHandler}.
 *
 * @param ex The exception to log./* ww  w  . ja va 2s .  c  o m*/
 * @param req The current web request.
 */
protected void logException(E ex, HttpServletRequest req) {

    if (LOG.isErrorEnabled() && getStatus().value() >= 500 || LOG.isInfoEnabled()) {
        Marker marker = MarkerFactory.getMarker(ex.getClass().getName());

        String uri = req.getRequestURI();
        if (req.getQueryString() != null) {
            uri += '?' + req.getQueryString();
        }
        String msg = String.format("%s %s ~> %s", req.getMethod(), uri, getStatus());

        if (getStatus().value() >= 500) {
            LOG.error(marker, msg, ex);

        } else if (LOG.isDebugEnabled()) {
            LOG.debug(marker, msg, ex);

        } else {
            LOG.info(marker, msg);
        }
    }
}

From source file:ua.aits.sdolyna.controller.MainController.java

@RequestMapping(value = { "/500", "/Sdolyna/500" })
public ModelAndView error500(HttpServletRequest request, HttpServletResponse response) {
    Throwable exception = (Throwable) request.getAttribute("javax.servlet.error.exception");
    String url = request.getRequestURL().toString() + "?" + request.getQueryString();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);/*  w  ww .ja  v  a2s.  co m*/
    helpers.sendMail(url, sw.toString());
    ModelAndView model = new ModelAndView("/error/500");
    model.addObject("lan", "en");
    TranslateElements translate = new TranslateElements("en");
    model.addObject("lan", "en");
    model.addObject("translate", translate);
    return model;
}

From source file:com.zextras.zimbradrive.GetFileHttpHandler.java

private void doInternalGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws IOException {
    Map<String, String> paramsMap = new HashMap<>();
    String queryString = httpServletRequest.getQueryString();
    if (queryString != null) {
        String[] params = queryString.split("&");
        for (String param : params) {
            String[] paramPair = param.split("=");
            if (paramPair.length > 1) {
                paramsMap.put(paramPair[0], paramPair[1]);
            }//from w  w w  .j av a  2s  .co m
        }
    }
    Account account = mBackendUtils.assertAccountFromAuthToken(httpServletRequest);
    ZimbraLog.addAccountNameToContext(account.getName());
    String requestedUrl = httpServletRequest.getPathInfo();
    int lengthOfBaseUrl = this.getPath().length() + 2; //   "/" + this.getPath() + "/"
    String path = requestedUrl.substring(lengthOfBaseUrl);

    // Don't trigger *cloud if param preview=1
    if (paramsMap.containsKey("previewcallback")) {
        httpServletResponse.getWriter().print(this.triggerCallback(paramsMap.get("previewcallback")));
    } else {
        HttpResponse fileRequestResponse = mCloudHttpRequestUtils.queryCloudServerService(account, path);

        int responseCode = fileRequestResponse.getStatusLine().getStatusCode();
        if (responseCode < HTTP_LOWEST_ERROR_STATUS) {
            Header[] headers = fileRequestResponse.getAllHeaders();
            for (Header header : headers) {
                String headerName = header.getName();
                switch (header.getName()) {
                case CONTENT_DISPOSITION_HTTP_HEADER:
                    if (paramsMap.containsKey("viewonly") && (paramsMap.get("viewonly").equals("1"))) {
                        httpServletResponse.setHeader(headerName,
                                header.getValue().replace("attachment", "inline"));
                    } else {
                        httpServletResponse.setHeader(headerName, header.getValue());
                    }
                    break;
                case HttpHeaders.CONTENT_LENGTH:
                case HttpHeaders.CONTENT_TYPE:
                    httpServletResponse.setHeader(headerName, header.getValue());
                    break;
                }
            }
            try (OutputStream responseOutputStream = httpServletResponse.getOutputStream()) {
                fileRequestResponse.getEntity().writeTo(responseOutputStream);
            }
        } else {
            httpServletResponse.setStatus(responseCode);
            if (paramsMap.containsKey("errorcallback")) {
                httpServletResponse.getWriter().print(this.triggerCallback(paramsMap.get("errorcallback")));
            }
        }
    }
}

From source file:com.acc.storefront.filters.StorefrontFilter.java

@Override
public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    final HttpSession session = request.getSession();
    final String queryString = request.getQueryString();

    if (isSessionNotInitialized(session, queryString)) {
        initDefaults(request);/*from w ww  . j av  a 2 s  . c  o m*/

        markSessionInitialized(session);
    }

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

    if (isGetMethod(request)) {
        getBrowseHistory().addBrowseHistoryEntry(new BrowseHistoryEntry(request.getRequestURI(), null));
    }

    filterChain.doFilter(request, response);
}

From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolver.java

public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception exception) {

    if (!exception.getClass().equals(NoSuchFlowExecutionException.class)) {
        return null;
    }/*  www.jav  a  2  s .  c o m*/

    final String urlToRedirectTo = request.getRequestURI()
            + (request.getQueryString() != null ? "?" + request.getQueryString() : "");

    if (log.isDebugEnabled()) {
        log.debug("Error getting flow information for URL:" + urlToRedirectTo, exception);
    }

    return new ModelAndView(new RedirectView(urlToRedirectTo));
}

From source file:com.bluexml.side.Framework.alfresco.languagepicker.MyWebScriptServlet.java

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() : ""));

    if (req.getCharacterEncoding() == null) {
        req.setCharacterEncoding("UTF-8");
    }//  ww w.  j  a v  a 2 s. com

    setUserLanguage(req);

    try {
        WebScriptServletRuntime runtime = new WebScriptServletRuntime(container, authenticatorFactory, req, res,
                serverProperties);
        runtime.executeScript();
    } finally {
        // clear threadlocal
        I18NUtil.setLocale(null);
    }
}

From source file:info.magnolia.cms.util.ServletUtil.java

/**
 * Returns the original request url. If the request has been forwarded it reconstructs the url from  request
 * attributes. The returned url is not decoded.
 *///from ww w.  j  a v  a 2  s .  c  om
public static String getOriginalRequestURLIncludingQueryString(HttpServletRequest request) {
    if (request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE) != null) {
        StringBuilder builder = new StringBuilder();

        String scheme = request.getScheme();
        builder.append(scheme).append("://").append(request.getServerName());

        int port = request.getServerPort();
        if ((scheme.equalsIgnoreCase("http") && port == 80)
                || (scheme.equalsIgnoreCase("https") && port == 443)) {
            // adding port is not necessary
        } else {
            builder.append(":").append(port);
        }

        String requestUri = (String) request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE);
        builder.append(requestUri);

        String queryString = (String) request.getAttribute(FORWARD_QUERY_STRING_ATTRIBUTE);
        if (StringUtils.isNotEmpty(queryString)) {
            builder.append("?").append(queryString);
        }

        return builder.toString();
    }
    StringBuilder builder = new StringBuilder();
    builder.append(request.getRequestURL());
    String queryString = request.getQueryString();
    if (StringUtils.isNotEmpty(queryString)) {
        builder.append("?").append(queryString);
    }
    return builder.toString();
}

From source file:org.socialsignin.exfmproxy.mvc.ExFmProxyController.java

protected String getJson(HttpServletRequest request, String url) {
    String json = "";
    String method = request.getMethod().toLowerCase();
    if (method.equals("get")) {
        if (request.getQueryString() != null) {
            json = restTemplate.getForObject(url + "?" + request.getQueryString(), String.class);
        } else {//from ww w  . j  a  va2s. c  om
            json = restTemplate.getForObject(url, String.class);
        }
    } else if (method.equals("post")) {
        HttpHeaders requestHeaders = new HttpHeaders();

        requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

        HttpEntity<?> httpEntity = new HttpEntity<Object>(requestHeaders);
        json = restTemplate.postForEntity(url, httpEntity, String.class).getBody();

    }
    return json.trim();
}

From source file:eu.simpaticoproject.ife.controller.ProxyController.java

@RequestMapping(value = "/api/proxy/images", method = RequestMethod.GET)
public @ResponseBody HttpEntity<String> images(HttpServletRequest request) throws Exception {

    String urlToCall = imagesUrl;
    if (Utils.isNotEmpty(request.getQueryString())) {
        urlToCall = urlToCall + "?" + request.getQueryString();
    }/*from   www  .j  av  a 2  s .c  o m*/
    if (logger.isInfoEnabled()) {
        logger.info("images:" + urlToCall);
    }
    GetMethod responseConnection = HTTPUtils.getConnection(urlToCall, imagesKeyName, imagesKeyValue, null, null,
            request);

    HttpHeaders headers = new HttpHeaders();
    Header[] responseHeaders = responseConnection.getResponseHeaders();
    for (Header header : responseHeaders) {
        headers.add(header.getName(), header.getValue());
    }
    InputStream is = responseConnection.getResponseBodyAsStream();
    byte[] byteStream = IOUtils.toByteArray(is);
    String body = new String(byteStream, "UTF-8");
    return new HttpEntity<String>(body, headers);
}

From source file:psiprobe.controllers.apps.RemoveApplicationAttributeController.java

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

    String attrName = ServletRequestUtils.getStringParameter(request, "attr");
    context.getServletContext().removeAttribute(attrName);

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