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.google.youtube.captions.AuthSubLogin.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {/*from  ww  w.j a v a 2 s.  com*/
        String authSubToken = AuthSubUtil.getTokenFromReply(req.getQueryString());
        if (authSubToken == null) {
            throw new IllegalStateException("Could not parse token from AuthSub response.");
        } else {
            authSubToken = URLDecoder.decode(authSubToken, "UTF-8");
        }

        authSubToken = AuthSubUtil.exchangeForSessionToken(authSubToken, null);

        YouTubeService service = new YouTubeService(SystemProperty.applicationId.get(), Util.DEVELOPER_KEY);
        service.setAuthSubToken(authSubToken);

        UserProfileEntry profileEntry = service.getEntry(new URL(PROFILE_URL), UserProfileEntry.class);
        String username = profileEntry.getUsername();

        String authSubCookie = Util.getCookie(req, Util.AUTH_SUB_COOKIE);
        JSONObject cookieAsJSON = new JSONObject();
        if (!Util.isEmptyOrNull(authSubCookie)) {
            try {
                cookieAsJSON = new JSONObject(authSubCookie);
            } catch (JSONException e) {
                LOG.log(Level.WARNING, "Unable to parse JSON from the existing cookie: " + authSubCookie, e);
            }
        }

        try {
            cookieAsJSON.put(username, authSubToken);
        } catch (JSONException e) {
            LOG.log(Level.WARNING,
                    String.format("Unable to add account '%s' and AuthSub token '%s'" + " to the JSON object.",
                            username, authSubToken),
                    e);
        }

        Cookie cookie = new Cookie(Util.AUTH_SUB_COOKIE, cookieAsJSON.toString());
        cookie.setMaxAge(Util.COOKIE_LIFETIME);
        resp.addCookie(cookie);

        cookie = new Cookie(Util.CURRENT_AUTHSUB_TOKEN, authSubToken);
        cookie.setMaxAge(Util.COOKIE_LIFETIME);
        resp.addCookie(cookie);

        cookie = new Cookie(Util.CURRENT_USERNAME, username);
        cookie.setMaxAge(Util.COOKIE_LIFETIME);
        resp.addCookie(cookie);
    } catch (IllegalStateException e) {
        LOG.log(Level.WARNING, "", e);
    } catch (AuthenticationException e) {
        LOG.log(Level.WARNING, "", e);
    } catch (GeneralSecurityException e) {
        LOG.log(Level.WARNING, "", e);
    } catch (ServiceException e) {
        LOG.log(Level.WARNING, "", e);
    }

    resp.sendRedirect("/");
}

From source file:com.apress.progwt.server.web.controllers.ViewUserController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse arg1)
        throws Exception {

    log.debug("SERVLET PATH: " + req.getServletPath() + " " + req.getPathInfo() + " " + req.getQueryString());

    Map<String, Object> model = getDefaultModel(req);

    String path = req.getPathInfo();

    String[] pathParts = path.split("/");
    log.debug("!path parts " + Arrays.toString(pathParts));

    // "/user/jeff" splits to [,jeff]
    if (pathParts.length < 2) {
        return new ModelAndView(getNotFoundView());
    }//w ww.java 2  s  . c  om

    String nickname = pathParts[1];

    User fetchedUser = userService.getUserByNicknameFullFetch(nickname);

    if (log.isDebugEnabled()) {
        log.debug("user u: " + fetchedUser);
        log.debug("isinit user " + Hibernate.isInitialized(fetchedUser));
        log.debug("isinit schools " + Hibernate.isInitialized(fetchedUser.getSchoolRankings()));
        for (Application sap : fetchedUser.getSchoolRankings()) {
            if (!Hibernate.isInitialized(sap)) {
                log.debug("Not initialized");
            }
        }
    }

    if (fetchedUser == null) {
        return new ModelAndView(getNotFoundView(), "message", "Couldn't find user with nickname: " + nickname);
    }
    model.put("viewUser", fetchedUser);

    ModelAndView mav = getMav();
    mav.addAllObjects(model);
    return mav;
}

From source file:cn.guoyukun.spring.web.filter.DebugRequestAndResponseFilter.java

private void debugRequest(HttpServletRequest request) {
    log.debug("=====================request begin==========================");
    String uri = request.getRequestURI();
    String queryString = request.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        uri = uri + "?" + queryString;
    }//from   w ww .  j av  a2 s. c o  m
    log.debug("{}:{}", request.getMethod(), uri);
    log.debug("remote ip:{}  sessionId:{}  ", IpUtils.getIpAddr(request), request.getRequestedSessionId());
    log.debug("===header begin============================================");
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        String value = headersToString(request.getHeaders(name));
        log.debug("{}={}", name, value);
    }
    log.debug("===header   end============================================");
    log.debug("===parameter begin==========================================");
    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        String value = StringUtils.join(request.getParameterValues(name), "||");
        log.debug("{}={}", name, value);
    }
    log.debug("===parameter   end==========================================");
    log.debug("=====================request   end==========================");
}

From source file:cn.bc.web.util.DebugUtils.java

public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) {
    @SuppressWarnings("rawtypes")
    Enumeration e;//  ww  w  . ja v a2  s .co  m
    String name;
    StringBuffer html = new StringBuffer();

    //session
    HttpSession session = request.getSession();
    html.append("<div><b>session:</b></div><ul>");
    html.append(createLI("Id", session.getId()));
    html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString()));
    html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString()));

    //session:attributes
    e = session.getAttributeNames();
    html.append("<li>attributes:<ul>\r\n");
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        html.append(createLI(name, String.valueOf(session.getAttribute(name))));
    }
    html.append("</ul></li>\r\n");
    html.append("</ul>\r\n");

    //request
    html.append("<div><b>request:</b></div><ul>");
    html.append(createLI("URL", request.getRequestURL().toString()));
    html.append(createLI("QueryString", request.getQueryString()));
    html.append(createLI("Method", request.getMethod()));
    html.append(createLI("CharacterEncoding", request.getCharacterEncoding()));
    html.append(createLI("ContentType", request.getContentType()));
    html.append(createLI("Protocol", request.getProtocol()));
    html.append(createLI("RemoteAddr", request.getRemoteAddr()));
    html.append(createLI("RemoteHost", request.getRemoteHost()));
    html.append(createLI("RemotePort", request.getRemotePort() + ""));
    html.append(createLI("RemoteUser", request.getRemoteUser()));
    html.append(createLI("ServerName", request.getServerName()));
    html.append(createLI("ServletPath", request.getServletPath()));
    html.append(createLI("ServerPort", request.getServerPort() + ""));
    html.append(createLI("Scheme", request.getScheme()));
    html.append(createLI("LocalAddr", request.getLocalAddr()));
    html.append(createLI("LocalName", request.getLocalName()));
    html.append(createLI("LocalPort", request.getLocalPort() + ""));
    html.append(createLI("Locale", request.getLocale().toString()));

    //request:headers
    e = request.getHeaderNames();
    html.append("<li>Headers:<ul>\r\n");
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        html.append(createLI(name, request.getHeader(name)));
    }
    html.append("</ul></li>\r\n");

    //request:parameters
    e = request.getParameterNames();
    html.append("<li>Parameters:<ul>\r\n");
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        html.append(createLI(name, request.getParameter(name)));
    }
    html.append("</ul></li>\r\n");

    html.append("</ul>\r\n");

    //response
    html.append("<div><b>response:</b></div><ul>");
    html.append(createLI("CharacterEncoding", response.getCharacterEncoding()));
    html.append(createLI("ContentType", response.getContentType()));
    html.append(createLI("BufferSize", response.getBufferSize() + ""));
    html.append(createLI("Locale", response.getLocale().toString()));
    html.append("<ul>\r\n");
    return html;
}

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

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:fi.okm.mpass.shibboleth.authn.impl.ValidateWilmaResponse.java

/**
 * Returns the given parameter from the query.
 * @param servletRequest The request containing the query.
 * @param paramName The parameter whose value is to be returned.
 * @return The value for the parameter, or null if it does not exist.
 *///from   w  w w. j a va 2 s  . c o m
protected String getQueryParam(final HttpServletRequest servletRequest, final String paramName) {
    final String query = servletRequest.getQueryString();
    if (query.indexOf(paramName + "=") != -1) {
        final String cut = query.substring(query.indexOf(paramName + "=") + paramName.length() + 1);
        if (cut.indexOf("&") > 0) {
            return StringSupport.trimOrNull(cut.substring(0, cut.indexOf("&")));
        } else {
            return StringSupport.trimOrNull(cut);
        }
    }
    return null;
}

From source file:com.collabnet.svnedge.util.SessionProgressListener.java

public SessionProgressListener(HttpServletRequest request) {
    startTimeMillis = System.currentTimeMillis();
    this.session = request.getSession(false);
    this.stats = new HashMap<String, Object>();
    String qs = request.getQueryString();
    String name = QUERY_PARAM_KEY + "=";
    String key = null;//from  w  w w  . ja v  a 2 s.  c  o  m
    if (qs != null) {
        int start = qs.indexOf(name);
        if (start >= 0) {
            int end = qs.indexOf('&', start);
            if (end < start) {
                end = qs.length();
            }
            key = qs.substring(start + name.length(), end);
        }
    }
    if (null == key) {
        key = "uploadStatsDefaultKey";
    }
    request.setAttribute("uploadStatsSessionKey", key);
    session.setAttribute(key, stats);
    sessionKey = key;
    log = Logger.getLogger(getClass());
}

From source file:com.exxonmobile.ace.hybris.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  .  j a  v  a 2s .  c  o  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)) {
        getBrowseHistory().addBrowseHistoryEntry(new BrowseHistoryEntry(httpRequest.getRequestURI(), null));
    }

    chain.doFilter(request, response);
}

From source file:com.myjeeva.spring.security.securechannel.AbstractCrossDomainRetryEntryPoint.java

/**
 * {@inheritDoc}/*from   w  ww  .  java  2 s.  c o  m*/
 */
public void commence(ServletRequest req, ServletResponse res) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;

    String pathInfo = request.getPathInfo();
    String queryString = request.getQueryString();
    String contextPath = request.getContextPath();
    String destination = request.getServletPath() + ((pathInfo == null) ? "" : pathInfo)
            + ((queryString == null) ? "" : ("?" + queryString));

    String redirectUrl = contextPath;

    Integer currentPort = new Integer(portResolver.getServerPort(request));
    Integer redirectPort = getMappedPort(currentPort);

    if (redirectPort != null) {
        boolean includePort = redirectPort.intValue() != standardPort;

        redirectUrl = scheme + getMappedDomain(request.getServerName())
                + ((includePort) ? (":" + redirectPort) : "") + contextPath + destination;
    }

    LOG.debug(" Cross Domain EntryPoint Redirecting to: " + redirectUrl);

    ((HttpServletResponse) res).sendRedirect(((HttpServletResponse) res).encodeRedirectURL(redirectUrl));
}

From source file:com.education.lessons.ui.server.login.OpenIDLoginController.java

/**
 * Builds the current full URL./*from w  w w . j  a  va  2 s .  c o  m*/
 */
private String getRequestURL(HttpServletRequest request, boolean qs) {
    StringBuffer requestURL = request.getRequestURL();
    String queryString = request.getQueryString();

    if (qs && queryString != null && !queryString.isEmpty()) {
        requestURL.append("?").append(queryString);
    }

    return requestURL.toString();
}