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:org.artifactory.webapp.servlet.RepoFilter.java

private static String requestDebugString(HttpServletRequest request) {
    String queryString = request.getQueryString();
    String str = request.getMethod() + " (" + new HttpAuthenticationDetails(request).getRemoteAddress() + ") "
            + RequestUtils.getServletPathFromRequest(request) + (queryString != null ? queryString : "");
    return str;/*from  ww w . ja  v a  2s. co  m*/
}

From source file:br.eb.ime.pfc.domain.GeoServerCommunication.java

public static void redirectStreamFromRequest(HttpServletRequest request, HttpServletResponse response) {

    final String urlName = GEOSERVER_URL
            + request.getRequestURI().replace(request.getContextPath() + "/geoserver", "") + "?"
            + request.getQueryString();
    request.getServletContext().log("URL" + urlName);
    request.getServletContext().log("CONTEXT" + request.getContextPath());
    request.getServletContext().log("URL" + request.getRequestURI());
    redirectStream(urlName, request, response);
}

From source file:edu.umich.ctools.sectionsUtilityTool.Utils.java

public static void openFile(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    M_log.debug("Stub method called");
    String pathInfo = request.getPathInfo();
    M_log.debug("Path Info: " + pathInfo);

    String url = request.getPathInfo();
    String queryString = request.getQueryString();

    if (queryString != null) {
        url = pathInfo + "?" + queryString;
    }/*from www . j  a  va2 s  .c o m*/

    FileReader fr = null;

    if (url.matches(SectionsUtilityToolServlet.appExtPropertiesFile.getProperty(CANVAS_API_TERMS))) {
        fr = retrieveTestFile(url, fr, "Courses call stub", "/stubs/canvas/termsSample.txt");
    }

    else if (pathInfo.equalsIgnoreCase("/api/v1/courses/2222/sections")) {
        fr = retrieveTestFile(url, fr, "Sections call for course 2222 stub",
                "/stubs/canvas/mySecondSections.txt");
    }

    else if (pathInfo.equalsIgnoreCase("/api/v1/courses/1111/sections")) {
        fr = retrieveTestFile(url, fr, "Sections call for course 1111 stub",
                "/stubs/canvas/myFirstSections.txt");
    }

    else if (pathInfo.equalsIgnoreCase("/api/v1/courses")) {
        fr = retrieveTestFile(url, fr, "Courses call stub", "/stubs/canvas/coursesSample.txt");
    }

    else if (url.matches(SectionsUtilityToolServlet.appExtPropertiesFile.getProperty(CANVAS_API_GET_COURSE))) {
        fr = retrieveTestFile(url, fr, "Specific courses call stub", "/stubs/canvas/myCoursesSample.txt");
    }

    else if (url.matches(SectionsUtilityToolServlet.appExtPropertiesFile
            .getProperty(CANVAS_API_GETALLSECTIONS_PER_COURSE))) {
        fr = retrieveTestFile(url, fr, "Sections call stub", "/stubs/canvas/sectionsSample.txt");
    }

    else if (pathInfo.equalsIgnoreCase(SectionsUtilityToolServlet.MPATHWAYS_PATH_INFO)) {
        fr = retrieveTestFile(url, fr, "MPathways call stub", "/stubs/esb/mpathwaysSample.txt");
    }

    else {
        M_log.debug("Unrecognized call: " + url);
    }

    try {
        BufferedReader rd = new BufferedReader(fr);
        ;
        String line = "";
        StringBuilder sb = new StringBuilder();
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        out.print(sb.toString());
        out.flush();
        M_log.debug("SUCCESS");
    } catch (Exception e) {
        M_log.error("FAILURE");
        e.printStackTrace();
    }
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

/**
 * ?QueryString?URLDecoderUTF-8??post??//from  w ww  .j a v  a2  s .c o  m
 * HttpServletRequest#getParameter?
 *
 * @param request web
 * @param name    ???
 * @return
 */
public static String getQueryParam(HttpServletRequest request, String name) {
    if (StringUtils.isBlank(name)) {
        return null;
    }
    if (request.getMethod().equalsIgnoreCase(POST)) {
        return request.getParameter(name);
    }
    String s = request.getQueryString();
    if (StringUtils.isBlank(s)) {
        return null;
    }
    try {
        s = URLDecoder.decode(s, UTF8);
    } catch (UnsupportedEncodingException e) {
        log.error("encoding " + UTF8 + " not support?", e);
    }
    String[] values = parseQueryString(s).get(name);
    if (values != null && values.length > 0) {
        return values[values.length - 1];
    } else {
        return null;
    }
}

From source file:org.apache.hadoop.yarn.webapp.util.WebAppUtils.java

private static String getURLEncodedQueryString(HttpServletRequest request) {
    String queryString = request.getQueryString();
    if (queryString != null && !queryString.isEmpty()) {
        String reqEncoding = request.getCharacterEncoding();
        if (reqEncoding == null || reqEncoding.isEmpty()) {
            reqEncoding = "ISO-8859-1";
        }/*from w  w w  . j  a  v a  2s . c  om*/
        Charset encoding = Charset.forName(reqEncoding);
        List<NameValuePair> params = URLEncodedUtils.parse(queryString, encoding);
        return URLEncodedUtils.format(params, encoding);
    }
    return null;
}

From source file:io.lavagna.web.security.SecurityConfiguration.java

private static String extractRequestedUrl(HttpServletRequest req) {
    String queryString = req.getQueryString();
    return req.getRequestURI() + (queryString != null ? ("?" + queryString) : "");
}

From source file:com.o2o.util.WebUtils.java

public static String getPath(HttpServletRequest request) {
    String path_str = request.getServletPath();
    String param_str = request.getQueryString();
    if (request.getQueryString() != null) {
        path_str += "?" + param_str;
    }/*from  w ww  .  j a  v a  2  s. com*/
    return path_str;
}

From source file:com.trailmagic.image.ui.WebSupport.java

/**
 * If the request URI does not end with a /, redirects to the same URI
 * with a trailing /.  Otherwise, does nothing.
 *
 * @param req the servlet request/*from  w  ww  . jav a2  s.  c o m*/
 * @param res the servlet response
 */
public static boolean handleDirectoryUrlRedirect(HttpServletRequest req, HttpServletResponse res)
        throws IOException {
    String uri = req.getRequestURI();
    // if trailing / already, no work to do; we're done
    if (!uri.endsWith("/")) {
        StringBuffer newLocation = new StringBuffer();
        newLocation.append(uri);
        newLocation.append("/");
        if (req.getQueryString() != null) {
            newLocation.append("?");
            newLocation.append(req.getQueryString());
        }

        res.sendRedirect(newLocation.toString());
        return true;
    }
    return false;
}

From source file:org.oncoblocks.centromere.web.controller.RequestUtils.java

/**
 * Extracts request parameters and matches them to available database query parameters, as defined
 *   in the {@code model} class definition.
 *
 * @param request {@link HttpServletRequest}
 * @return//from  w w w .  j a v  a 2s.  c  om
 */
public static List<QueryCriteria> getQueryCriteriaFromRequest(Class<? extends Model<?>> model,
        HttpServletRequest request) {
    logger.info(String.format("Generating QueryCriteria for request parameters: model=%s params=%s",
            model.getName(), request.getQueryString()));
    List<QueryCriteria> criteriaList = new ArrayList<>();
    Map<String, QueryParameterDescriptor> paramMap = getAvailableQueryParameters(model);
    for (Map.Entry entry : request.getParameterMap().entrySet()) {
        String paramName = (String) entry.getKey();
        String[] paramValue = ((String[]) entry.getValue())[0].split(",");
        if (!excludedParameters.contains(paramName)) {
            if (paramMap.containsKey(paramName)) {
                QueryParameterDescriptor descriptor = paramMap.get(paramName);
                QueryCriteria criteria = createCriteriaFromRequestParameter(descriptor.getFieldName(),
                        paramValue, descriptor.getType(), descriptor.getEvaluation());
                criteriaList.add(criteria);
            } else {
                logger.warn(String.format("Unable to map request parameter to available model parameters: %s",
                        paramName));
                throw new InvalidParameterException("Invalid request parameter: " + paramName);
            }
        }
    }
    logger.info(String.format("Generated QueryCriteria for request: %s", criteriaList.toString()));
    return criteriaList;
}

From source file:com.vmware.identity.samlservice.Shared.java

/**
 * Utility method to get complete request URL
 *
 * @param req// w  w w  .  j  av a 2  s .com
 * @return
 */
public static String getUrl(HttpServletRequest req) {
    String reqUrl = req.getRequestURL().toString();
    String queryString = req.getQueryString(); // d=789
    if (queryString != null) {
        reqUrl += "?" + queryString;
    }
    return reqUrl;
}