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:com.epam.cme.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from
 * cmscockpit)// ww w.  j  av a2s.com
 * <p/>
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 * 
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *            current request
 * @param httpResponse
 *            the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    // set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())
            && !SiteChannel.TELCO.equals(cmsSiteModel.getChannel())) // Restrict to B2C and
                                                                                                                                   // Telco channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    // set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:io.druid.server.AsyncManagementForwardingServlet.java

@Override
protected String rewriteTarget(HttpServletRequest request) {
    try {//w  ww. ja  v a  2  s . com
        return new URIBuilder((String) request.getAttribute(BASE_URI_ATTRIBUTE))
                .setPath(request.getAttribute(MODIFIED_PATH_ATTRIBUTE) != null
                        ? (String) request.getAttribute(MODIFIED_PATH_ATTRIBUTE)
                        : request.getRequestURI())
                .setQuery(request.getQueryString()) // No need to encode-decode queryString, it is already encoded
                .build().toString();
    } catch (URISyntaxException e) {
        log.error(e, "Unable to rewrite URI [%s]", e.getMessage());
        throw Throwables.propagate(e);
    }
}

From source file:org.venice.beachfront.bfapi.services.GeoServerProxyService.java

public ResponseEntity<byte[]> proxyRequest(HttpServletRequest request)
        throws MalformedURLException, IOException, URISyntaxException, UserException {
    String requestPath = request.getRequestURI();
    // Form the complete URI by piecing together the GeoServer URL with the API proxy request parameters
    URI requestUri = new URI(geoserverUrl.getProtocol(), null, geoserverUrl.getHost(), geoserverUrl.getPort(),
            requestPath, request.getQueryString(), null);
    // Double encoding takes place here. First, in the REST Request delivered to API by the client. Second, in the
    // translation to the URI object. Decode both of these steps to get the real, completely decoded request to
    // GeoServer.
    String decodedUrl = URLDecoder.decode(requestUri.toString(), "UTF-8");
    decodedUrl = URLDecoder.decode(decodedUrl.toString(), "UTF-8");
    piazzaLogger.log(String.format("Proxying request to GET GeoServer at URI %s", decodedUrl),
            Severity.INFORMATIONAL);
    try {//ww w . java2 s.  c  o  m
        ResponseEntity<byte[]> response = restTemplate.exchange(decodedUrl, HttpMethod.GET, requestHeaders,
                byte[].class);
        return response;
    } catch (HttpClientErrorException | HttpServerErrorException exception) {
        piazzaLogger.log(String.format("Received GeoServer error response, code=%d, length=%d, for URI %s",
                exception.getStatusCode().value(), exception.getResponseBodyAsString().length(), decodedUrl),
                Severity.ERROR);
        if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)
                || exception.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
            throw new UserException("Bad Authentication with GeoServer", exception,
                    exception.getResponseBodyAsString(), HttpStatus.BAD_REQUEST);
        }
        throw new UserException("Upstream GeoServer error", exception, exception.getResponseBodyAsString(),
                exception.getStatusCode());
    }
}

From source file:com.adito.boot.Util.java

/**
 * Rebuild the URI of the request by concatenating the servlet path and and
 * request parameters// www  . j ava2  s  . co  m
 * 
 * @param request request to extra path from
 * @return path
 */
public static String getOriginalRequest(HttpServletRequest request) {
    StringBuffer req = new StringBuffer(request.getServletPath());
    if (request.getQueryString() != null && request.getQueryString().length() > 0) {
        req.append("?");
        req.append(request.getQueryString());
    }
    return req.toString();
}

From source file:org.flowable.ui.modeler.service.FlowableModelQueryService.java

public ResultListDataRepresentation getModels(String filter, String sort, Integer modelType,
        HttpServletRequest request) {

    // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing.
    String filterText = null;//  w w  w. j  av  a 2s  .  c om
    List<NameValuePair> params = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8"));
    if (params != null) {
        for (NameValuePair nameValuePair : params) {
            if ("filterText".equalsIgnoreCase(nameValuePair.getName())) {
                filterText = nameValuePair.getValue();
            }
        }
    }

    List<ModelRepresentation> resultList = new ArrayList<>();
    List<Model> models = null;

    String validFilter = makeValidFilterText(filterText);

    if (validFilter != null) {
        models = modelRepository.findByModelTypeAndFilter(modelType, validFilter, sort);

    } else {
        models = modelRepository.findByModelType(modelType, sort);
    }

    if (CollectionUtils.isNotEmpty(models)) {
        List<String> addedModelIds = new ArrayList<>();
        for (Model model : models) {
            if (!addedModelIds.contains(model.getId())) {
                addedModelIds.add(model.getId());
                ModelRepresentation representation = createModelRepresentation(model);
                resultList.add(representation);
            }
        }
    }

    ResultListDataRepresentation result = new ResultListDataRepresentation(resultList);
    return result;
}

From source file:com.atlassian.jira.web.dispatcher.JiraWebworkActionDispatcher.java

private String getDestinationUrl(HttpServletRequest httpServletRequest) {
    return JiraUrlCodec.encode(httpServletRequest.getServletPath()
            + (httpServletRequest.getPathInfo() == null ? "" : httpServletRequest.getPathInfo())
            + (httpServletRequest.getQueryString() == null ? "" : "?" + httpServletRequest.getQueryString()));
}

From source file:com.graphhopper.http.GraphHopperServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {//from   ww w  . j a  v a 2 s.c o  m
        writePath(req, res);
    } catch (IllegalArgumentException ex) {
        writeError(res, SC_BAD_REQUEST, ex.getMessage());
    } catch (Exception ex) {
        logger.error("Error while executing request: " + req.getQueryString(), ex);
        writeError(res, SC_INTERNAL_SERVER_ERROR, "Problem occured:" + ex.getMessage());
    }
}

From source file:com.ctc.storefront.filters.cms.CMSSiteFilter.java

/**
 * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit)
 * <p/>//  www  .  ja  v a2  s  . c  om
 * <b>Note:</b> <br/>
 * We preparing application by setting correct:
 * <ul>
 * <li>Current Site</li>
 * <li>Current Catalog Versions</li>
 * <li>Enabled language fallback</li>
 * </ul>
 *
 * @see ContextInformationLoader#initializeSiteFromRequest(String)
 * @see ContextInformationLoader#setCatalogVersions()
 * @param httpRequest
 *           current request
 * @param httpResponse
 *           the http response
 * @throws java.io.IOException
 */
protected boolean processNormalRequest(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse) throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    //set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
        final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/")
                + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

        cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
        // Failed to lookup CMS site
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
        return false;
    } else if (!getSiteChannelValidationStrategy().validateSiteChannel(cmsSiteModel.getChannel())) // Restrict to configured channel
    {
        // CMS site that we looked up was for an unsupported channel
        httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
        return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
        throw new IllegalStateException(
                "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    //set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
}

From source file:org.flymine.web.ChartRenderer.java

/**
 * First, check for a cached image, otherwise defer to appropriate method.
 *
 * @param mapping The ActionMapping used to select this instance
 * @param form The optional ActionForm bean for this request (if any)
 * @param request The HTTP request we are processing
 * @param response The HTTP response we are creating
 * @return an ActionForward object defining where control goes next
 * @exception Exception if the application business logic throws
 *  an exception//from w w w .  ja v a2  s . c  o m
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession();
    ServletContext servletContext = session.getServletContext();
    Map graphImageCache = (Map) servletContext.getAttribute(Constants.GRAPH_CACHE);
    String filename = (String) graphImageCache.get(request.getQueryString());

    if (filename != null) {
        //ServletUtilities.sendTempFile(filename, response);
        return null;
    }
    Method method = getClass().getMethod(request.getParameter("method"), SIG);
    if (!"execute".equals(method.getName())) { // avoid infinite loop
        return (ActionForward) method.invoke(this, new Object[] { mapping, form, request, response });
    }
    LOG.error("bad method parameter \"" + request.getParameter("method") + "\"");
    return null;
}

From source file:com.jaeksoft.searchlib.web.AbstractServlet.java

private void buildUrls(HttpServletRequest request) throws MalformedURLException {
    serverBaseURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(),
            request.getContextPath()).toString();
    StringBuilder sbUrl = new StringBuilder(request.getRequestURI());
    String qs = request.getQueryString();
    if (qs != null) {
        sbUrl.append('?');
        sbUrl.append(qs);/*  w ww  . j a  v a 2s. c om*/
    }
    URL url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), sbUrl.toString());
    serverURL = url.toString();
}