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:org.shaf.server.security.RestAuthenticationEntryPoint.java

/**
 * Executes if authentication is required.
 *//*from  w w  w. ja v a2  s.  c  om*/
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException {
    LOG.debug("SECURITY: Authentication request...");

    response.sendRedirect(request.getContextPath() + "/login.jsp");
}

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

@Override
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:io.dfox.junit.http.JUnitHttpServlet.java

/**
 * Get the path from the request. The path is the relative path after the specified prefix.
 * For example, if the full request URI is "/contextName/fixtures/foobars/foo.json", the 
 * array returned will contain "fixtures", "foobars", and "foo.json".
 * /*  ww w .  j  a v  a  2  s.c  om*/
 * @param request The request
 * @return The parsed path
 */
private String[] parsePath(final HttpServletRequest request) {
    final int prefixLength = request.getContextPath().length() + 1;
    String path = request.getRequestURI().substring(prefixLength);
    return path.split("/");
}

From source file:org.squale.squaleweb.util.graph.GraphMaker.java

/**
 * Factorisation du code mettant  jour les donns d'une image cliquables
 * /*www  .  j  a v  a 2 s .c om*/
 * @param fileName le nom du fichier
 * @param info le ChartRenderingInfo de l'image
 * @param pRequest la requete pour internationalisation
 */
public GraphMaker(HttpServletRequest pRequest, String fileName, ChartRenderingInfo info) {
    setMapDescription(ChartUtilities.getImageMap(fileName, info));
    setSrcName(pRequest.getContextPath() + WebMessages.getString("default.path.display") + fileName);
    setUseMapName("#" + fileName);

}

From source file:com.controller.SkillController.java

@RequestMapping(value = "admin/skill_edit/save", method = RequestMethod.POST)
public View updateSkill(HttpServletRequest request, @ModelAttribute Skill skill) {
    skill.setStatus(1);/*  w  w w . j  av a  2 s.  co  m*/
    ski.updateSkill(skill);
    return new RedirectView(request.getContextPath() + "/admin/skill_list");
}

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 av a 2 s  . c  om
    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:com.arihant15.ActionServlet.java

@RequestMapping("/logout.arihant15")
public void dologout(HttpServletRequest req, HttpServletResponse res) throws IOException {
    try {/* w  w w.  j a v  a2  s  . co  m*/
        req.getSession().invalidate();
        res.sendRedirect(req.getContextPath() + "/");
    } catch (Exception e) {
        (res.getWriter()).println(e);
    }
}

From source file:ltistarter.lti.LTIRequest.java

/**
 * Creates an LTI composite key which can be used to identify a user session consistently
 *
 * @param request     the incoming request
 * @param sessionSalt the salt (defaults to a big random string)
 * @return the composite string (md5)/* www  . j a  v a  2  s. com*/
 */
public static String makeLTICompositeKey(HttpServletRequest request, String sessionSalt) {
    if (StringUtils.isBlank(sessionSalt)) {
        sessionSalt = "A7k254A0itEuQ9ndKJuZ";
    }
    String composite = sessionSalt + "::" + request.getParameter(LTI_CONSUMER_KEY) + "::"
            + request.getParameter(LTI_CONTEXT_ID) + "::" + request.getParameter(LTI_LINK_ID) + "::"
            + request.getParameter(LTI_USER_ID) + "::" + (System.currentTimeMillis() / 1800)
            + request.getHeader("User-Agent") + "::" + request.getContextPath();
    return DigestUtils.md5Hex(composite);
}

From source file:org.apache.cxf.fediz.spring.web.FederationLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    String contextName = request.getContextPath();
    if (contextName == null || contextName.isEmpty()) {
        contextName = "/";
    }/*ww  w .  ja v  a  2 s  .c  o  m*/
    FedizContext fedCtx = federationConfig.getFedizContext(contextName);
    try {
        FedizProcessor wfProc = FedizProcessorFactory.newFedizProcessor(fedCtx.getProtocol());
        RedirectionResponse redirectionResponse = wfProc.createSignOutRequest(request, null, fedCtx); //TODO
        String redirectURL = redirectionResponse.getRedirectionURL();
        if (redirectURL != null) {
            Map<String, String> headers = redirectionResponse.getHeaders();
            if (!headers.isEmpty()) {
                for (String headerName : headers.keySet()) {
                    response.addHeader(headerName, headers.get(headerName));
                }
            }

            response.sendRedirect(redirectURL);
        } else {
            LOG.warn("Failed to create SignOutRequest.");
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Failed to create SignOutRequest.");
        }
    } catch (ProcessingException ex) {
        LOG.warn("Failed to create SignOutRequest: " + ex.getMessage());
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create SignOutRequest.");
    }
}

From source file:org.vaadin.spring.security.web.VaadinDefaultRedirectStrategy.java

@Override
public void sendRedirect(String url) {
    HttpServletRequest request = http.getCurrentRequest();
    HttpServletResponse response = http.getCurrentResponse();

    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    if (logger.isDebugEnabled()) {
        logger.debug("Redirecting to '" + redirectUrl + "'");
    }//from w ww . j ava 2s.  c o  m

    // Change to Vaadin Redirect
    UI.getCurrent().getPage().setLocation(redirectUrl);
}