Example usage for javax.servlet.http HttpServletRequest getRequestURI

List of usage examples for javax.servlet.http HttpServletRequest getRequestURI

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRequestURI.

Prototype

public String getRequestURI();

Source Link

Document

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Usage

From source file:grails.plugins.jaxrs.web.JaxrsFilter.java

/**
 * Stores the request URI as request attribute.
 *
 * @see JaxrsUtils#REQUEST_URI_ATTRIBUTE_NAME
 *///from  w  w  w .  ja va  2  s  .co  m
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    JaxrsUtils.setRequestUriAttribute(request, request.getRequestURI());
    chain.doFilter(request, response);
}

From source file:com.adeptj.modules.oauth.http.OAuthAuthorizationRequestServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String providerName = StringUtils.substringAfterLast(req.getRequestURI(), "/");
    LOGGER.info("Authz request for provider: [{}]", providerName);
    OAuthProvider provider = this.providerFactory.getProvider(providerName);
    LOGGER.info("OAuthProvider: [{}]", provider);
    OAuth20Service oauth2Service = this.providerFactory.getOAuth2Service(providerName);
    if (oauth2Service == null) {
        oauth2Service = new ServiceBuilder(provider.getApiKey()).apiSecret(provider.getApiSecret())
                .callback(provider.getCallbackURL()).build(provider.getApi());
        this.providerFactory.addOAuth2Service(providerName, oauth2Service);
    }//w  w  w.  j av  a 2 s. c o  m
    String authorizationUrl = oauth2Service.getAuthorizationUrl();
    LOGGER.info("Authz URL: [{}]", authorizationUrl);
    resp.sendRedirect(authorizationUrl);
}

From source file:com.mobileman.filter.SecurityCheckFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    HttpServletRequest rq1 = (HttpServletRequest) request;
    String requestURI = rq1.getRequestURI().toLowerCase();
    DataHolder holder = new DataHolder(rq1);
    boolean error = false;
    if (requestURI.contains("/patient/")) {
        //check patient loaded         
        if (!holder.isPatient()) {
            error = true;/*  w w w .j av a 2  s.c  om*/
        }
    } else if (requestURI.contains("/arzt/")) {
        //check doctor loaded
        if (!holder.isDoctor()) {
            error = true;
        }
    } else if (requestURI.contains("/admin/") && !requestURI.contains("/admin/anmeldung")) {
        //check admin loaded
        if (!holder.isAdmin()) {
            error = true;
        }
    }

    ///////////////
    if (requestURI.contains("/public")) {
        //redirect to /behandlung
        StringBuffer sb = rq1.getRequestURL();
        String newUrl = StringUtils.replace(sb.toString(), "/public", "/behandlung");
        java.io.PrintWriter out = response.getWriter();
        response.setContentType("text/html");

        out.println("<html>");
        out.println("<head>");
        out.println("<meta http-equiv=\"refresh\" content=\"0;url=");
        out.print(newUrl);
        out.println("\" />");
        out.println("</head>");
        out.println("<body>");
        out.println("</body>");
        out.println("</html>");

        return;
    }

    if (error) {
        //redirect
        request.getRequestDispatcher("/").forward(request, response);
        return;
    }
    filterChain.doFilter(request, response);
}

From source file:de.uni_koeln.spinfo.maalr.webapp.i18n.InternationalUrlFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    //long start = System.nanoTime();
    HttpServletRequest h = (HttpServletRequest) request;
    String uri = h.getRequestURI();
    String path = h.getContextPath();
    Locale userLocale = request.getLocale();
    h.getSession().setAttribute("lang", userLocale.getLanguage());
    String url = uri.substring(path.length());
    /*/*from ww  w .j a  v  a 2s.c  o m*/
     * Idee: die URL in ihre Bestandteile zerlegen und die einzelnen Teile
     * in einem Keyword-Tree matchen. Auf jeder Stufe wird dabei die eigentliche
     * URL um ein neues Element ergnzt.
     * 
     * Funktioniert auf diese Weise gut fr statische URLs, aufbau eines Baums
     * fr URLs mit fest definierten Klassen (z.B. bersetzungsrichtung) ist ebenfalls mglich.
     * 
     * Funktioniert aber nicht fr dynamische Bestandteile - da muss eine Wildcard
     * rein.
     * 
     * :wrterbuch:deutsch-rumantsch:nase.html oder .json oder .xml
     * 
     * Baum:
     * wrterbuch -> dictionary
     *      deutsch-rumantsch -> tudesg->rumantsch
     *         * -> *
     *            ending
     * 
     * Filter-Funktionalitt:
     * 
     * a) Prfen, ob die URL schon in die Zielsprache bersetzt wurde. Falls ja:
     * doFilter() aufrufen, sonst bersetzen (andernfalls Endlos-Schleife).
     * 
     * b) die gewhlte Sprache irgendwo in der Session hinterlegen, damit der
     * Rest des Programms (GUI) entsprechend der URL auch die richtigen Elemente
     * darstellt.
     * 
     * c) Hilfsklasse notwendig, die URLs entsprechend der Sprache generiert,
     * z.B. fr dictionary (s.o.), aber auch fr "translate", einschlielich der
     * Durchblttern-Funktion. HTTP-GET sollte auch bersetzt werden (also Parameter-Namen),
     * POST nicht.
     * 
     * d) Die Generierung des Baums darf lange dauern, die Abfrage muss aber
     * schnell sein - also z.B. Pattern.compile() beim Aufbau des Baums, nicht
     * beim Abfragen. 
     *  
     */
    if ("/hilfe.html".equals(url) || "/help.html".equals(url)) {
        // change url and forward
        RequestDispatcher dispatcher = request.getRequestDispatcher("/agid.html");
        //   long end = System.nanoTime();
        dispatcher.forward(request, response);
    } else {
        //   long end = System.nanoTime();
        chain.doFilter(request, response);
    }
}

From source file:ru.mystamps.web.service.SiteServiceImpl.java

/**
 * @author Sergey Chechenev//w w w .j ava  2  s.c  om
 */
@Override
@Transactional
public void logAboutMissingCsrfToken(HttpServletRequest request) {

    logEvent(MISSING_CSRF_TOKEN, request.getRequestURI(), request.getMethod(), SecurityContextUtils.getUserId(),
            request.getRemoteAddr(), request.getHeader("referer"), request.getHeader("user-agent"), new Date());

}

From source file:ru.mystamps.web.service.SiteServiceImpl.java

/**
 * @author Sergey Chechenev//from  w w w  .j  a va  2 s  . c  om
 */
@Override
@Transactional
public void logAboutInvalidCsrfToken(HttpServletRequest request) {

    logEvent(INVALID_CSRF_TOKEN, request.getRequestURI(), request.getMethod(), SecurityContextUtils.getUserId(),
            request.getRemoteAddr(), request.getHeader("referer"), request.getHeader("user-agent"), new Date());

}

From source file:com.thinkgem.jeesite.modules.sys.interceptor.GlobalInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    String uri = request.getRequestURI();
    String uriPrefix = request.getContextPath() + Global.ADMIN_PATH;
    // ??POST//from   w w w.  j a v a2s. c  o m
    if ("POST".equals(request.getMethod()) && uri.length() > uriPrefix.length()) {
        User user = UserUtils.getUser();
        if (user != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("url: (" + request.getMethod() + ") " + uri);
            int index = 0;
            for (Object param : request.getParameterMap().keySet()) {
                sb.append((index++ == 0 ? "?" : "&") + param + "=");
                sb.append(StringUtils.abbreviate(request.getParameter((String) param), 100));
            }
            sb.append("; userId: " + user.getId());
            sb.append("; userName: " + user.getName());
            sb.append("; loginName: " + user.getLoginName());
            sb.append("; ipAddr: " + request.getLocalAddr());
            sb.append("; datetime: " + DateUtils.getDateTime());
            sb.append("; handler: " + handler.toString());
            logger.info(sb.toString());
        }
    }
}

From source file:WebApp.Controller.IncourseController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView modelAndView = null;/*from w  w w .  j  ava2 s  . c o  m*/

    String requestedUri = request.getRequestURI();

    if (requestedUri.contains(Constants.INCOURSE_FINAL_MARKS_FORM)) {
        modelAndView = new ModelAndView("insertEachIncourseMarks");
    } else if (requestedUri.contains(Constants.INSERT_INCOURSE_FINAL)) {
        String courseCode = request.getParameter(COURSE_CODE);
        String session = request.getParameter(SESSION);
        String deptRoll = request.getParameter(DEPT_ROLL);
        String incourseFinal = request.getParameter(INCOURSE_FINAL);

        IncourseService incourseService = new IncourseServiceImp();
        incourseService.saveFinal(createIncourse(courseCode, session, deptRoll, incourseFinal));

        modelAndView = new ModelAndView("insertEachIncourseMarks");
        modelAndView.addObject("message", "successfully inserted incourse marks information");
    }

    return modelAndView;
}

From source file:com.surfs.storage.web.filter.LoginFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    String uriStr = req.getRequestURI();
    String path = req.getContextPath();
    System.out.println(uriStr);//from  w w  w  . j  a  va2 s  .c  o m
    if (excludes_Pattern != null) {
        for (Pattern exclude_Pattern : excludes_Pattern) {
            if (exclude_Pattern.matcher(uriStr).find()) {
                chain.doFilter(request, response);
                return;
            }
        }
    }

    Object user = req.getSession().getAttribute("user");
    if (user == null) {
        resp.sendRedirect(path + "/home.jsp?status=access_error");
        return;
    }
    chain.doFilter(request, response);
}

From source file:ru.mystamps.web.support.spring.security.SessionLocaleResolverAwareFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    try {/* w  w w . j a v  a  2s.c o  m*/
        HttpServletRequest req = (HttpServletRequest) request;
        LOG.debug("Handling request {} {}", req.getMethod(), req.getRequestURI());

        Locale locale = (Locale) WebUtils.getSessionAttribute((HttpServletRequest) request,
                SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);

        if (locale == null) {
            locale = Locale.ENGLISH;
            LOG.debug("Locale reset to 'en' (default)");
        } else {
            LOG.debug("Locale reset to '{}' (from session)", locale);
        }

        LocaleContextHolder.setLocale(locale);

    } catch (RuntimeException ex) { // NOPMD: AvoidCatchingGenericException
        LOG.warn("Couldn't handle request: {}", ex);

    } finally {
        chain.doFilter(request, response);
    }
}