Example usage for javax.servlet.http HttpServletRequest getContextPath

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

Introduction

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

Prototype

public String getContextPath();

Source Link

Document

Returns the portion of the request URI that indicates the context of the request.

Usage

From source file:net.risesoft.soa.asf.web.controller.SystemController.java

@RequestMapping({ "index.html", "index.do", "index" })
public void index(HttpServletRequest req, Map<String, String> model) {
    model.put("AppRoot", req.getContextPath());
    model.put("osgiDev", String.valueOf(this.bundleHelper.isDevMode()));
}

From source file:com.yahoo.dba.perf.myperf.springmvc.MyPerfBaseController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp)
        throws Exception {
    logger.info("receive url path: " + req.getContextPath() + "," + req.getRequestURI() + ", "
            + req.getServletPath() + ", parameters: " + req.getQueryString());

    AppUser user = retrieveAppUser(req);

    if (this.requireLogin && user == null)//check if user valid when require login
    {//from   w  w w. jav  a2 s .c o  m
        if (this.nosessView != null)
            return new ModelAndView(new RedirectView(nosessView));
        return respondFailure("Session expired. Please relogin and try again.", req);
    } else if (this.requireLogin && !user.isVerified()) {
        //TODO use a message view
        return this.respondFailure(
                "New user request has not been verified by administrator yet. Please contact administrator by email "
                        + this.frameworkContext.getMyperfConfig().getAdminEmail() + ".",
                req);
    }

    return handleRequestImpl(req, resp);
}

From source file:com.yuga.ygplatform.modules.sys.interceptor.LogInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {

    String requestRri = request.getRequestURI();
    String uriPrefix = request.getContextPath() + Global.getAdminPath();

    if ((StringUtils.startsWith(requestRri, uriPrefix) && (StringUtils.endsWith(requestRri, "/save")
            || StringUtils.endsWith(requestRri, "/delete") || StringUtils.endsWith(requestRri, "/import")
            || StringUtils.endsWith(requestRri, "/updateSort"))) || ex != null) {

        User user = UserUtils.getUser();
        if (user != null && user.getId() != null) {

            StringBuilder params = new StringBuilder();
            int index = 0;
            for (Object param : request.getParameterMap().keySet()) {
                params.append((index++ == 0 ? "" : "&") + param + "=");
                params.append(StringUtils.abbr(StringUtils.endsWithIgnoreCase((String) param, "password") ? ""
                        : request.getParameter((String) param), 100));
            }//from w w  w. j a  va2s  .c o m

            Log log = new Log();
            log.setType(ex == null ? Log.TYPE_ACCESS : Log.TYPE_EXCEPTION);
            log.setCreateBy(user);
            log.setCreateDate(new Date());
            log.setRemoteAddr(StringUtils.getRemoteAddr(request));
            log.setUserAgent(request.getHeader("user-agent"));
            log.setRequestUri(request.getRequestURI());
            log.setMethod(request.getMethod());
            log.setParams(params.toString());
            log.setException(ex != null ? ex.toString() : "");
            logDao.save(log);

            logger.debug("save log {type: {}, loginName: {}, uri: {}}, ", log.getType(), user.getLoginName(),
                    log.getRequestUri());

        }
    }

    //      logger.debug(": {}, ?: {}, ?: {}, ?: {}", 
    //            Runtime.getRuntime().maxMemory(), Runtime.getRuntime().totalMemory(), Runtime.getRuntime().freeMemory(), 
    //            Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory()); 

}

From source file:com.concursive.connect.web.filters.ClientTypeRequestFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    HttpServletRequest hsRequest = (HttpServletRequest) request;
    HttpServletResponse hsResponse = (HttpServletResponse) response;

    // Determine the requested path
    String contextPath = hsRequest.getContextPath();
    String uri = hsRequest.getRequestURI();
    String requestedPath = uri.substring(contextPath.length());

    LOG.debug("Requested Path is: " + requestedPath);

    // Determine if a client session is required
    if (requestedPath.startsWith("/api") || requestedPath.startsWith("/Process")) {
        // No need to track this client via a session

    } else {/*w  w w .ja v a  2s . c  o  m*/
        // Track information about the client
        ClientType clientType = (ClientType) hsRequest.getSession().getAttribute(Constants.SESSION_CLIENT_TYPE);
        if (clientType == null) {
            clientType = new ClientType(hsRequest);
            hsRequest.getSession().setAttribute(Constants.SESSION_CLIENT_TYPE, clientType);
            LOG.debug("Created clientType");
        } else if (clientType.getId() == -1) {
            clientType.setParameters(hsRequest);
        }
    }
    chain.doFilter(hsRequest, hsResponse);
}

From source file:controller.ChangepasswordController.java

@RequestMapping(value = "/process", method = RequestMethod.POST)
public String changepassProcess(Authentication authen, @RequestParam String newpass,
        @RequestParam String oldpass, ModelMap mm, HttpServletRequest req) {
    Customer cus = cusModel.find(authen.getName(), "username", false).get(0);
    if (!cus.getPassword().equals(oldpass)) {
        mm.put("check", true);
        mm.put("alert", "Old password invalid");
        mm.put("link", req.getContextPath() + "/customer/changepassword.html");
    } else {/*  www  .j a va 2 s . c o m*/
        cus.setPassword(newpass);
        mm.put("check", cusModel.addOrUpdate(cus));
        mm.put("alert", "Password updated");
        mm.put("link", req.getContextPath());
    }
    return "changepassProcess";
}

From source file:ch.puzzle.modjprof.control.ControlServlet.java

private String getBaseUri(HttpServletRequest request) {
    String baseURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    return baseURI;
}

From source file:vmware.au.se.sqlfireweb.controller.HistoryController.java

@RequestMapping(value = "/history", method = RequestMethod.GET)
public String showHistory(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/sqlfireweb/login");
        return null;
    }/*from  ww  w  .  j ava  2s.  c  o  m*/

    logger.debug("Received request to show command history");
    UserPref userPref = (UserPref) session.getAttribute("prefs");

    String histAction = request.getParameter("histAction");

    if (histAction != null) {
        logger.debug("histAction = " + histAction);
        // clear history
        session.setAttribute("history", new LinkedList());

        model.addAttribute("historyremoved", "Succesfully cleared history list");
    }

    LinkedList historyList = (LinkedList) session.getAttribute("history");

    int maxsize = userPref.getHistorySize();

    model.addAttribute("historyList", historyList.toArray());
    model.addAttribute("historysize", historyList.size());

    // This will resolve to /WEB-INF/jsp/history.jsp
    return "history";
}

From source file:org.springside.modules.security.jcaptcha.JCaptchaFilter.java

/**
 * ?.//from w ww.  j  av  a 2 s  .c om
 * 
 * ??, sessionSpringSecurityException.
 */
protected void redirectFailureUrl(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException {
    response.sendRedirect(request.getContextPath() + failureUrl);
}

From source file:org.openmrs.module.tracdataquality.web.controller.DownloadController.java

/**
 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *///from w ww.j a va  2  s.c  om
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    if (Context.getAuthenticatedUser() == null)
        return new ModelAndView(new RedirectView(request.getContextPath() + "/login.htm"));

    //getting necessary parameters
    String programIdKey = request.getParameter("checkType");
    String valueRangeType = request.getParameter("createriaValue");

    try {
        //getting patients responding to criteria asked
        DataQualityByCheckTypeController checkingDataQuality = new DataQualityByCheckTypeController();
        List<Patient> patients = new ArrayList<Patient>();
        patients = checkingDataQuality.checkTypeController(programIdKey, valueRangeType);

        //building the fileName based on current time and the name of the indicator
        String timeNow = new SimpleDateFormat("dd_MMM_yyyy_HH_mm_ss").format(new Date());
        String fileName = ((request.getParameter("checkType") != null) ? request.getParameter("checkType") + "_"
                : "dataQualityReport_") + timeNow + ".csv";

        //download the report in csv file
        doDownload(request, response, patients, fileName,
                ContextProvider.getMessage("tracdataquality.indicator." + programIdKey));
    } catch (Exception e) {
        log.info(">>>>>TRAC>>DATA>>QUALITY>> " + e.getMessage());
        e.printStackTrace();
    }
    return null;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.facebook.FacebookLogoutHandler.java

/**
 * {@inheritDoc}//from w  w w .j av a 2 s. co m
 * @see org.springframework.security.ui.logout.LogoutHandler#logout(
 *    javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
 *    org.springframework.security.Authentication)
 */
public void logout(final HttpServletRequest request, final HttpServletResponse response,
        final Authentication authentication) {

    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        String path = StringUtils.hasLength(request.getContextPath()) ? request.getContextPath() : "/";
        for (Cookie cookie : cookies) {
            if (cookie.getName().startsWith(_apiKey)) {
                cancelCookie(cookie.getName(), path, response);
            }
        }
    }
}