Example usage for javax.servlet.http HttpServletRequest getServletPath

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

Introduction

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

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:org.springjutsu.validation.mvc.ViewTranslatorValidationFailureRedirector.java

public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {//  w  w w .  j ava2s  .  c o  m
    ModelAndView mav = null;
    if (ex instanceof BindException) {
        String view = null;
        if (viewTranslator != null) {
            try {
                view = viewTranslator.getViewName(request);
            } catch (Exception e) {
                log.error("view translator could not determine view name, utilizing servlet path instead", e);
            }
        }
        if (view == null) {
            view = request.getServletPath();
        }
        mav = new ModelAndView(view, ((BindException) ex).getModel());
    }

    return mav;
}

From source file:com.litemvc.LiteMvcFilter.java

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;

    RequestHelper.setHttpServletRequest(request);
    RequestHelper.setHttpServletResponse(response);

    try {//from   w ww .j a  v a  2  s.  c  o m
        Binding binding = null;
        Matcher matcher = null;
        String servletPath = request.getServletPath();
        for (Pattern p : bindingsMap.keySet()) {
            matcher = p.matcher(servletPath);
            if (matcher.matches()) {
                binding = bindingsMap.get(p);
                break;
            }
        }

        if (binding != null) {
            Object handler = createObject(binding.getHandlerClass());

            if (tryToExecuteMethod(request, response, matcher, binding, handler)) {
                return;
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        RequestHelper.clean();
    }
    chain.doFilter(req, resp);
}

From source file:com.epam.trade.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }/*from  w w  w  .  j a  v a  2  s. c o m*/

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old + "/")) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old + "/", "/" + current + "/");
    }
    return REDIRECT_PREFIX + referer;
}

From source file:com.wavemaker.commons.web.filter.EtagFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    //Disabling etag for ie browser as it is not honouring etag header.
    boolean requestedFromIeBrowser = isRequestFromIeBrowser(request);

    if (request.getRequestURL().indexOf("/services") != -1) {
        logger.debug("Etag Request for url {}, IE browser {}, user-agent {}, servlet Path {} ",
                request.getRequestURL(), requestedFromIeBrowser, request.getHeader("User-Agent"),
                request.getServletPath());
    }/*from  w ww  .j  a v a 2  s.  c om*/

    //Setting no cache for ie as etag is disabled for it.
    if (requestedFromIeBrowser && (request.getServletPath().startsWith("/services")
            || request.getServletPath().startsWith("/app") || request.getServletPath().startsWith("/pages")
            || request.getServletPath().startsWith("/prefabs") || request.getServletPath().endsWith(".json"))) {
        response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
        response.setHeader("Pragma", "no-cache"); // HTTP 1.0
        response.setDateHeader("Expires", 0); // Proxies.
    }
    if (HttpMethod.GET.name().equals(request.getMethod()) && !requestedFromIeBrowser) {
        response.setHeader("Cache-Control", "max-age=0"); // HTTP 1.1
        super.doFilterInternal(request, response, filterChain);
    } else {
        filterChain.doFilter(request, response);
    }

}

From source file:net.maritimecloud.identityregistry.controllers.RoleController.java

/**
 * Returns info about the role identified by the given ID
 *
 * @return a reply...//from ww w. ja  v a2 s .  com
 * @throws McBasicRestException
 */
@RequestMapping(value = "/api/org/{orgMrn}/role/{roleId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<Role> getRole(HttpServletRequest request, @PathVariable String orgMrn,
        @PathVariable Long roleId) throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        Role role = this.roleService.getById(roleId);
        if (role == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ROLE_NOT_FOUND,
                    request.getServletPath());
        }
        if (role.getIdOrganization().compareTo(org.getId()) == 0) {
            return new ResponseEntity<>(role, HttpStatus.OK);
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }

}

From source file:net.maritimecloud.identityregistry.controllers.RoleController.java

/**
 * Deletes a Role/*from  w ww  . j av a 2s.c om*/
 *
 * @return a reply...
 * @throws McBasicRestException
 */
@RequestMapping(value = "/api/org/{orgMrn}/role/{roleId}", method = RequestMethod.DELETE)
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<?> deleteRole(HttpServletRequest request, @PathVariable String orgMrn,
        @PathVariable Long roleId) throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        Role role = this.roleService.getById(roleId);
        if (role == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ROLE_NOT_FOUND,
                    request.getServletPath());
        }
        if (role.getIdOrganization().compareTo(org.getId()) == 0) {
            this.roleService.delete(roleId);
            return new ResponseEntity<>(HttpStatus.OK);
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:net.maritimecloud.identityregistry.controllers.OrganizationController.java

/**
 * Returns info about the organization identified by the given ID
 * /*w  ww.  ja va2s .c o m*/
 * @return a reply...
 * @throws McBasicRestException 
 */
@RequestMapping(value = "/api/org/{orgMrn}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public ResponseEntity<Organization> getOrganization(HttpServletRequest request, @PathVariable String orgMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org == null) {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
    return new ResponseEntity<>(org, HttpStatus.OK);
}

From source file:org.appverse.web.framework.backend.api.controllers.FileRetrievalController.java

@RequestMapping(value = "/*.rpc", method = RequestMethod.POST)
public void handleFormUpload(HttpServletRequest request, HttpServletResponse response) throws Exception {
    @SuppressWarnings("unchecked")
    Enumeration<String> parameterNames = request.getParameterNames();
    Map<String, String> parameters = new HashMap<String, String>();
    while (parameterNames.hasMoreElements()) {
        String parameterName = parameterNames.nextElement();
        String parameter = request.getParameter(parameterName);
        parameters.put(parameterName, parameter);
    }//  ww  w .j  a  va2 s.  c  o  m
    SecurityHelper.checkXSRFToken(request);

    String path = request.getServletPath();
    serviceName.set(path.substring(path.lastIndexOf('/') + 1, path.lastIndexOf('.')));
    processCall(response, parameters);

}

From source file:org.mitre.dsmiley.httpproxy.DynamicProxyServlet.java

private String extractTargetUrl(HttpServletRequest servletRequest) {
    return servletRequest.getRequestURI().replaceAll(servletRequest.getServletPath(), "").replaceFirst("/", "");
}

From source file:com.alfaariss.oa.sso.web.WebSSOServlet.java

private String resolveTarget(HttpServletRequest servletRequest) {
    String sRequestURI = servletRequest.getRequestURI();
    if (!sRequestURI.endsWith("/"))
        sRequestURI = sRequestURI + "/";
    sRequestURI = sRequestURI.toLowerCase();

    String sContextPath = servletRequest.getContextPath();
    String sServletPath = servletRequest.getServletPath();

    String target = sRequestURI.substring(sContextPath.length() + sServletPath.length() + 1);// +1 for trailing /
    if (target != null && target.length() > 1)// >1: target must be larger then '/'
    {/*w w w .j  a v  a 2  s  .c  o  m*/
        int iIndex = target.indexOf("/");
        if (target.length() - 1 > iIndex) {//target must be splitted to first /
            return target.substring(0, iIndex + 1);
        }
        return target;
    }

    return null;
}