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:be.fedict.eid.dss.sp.bean.SignatureRequestServiceBean.java

@Override
public String getSPDestination() {

    HttpServletRequest httpServletRequest = getHttpServletRequest();

    return httpServletRequest.getScheme() + "://" + httpServletRequest.getServerName() + ":"
            + httpServletRequest.getServerPort() + httpServletRequest.getContextPath() + "/dss-response";

    // return "../eid-dss-sp/dss-response";
}

From source file:com.spstudio.session.filter.SessionAOP.java

@Around(value = "@annotation(com.spstudio.session.UserSession)")
public Object aroundManager(ProceedingJoinPoint pj) throws Exception {
    HttpServletRequest request = SysContent.getRequest();
    HttpServletResponse response = SysContent.getResponse();
    HttpSession session = SysContent.getSession();

    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";

    UserSessionType type = this.getSessionType(pj);
    if (type == null) {
        throw new Exception("The value of NeedSession is must.");
    }/*w  ww.  j a v  a  2 s. c  om*/

    Object uobj = session.getAttribute("user");
    Object mobj = session.getAttribute("manager");

    boolean isUser = type == UserSessionType.USER && uobj != null;
    boolean isManager = type == UserSessionType.MANAGER && mobj != null;
    boolean isUserOrManager = type == UserSessionType.OR && (mobj != null || uobj != null);
    try {
        if (isUser || isManager || isUserOrManager) {
            return pj.proceed();
        } else { // ?session  
            if (request.getHeader("x-requested-with") != null
                    && request.getHeader("x-requested-with").equalsIgnoreCase( //ajax?       
                            "XMLHttpRequest")) {
                response.addHeader("sessionstatus", "timeout");
                // EasyUi  
                //response.getWriter().print("{\"rows\":[],\"success\":false,\"total\":0}");       
            } else {//http?       
                response.sendRedirect(basePath + "error/nosession");
            }
        }
    } catch (Throwable e) {
        // TODO Auto-generated catch block  
        e.printStackTrace();
    }
    return null;
}

From source file:com.glaf.core.util.RequestUtils.java

public static String getLocalAddress(HttpServletRequest request) {
    // reads local address
    String host = getLocalHostAddress(request, true);
    return host + request.getContextPath();
}

From source file:com.googlecode.psiprobe.controllers.connectors.ResetConnectorStatsController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String connectorName = ServletRequestUtils.getRequiredStringParameter(request, "cn");
    collectorBean.reset(connectorName);/*from www.j  a va 2s.c o m*/
    return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()));
}

From source file:org.jamwiki.servlets.StylesheetServlet.java

/**
 *
 *///from  w  w  w  .j a v  a  2  s  .c om
public ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response,
        ModelAndView next, WikiPageInfo pageInfo) throws Exception {
    String virtualWiki = pageInfo.getVirtualWikiName();
    String stylesheet = ServletUtil.cachedContent(request.getContextPath(), request.getLocale(), virtualWiki,
            WikiBase.SPECIAL_PAGE_SYSTEM_CSS, false);
    stylesheet += '\n' + ServletUtil.cachedContent(request.getContextPath(), request.getLocale(), virtualWiki,
            WikiBase.SPECIAL_PAGE_CUSTOM_CSS, false);
    response.setContentType("text/css");
    response.setCharacterEncoding("UTF-8");
    // cache for 30 minutes (60 * 30 = 1800)
    // FIXME - make configurable
    response.setHeader("Cache-Control", "max-age=1800");
    PrintWriter out = response.getWriter();
    out.print(stylesheet);
    out.close();
    // do not load defaults or redirect - return as raw CSS
    return null;
}

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

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

    //Session session = getSessionFactory().getCurrentSession();
    ModelAndView mav = new ModelAndView();
    mav.setViewName(getViewName());

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

    try {
        //defining some createria which should be resend to the same page for the user to add some other selection createrias
        DataQualityByCheckTypeController checkingDataQuality = new DataQualityByCheckTypeController();
        List<Patient> patients = new ArrayList<Patient>();
        patients = checkingDataQuality.checkTypeController(programIdKey, valueRangeType);

        //setting necessary ressources for the view
        mav.addObject("msgToDisplay", getMsgToDisplay());
        mav.addObject("thePatientList", patients);
        mav.addObject("checkType", programIdKey);
        mav.addObject("valueRangeType", valueRangeType);
    } catch (Exception e) {
        log.error(">>>>>TRAC>>DATA>>QUALITY>> " + e.getMessage());
        e.printStackTrace();
    }
    //           mav.setViewName("module/tracdataquality/dataQualitySuccess");

    return mav;
}

From source file:br.com.flucianofeijao.security.JsfAccessDeniedHandler.java

public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), loginPath);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    //we should redirect using ajax response if the case warrants
    boolean ajaxRedirect = request.getHeader("faces-request") != null
            && request.getHeader("faces-request").toLowerCase().indexOf("ajax") > -1;

    if (ajaxRedirect) {
        //javax.faces.context.FacesContext ctxt = javax.faces.context.FacesContext.getCurrentInstance();
        //ctxt.getExternalContext().redirect(redirectUrl);

        String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>";
        response.setContentType("text/xml");
        response.getWriter().write(ajaxRedirectXml);
    } else {/*from www  .  ja v  a  2  s . c  o m*/
        response.sendRedirect(redirectUrl);
    }
}

From source file:edu.chalmers.dat076.moviefinder.filter.UserFilter.java

@Override
protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain)
        throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    String path = req.getRequestURI().substring(req.getContextPath().length());

    Object o = session.getAttribute("user");

    if (o == null) {
        if (path.toLowerCase().startsWith("/api/login/login")) {
            chain.doFilter(req, res);//from  w w w . jav a  2 s. c  om
            return;
        } else if (path.toLowerCase().startsWith("/api/")) {
            res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        } else {
            chain.doFilter(req, res);
            return;
        }
    }

    User u = (User) o;
    if (path.toLowerCase().startsWith("/api/admin") && u.getRole() != UserRole.ADMIN) {
        res.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    chain.doFilter(req, res);
}

From source file:br.com.wavii.securyti.JsfAccessDeniedHandler.java

public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), loginPath);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    // we should redirect using ajax response if the case warrants
    boolean ajaxRedirect = request.getHeader("faces-request") != null
            && request.getHeader("faces-request").toLowerCase().indexOf("ajax") > -1;

    if (ajaxRedirect) {
        // javax.faces.context.FacesContext ctxt =
        // javax.faces.context.FacesContext.getCurrentInstance();
        // ctxt.getExternalContext().redirect(redirectUrl);

        String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>";
        response.setContentType("text/xml");
        response.getWriter().write(ajaxRedirectXml);
    } else {//from   www .  j a  v a 2 s . c  o m
        response.sendRedirect(redirectUrl);
    }
}