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:ar.com.zauber.commons.web.uri.UriJspFunctionsTest.java

/** Test de UriJsp sin cotexto*/
@Test//from w w  w. j  av  a2 s  .c o m
@Ignore(value = "ahora que no se envia el request...")
public final void buildUriDefault() throws Exception {
    setException(true);
    PageContext ctx = getPc();
    HttpServletRequest req = getReq();
    Mockito.when(req.getRequestURI()).thenReturn("/123/abc/asd/asd");
    Mockito.when(req.getContextPath()).thenReturn(StringUtils.EMPTY);
    Assert.assertEquals("../../../abc", UriJspFunctions.buildVarArgs(ctx, "abc", ctx.getRequest()));
}

From source file:de.otto.jsonhome.example.products.ProductsController.java

@RequestMapping(value = "/{productId}", method = RequestMethod.GET, produces = { "application/example-product",
        "application/json" })
@ResponseBody/*from w w w. j a va 2  s  .  c o  m*/
@Rel("/rel/product")
public Map<String, Object> getProductAsJson(final @PathVariable long productId,
        final HttpServletRequest request) {
    return productToJson(productService.findProduct(productId), request.getContextPath());
}

From source file:org.nebula.service.auth.AuthenticationInterceptor.java

private void checkIfAccessAdminUrls(AuthenticationHelper helper, HttpServletRequest request)
        throws GeneralSecurityException {

    if (!helper.isAdmin()) {

        String contextPath = request.getContextPath();
        String requestUri = request.getRequestURI();

        for (String url : adminUrls) {
            if (requestUri.startsWith(contextPath + url)) {
                throw new GeneralSecurityException(
                        "The user is not allowed to access the url " + (contextPath + url));
            }/*from  w w w  . j  a  v a 2 s .  c o  m*/
        }
    }
}

From source file:mvc.interceptor.AutorizadorInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object controller)
        throws Exception {

    String uri = request.getRequestURI();
    String contextPath = request.getContextPath();

    if (uri.endsWith(contextPath) || uri.contains("index") || uri.contains("formLogin")
            || uri.contains("efetuaLogin") || uri.contains("listaTarefas") || uri.contains("resources")) {
        return true;
    }/*  w w  w .  j  a  v  a  2  s .c o m*/

    HttpSession session = request.getSession();

    if (session.getAttribute("usuarioLogado") != null) {
        return true;
    }

    response.sendRedirect("formLogin");

    return false;
}

From source file:eu.openanalytics.rpooli.web.BaseUriInjectionFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletRequest req = (HttpServletRequest) request;
    final String baseUri = StringUtils.replace(req.getRequestURL().toString(), req.getRequestURI(),
            req.getContextPath());
    request.setAttribute("baseUri", baseUri);

    chain.doFilter(request, response);//  ww w  .j ava 2 s .c om
}

From source file:ar.com.zauber.commons.web.uri.UriJspFunctionsTest.java

/** Test que prueba si el pedido es en el mismo segmento ..*/
@Test//from  w  w  w .ja  v a 2 s. c o m
@Ignore(value = "ahora que no se envia el request...")
public final void buildUriWithContext() {
    setException(true);
    PageContext ctx = getPc();
    HttpServletRequest req = getReq();
    Mockito.when(req.getRequestURI()).thenReturn("/app/bin/nada");
    Mockito.when(req.getContextPath()).thenReturn("/app/bin");
    Assert.assertEquals("./abc", UriJspFunctions.buildVarArgs(ctx, "abc", ctx.getRequest()));

    Assert.assertEquals("./abc", UriJspFunctions.buildVarArgs(ctx, "/abc", ctx.getRequest()));

    Mockito.when(req.getRequestURI()).thenReturn("/app/bin/nada/par");
    Mockito.when(req.getContextPath()).thenReturn("/app/bin");

    Assert.assertEquals("../par/abc", UriJspFunctions.buildVarArgs(ctx, "/par/abc", ctx.getRequest()));
}

From source file:com.hp.autonomy.frontend.find.core.web.FindController.java

@RequestMapping("/")
public void index(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String contextPath = request.getContextPath();

    if (LoginTypes.DEFAULT.equals(authenticationConfigService.getConfig().getAuthentication().getMethod())) {
        response.sendRedirect(contextPath + DEFAULT_LOGIN_PAGE);
    } else {//from w  ww. j  a v  a2 s .c  o  m
        response.sendRedirect(contextPath + APP_PATH);
    }
}

From source file:net.bafeimao.umbrella.web.interceptor.SecurityCheckingHandlerInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (request.getSession().getAttribute("user") == null) {
        response.sendRedirect(request.getContextPath() + "/login?returl=" + request.getPathInfo());
        return false;
    }//from  w  w w.j  a va2 s .c  o  m

    return super.preHandle(request, response, handler);
}

From source file:org.openmrs.module.mohtracportal.web.controller.MohTracPortalModuleFormController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    if (Context.getAuthenticatedUser() == null)
        return new ModelAndView(new RedirectView(request.getContextPath() + "/login.htm"));

    ModelAndView mav = new ModelAndView();
    mav.setViewName(getViewName());//www  . j  av a  2s.  c  o  m

    return mav;
}

From source file:org.uaa.security.core.AuthorizationManager.java

public void decide(UsernamePasswordToken token, HttpServletRequest request) throws AccessDeniedException {
    String action = request.getMethod().toUpperCase();
    String uri = request.getRequestURI();
    String context = request.getContextPath();
    log.debug(uri.replace(context, ""));

    List<Integer> roles = token.getRoles();

    if (!SecuritySupport.isAllowed(action, uri.replace(context, ""), roles)) {
        log.info("you don't have needed authorities to access this resource");
        throw new AccessDeniedException("you don't have needed authorities to access this resource");
    }//from   w  ww  .j av a 2  s.  c  o m
}