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:gov.nih.nci.ncicb.tcga.dcc.common.web.StaticContentServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final String rawResourcePath = request.getServletPath() + request.getPathInfo();

    if (log.isDebugEnabled()) {
        log.debug("Attempting to GET resource: " + rawResourcePath);
    }//www .ja  v a 2 s .co m
    final URL[] resources = getRequestResourceURLs(request);
    if (resources == null || resources.length == 0) {
        if (log.isDebugEnabled()) {
            log.debug("Resource not found: " + rawResourcePath);
        }
        response.sendError(HttpServletResponse.SC_NOT_FOUND); //Error 404
        return;
    }
    //Render the resource as-is with a stream
    prepareResponse(response, resources, rawResourcePath);
    final OutputStream out = response.getOutputStream();
    try {
        for (int i = 0; i < resources.length; i++) {
            final URLConnection resourceConn = resources[i].openConnection();
            final InputStream in = resourceConn.getInputStream();
            try {
                byte[] buffer = new byte[1024];
                int bytesRead = -1;
                while ((bytesRead = in.read(buffer)) != -1) {
                    out.write(buffer, 0, bytesRead);
                }
            } finally {
                in.close();
            }
        }
    } finally {
        out.close();
    }
}

From source file:com.education.lessons.ui.server.login.OpenIDLoginController.java

/**
 * Builds the callback URL; realm + context path + return path, e.g.
 * http://www.mydomain.com/context/return.htm
 */// w w  w  .j a  v  a2s  .c o m
private String getReturnTo(HttpServletRequest request) {
    String realm = getRealm(request);
    realm = realm.substring(0, realm.length() - 1);
    String contextPath = request.getContextPath();
    String servletPath = request.getServletPath();
    return realm + contextPath + servletPath + "/login/openid/verify";
}

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  ww  w  .j  a  va2 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.dp2345.interceptor.LogInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    List<LogConfig> logConfigs = logConfigService.getAll();
    if (logConfigs != null) {
        String path = request.getServletPath();
        for (LogConfig logConfig : logConfigs) {
            if (antPathMatcher.match(logConfig.getUrlPattern(), path)) {
                String username = adminService.getCurrentUsername();
                String operation = logConfig.getOperation();
                String operator = username;
                String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                String ip = request.getRemoteAddr();
                request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                StringBuffer parameter = new StringBuffer();
                Map<String, String[]> parameterMap = request.getParameterMap();
                if (parameterMap != null) {
                    for (Entry<String, String[]> entry : parameterMap.entrySet()) {
                        String parameterName = entry.getKey();
                        if (!ArrayUtils.contains(ignoreParameters, parameterName)) {
                            String[] parameterValues = entry.getValue();
                            if (parameterValues != null) {
                                for (String parameterValue : parameterValues) {
                                    parameter.append(parameterName + " = " + parameterValue + "\n");
                                }//from   w w w  .j ava 2 s . com
                            }
                        }
                    }
                }
                Log log = new Log();
                log.setOperation(operation);
                log.setOperator(operator);
                log.setContent(content);
                log.setParameter(parameter.toString());
                log.setIp(ip);
                logService.save(log);
                break;
            }
        }
    }
}

From source file:com.hyeb.back.log.LogInterceptor.java

@SuppressWarnings("unchecked")
@Override//from w  w  w.  j a v  a  2s. com
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    List<LogConfig> logConfigs = logConfigService.getAll();
    if (logConfigs != null) {
        String path = request.getServletPath();
        for (LogConfig logConfig : logConfigs) {
            if (antPathMatcher.match(logConfig.getUrlPattern(), path)) {
                String username = sysUserService.getCurrentUsername();
                String operation = logConfig.getOperation();
                String operator = username;
                String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                String ip = request.getRemoteAddr();
                request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                StringBuffer parameter = new StringBuffer();
                Map<String, String[]> parameterMap = request.getParameterMap();
                if (parameterMap != null) {
                    for (Entry<String, String[]> entry : parameterMap.entrySet()) {
                        String parameterName = entry.getKey();
                        if (!ArrayUtils.contains(ignoreParameters, parameterName)) {
                            String[] parameterValues = entry.getValue();
                            if (parameterValues != null) {
                                for (String parameterValue : parameterValues) {
                                    parameter.append(parameterName + " = " + parameterValue + "\n");
                                }
                            }
                        }
                    }
                }
                Log log = new Log();
                log.setOperation(operation);
                log.setOperator(operator);
                log.setContent(content);
                log.setParameter(parameter.toString());
                log.setIp(ip);
                logService.save(log);
                break;
            }
        }
    }
}

From source file:net.groupbuy.interceptor.LogInterceptor.java

@SuppressWarnings("unchecked")
@Override/* ww  w. ja  v a  2s . c  om*/
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    List<LogConfig> logConfigs = logConfigService.getAll();
    if (logConfigs != null) {
        String path = request.getServletPath();
        for (LogConfig logConfig : logConfigs) {
            if (antPathMatcher.match(logConfig.getUrlPattern(), path)) {
                String username = adminService.getCurrentUsername();
                String operation = logConfig.getOperation();
                String operator = username;
                String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                String ip = request.getRemoteAddr();
                request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                StringBuffer parameter = new StringBuffer();
                Map<String, String[]> parameterMap = request.getParameterMap();
                if (parameterMap != null) {
                    for (Entry<String, String[]> entry : parameterMap.entrySet()) {
                        String parameterName = entry.getKey();
                        if (!ArrayUtils.contains(ignoreParameters, parameterName)) {
                            String[] parameterValues = entry.getValue();
                            if (parameterValues != null) {
                                for (String parameterValue : parameterValues) {
                                    parameter.append(parameterName + " = " + parameterValue + "\n");
                                }
                            }
                        }
                    }
                }
                Log log = new Log();
                log.setOperation(operation);
                log.setOperator(operator);
                log.setContent(content);
                log.setParameter(parameter.toString());
                log.setIp(ip);
                logService.save(log);
                break;
            }
        }
    }
}

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

@ApiOperation(hidden = true, value = "Reports a bug")
@RequestMapping(value = "/api/report-bug", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody//from  w ww.java  2 s  . co m
public ResponseEntity<?> reportBug(HttpServletRequest request, @RequestBody BugReport report)
        throws McBasicRestException {
    try {
        emailUtil.sendBugReport(report);
    } catch (MessagingException e) {
        throw new McBasicRestException(HttpStatus.INTERNAL_SERVER_ERROR,
                MCIdRegConstants.BUG_REPORT_CREATION_FAILED, request.getServletPath());
    }
    return new ResponseEntity<>(HttpStatus.OK);
}

From source file:com.jaspersoft.jasperserver.war.StaticFilesCacheControlFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        String path = httpServletRequest.getServletPath();
        if (path != null) {
            String resourcePatch = httpServletRequest.getPathInfo() == null ? path
                    : path.concat(httpServletRequest.getPathInfo());

            boolean excludeFromCacheFlag = false;
            for (String exclRegex : exclusionRegexSet) {
                if (path.matches(exclRegex)) {
                    log.debug("Excluding the path from browser cache by not setting the response header: "
                            + path);/* w w w.  j  av a2s  .  c  o m*/
                    excludeFromCacheFlag = true;
                    break;
                }
            }

            if (!excludeFromCacheFlag) {
                boolean set = false;
                for (String suffix : urlSuffixes) {
                    if (path.toLowerCase().endsWith(suffix)) {
                        log.debug("Setting headers for " + path);
                        setHeaders(httpServletRequest, httpServletResponse);
                        set = true;
                        break;
                    }
                }
                if (!set) {
                    for (String prefix : urlPrefixes) {
                        if (resourcePatch.toLowerCase().startsWith(prefix)) {
                            log.debug("Setting headers for " + resourcePatch);
                            setHeaders(httpServletRequest, httpServletResponse);
                            break;
                        }
                    }
                }
            }
        }
    }

    chain.doFilter(request, response);
}

From source file:com.sammyun.interceptor.LogInterceptor.java

@SuppressWarnings("unchecked")
@Override// ww  w  .  ja  v a 2  s. c o  m
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    List<LogConfig> logConfigs = logConfigService.getAll();
    if (logConfigs != null) {
        String path = request.getServletPath();
        for (LogConfig logConfig : logConfigs) {
            if (antPathMatcher.match(logConfig.getUrlPattern(), path)) {
                String username = adminService.getCurrentUsername();
                String operation = logConfig.getOperation();
                String operator = username;
                String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                String ip = EduUtil.getAddr(request);
                request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME);
                StringBuffer parameter = new StringBuffer();
                Map<String, String[]> parameterMap = request.getParameterMap();
                if (parameterMap != null) {
                    for (Entry<String, String[]> entry : parameterMap.entrySet()) {
                        String parameterName = entry.getKey();
                        if (!ArrayUtils.contains(ignoreParameters, parameterName)) {
                            String[] parameterValues = entry.getValue();
                            if (parameterValues != null) {
                                for (String parameterValue : parameterValues) {
                                    parameter.append(parameterName + " = " + parameterValue + "\n");
                                }
                            }
                        }
                    }
                }
                Log log = new Log();
                log.setOperation(operation);
                log.setOperator(operator);
                log.setContent(content);
                log.setParameter(parameter.toString());
                log.setIp(ip);
                logService.save(log);
                break;
            }
        }
    }
}

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

/**
 * URL format: /report/{cmd}/{dbgrp}/{dbhost}/{alertType}/{ts}/{random}.html
 * @param req//ww  w .  j a  v a  2  s  .  c  o m
 * @return
 */
private Map<String, String> parseURL(HttpServletRequest req) {
    Map<String, String> reqParams = new HashMap<String, String>();
    String path = req.getServletPath();
    if (path != null) {
        String[] paths = path.split("/");
        if (paths.length > 2) {
            reqParams.put(Constants.URL_PATH_CMD, paths[2]);
            if (paths.length > 3)
                reqParams.put(Constants.URL_PATH_DBGROUP, paths[3]);
            if (paths.length > 4)
                reqParams.put(Constants.URL_PATH_DBHOST, paths[4]);
            if (paths.length > 5)
                reqParams.put(Constants.URL_PATH_ALERT_TYPE, paths[5]);
            if (paths.length > 6)
                reqParams.put(Constants.URL_PATH_START_TS, paths[6]);
        }
    }
    return reqParams;
}