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.o2o.util.WebUtils.java

public static String getUrl(HttpServletRequest request) {
    String path_str = request.getRequestURL().toString();
    String param_str = request.getQueryString();
    if (request.getQueryString() != null) {
        path_str += "?" + param_str;
    }/*from w w  w .  ja  v  a  2 s  .  co m*/
    return path_str;
}

From source file:mojo.view.util.DebugUtils.java

public static void logRequestInfo(HttpServletRequest req) {
    logger.debug("session.id          : " + req.getSession().getId());
    logger.debug("request.method      : " + req.getMethod());
    logger.debug("request.pathInfo    : " + req.getPathInfo());
    logger.debug("request.requestURI  : " + req.getRequestURI());
    logger.debug("request.requestURL  : " + req.getRequestURL());
    logger.debug("request.queryString : " + req.getQueryString());
    logger.debug("");

    logRequestHeaders(req);/*from ww w.  ja  v a2s. c o  m*/
    logRequestParameters(req);
    logRequestAttributes(req);
}

From source file:edu.usu.sdl.openstorefront.security.SecurityUtil.java

/**
 * Constructs an Admin Audit Log Message
 *
 * @param request//  w  w w  . j  a  va2s. c o m
 * @return message
 */
public static String adminAuditLogMessage(HttpServletRequest request) {
    StringBuilder message = new StringBuilder();

    message.append("User: ").append(getCurrentUserName()).append(" (").append(getClientIp(request)).append(") ")
            .append(" Called Admin API: ");
    if (request != null) {
        message.append(request.getMethod()).append(" ");
        if (StringUtils.isNotBlank(request.getQueryString())) {
            message.append(request.getRequestURL()).append("?").append(request.getQueryString());
        } else {
            message.append(request.getRequestURL());
        }
    }

    return message.toString();
}

From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java

/**
 * Gen http request dump./*from  w  w  w . ja v  a  2s . co m*/
 *
 * @param req the req
 * @return the string
 */
@SuppressWarnings("unchecked")
public static String genHttpRequestDump(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();

    sb.append("method: ").append(req.getMethod()).append('\n')//
            .append("requestURL: ").append(req.getRequestURL()).append('\n')//
            .append("servletPath: ").append(req.getServletPath()).append('\n')//
            .append("requestURI: ").append(req.getRequestURI()).append('\n') //
            .append("queryString: ").append(req.getQueryString()).append('\n') //
            .append("pathInfo: ").append(req.getPathInfo()).append('\n')//
            .append("contextPath: ").append(req.getContextPath()).append('\n') //
            .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') //
            .append("localName: ").append(req.getLocalName()).append('\n') //
            .append("contentLength: ").append(req.getContentLength()).append('\n') //
    ;
    sb.append("Header:\n");
    for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) {
        String hn = en.nextElement();
        sb.append("  ").append(hn).append(": ").append(req.getHeader(hn)).append("\n");
    }
    sb.append("Attr: \n");
    Enumeration en = req.getAttributeNames();
    for (; en.hasMoreElements();) {
        String k = (String) en.nextElement();
        Object v = req.getAttribute(k);
        sb.append("  ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n');
    }

    return sb.toString();
}

From source file:com.liferay.util.Http.java

public static String getCompleteURL(HttpServletRequest req) {
    StringBuffer completeURL = req.getRequestURL();

    if (completeURL == null) {
        completeURL = new StringBuffer();
    }/*from   www.j a  v  a  2s. c  o m*/

    if (req.getQueryString() != null) {
        completeURL.append(StringPool.QUESTION);
        completeURL.append(req.getQueryString());
    }

    return completeURL.toString();
}

From source file:fiftyone.mobile.detection.webapp.JavascriptProvider.java

/**
 * Returns a base 64 encoded version of the hash for the core JavaScript
 * being returned./*from ww w.  j a  v a2s  .  co  m*/
 * @param dataSet providing the JavaScript properties.
 * @param request
 * @return 
 */
private static String eTagHash(Dataset dataSet, HttpServletRequest request)
        throws IOException, NoSuchAlgorithmException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    dos.writeLong(dataSet.published.getTime());
    dos.writeChars(request.getHeader("User-Agent"));
    dos.writeChars(request.getQueryString());
    return Base64.encodeBase64String(MessageDigest.getInstance("MD5").digest(bos.toByteArray()));
}

From source file:ServletUtils.java

/**
 * NOT UNIT TESTED Returns the URL (including query parameters) minus the scheme, host, and
 * context path.  This method probably be moved to a more general purpose
 * class./*from w  ww. j a v a2s  .c  om*/
 */
public static String getRelativeUrl(HttpServletRequest request) {

    String baseUrl = null;

    if ((request.getServerPort() == 80) || (request.getServerPort() == 443))
        baseUrl = request.getScheme() + "://" + request.getServerName() + request.getContextPath();
    else
        baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();

    StringBuffer buf = request.getRequestURL();

    if (request.getQueryString() != null) {
        buf.append("?");
        buf.append(request.getQueryString());
    }

    return buf.substring(baseUrl.length());
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.MultipartRequestWrapper.java

/**
 * If this is a multipart request, wrap it. Otherwise, just return the
 * request as it is.//from w w  w.j  a v a2 s  . c  om
 */
public static HttpServletRequest parse(HttpServletRequest req, ParsingStrategy strategy) throws IOException {
    if (!ServletFileUpload.isMultipartContent(req)) {
        return req;
    }

    ListsMap<String> parameters = new ListsMap<>();
    ListsMap<FileItem> files = new ListsMap<>();

    parseQueryString(req.getQueryString(), parameters);
    parseFileParts(req, parameters, files, strategy);

    return new MultipartRequestWrapper(req, parameters, files);
}

From source file:com.janrain.backplane2.server.Token.java

public static @NotNull Token fromRequest(DAOFactory daoFactory, HttpServletRequest request, String tokenString,
        String authorizationHeader) throws TokenException {

    Pair<String, EnumSet<TokenSource>> tokenAndSource = extractToken(request.getQueryString(), tokenString,
            authorizationHeader);//w  w w  . ja v  a2 s  .c o m

    if (!Token.looksLikeOurToken(tokenAndSource.getLeft())) {
        throw new TokenException("invalid token", HttpServletResponse.SC_FORBIDDEN);
    }

    Token token;
    try {
        token = daoFactory.getTokenDao().get(tokenAndSource.getLeft());
    } catch (BackplaneServerException e) {
        logger.error("Error looking up token: " + tokenAndSource.getLeft(), e);
        throw new TokenException(OAuth2.OAUTH2_TOKEN_SERVER_ERROR, "error loading token",
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    if (token == null) {
        logger.warn("token not found: " + tokenAndSource.getLeft());
        throw new TokenException("invalid token", HttpServletResponse.SC_FORBIDDEN);
    }

    if (token.isExpired()) {
        throw new TokenException("expired token", HttpServletResponse.SC_FORBIDDEN);
    }

    token.checkAllowedSources(tokenAndSource.getRight());

    return token;
}

From source file:ch.cern.security.saml2.utils.UrlUtils.java

/**
 * Preprocess the request and invokes the verification:
 * /*  w ww.  ja  v a2  s .  c om*/
 * @param request
 * @param isDebugEnabled
 * @return
 * @throws Exception
 */
public static boolean verify(HttpServletRequest request, boolean isDebugEnabled) throws Exception {

    StringBuffer data = new StringBuffer();
    String sigAlg = null;
    String signature = null;
    data.append(Constants.SAML_REQUEST);
    data.append(EQUAL);

    if (isDebugEnabled)
        nc.notice("Query String: " + request.getQueryString());

    if (request.getParameter(Constants.SAML_REQUEST) != null) {
        if (isDebugEnabled)
            nc.notice(request.getParameter(Constants.SAML_REQUEST));
        data.append(LogoutUtils.urlEncode(request.getParameter(Constants.SAML_REQUEST),
                Constants.CHARACTER_ENCODING));
    } else {
        nc.error("NO " + Constants.SAML_REQUEST + " parameter");
        throw new Exception("NO " + Constants.SAML_REQUEST + " parameter");
    }

    // Get the sigAlg, it should match with the one declared as context
    // param
    sigAlg = request.getParameter(Constants.SIG_ALG);
    if (isDebugEnabled)
        nc.notice(sigAlg);
    if (((String) request.getSession().getServletContext().getAttribute(Constants.SIG_ALG)).equals(sigAlg)) {
        data.append(AMPERSAND);
        data.append(Constants.SIG_ALG);
        data.append(EQUAL);
        data.append(LogoutUtils.urlEncode(sigAlg, Constants.CHARACTER_ENCODING));
    } else {
        throw new NoSuchAlgorithmException();
    }

    // Get the signature and decode it in Base64
    Base64 base64 = new Base64();
    if (request.getParameter(SIGNATURE) != null) {
        if (isDebugEnabled)
            nc.notice("Signature: " + request.getParameter(SIGNATURE));
        signature = request.getParameter(SIGNATURE);
    } else {
        nc.error("NO " + SIGNATURE + " parameter");
        throw new Exception("NO " + SIGNATURE + " parameter");
    }

    if (isDebugEnabled)
        nc.notice("Data to verify: " + data.toString());

    // Verify
    return SignatureUtils.verify(data.toString().getBytes(), (byte[]) base64.decode(signature.getBytes()),
            (PublicKey) request.getSession().getServletContext().getAttribute(Constants.IDP_PUBLIC_KEY));
}