Example usage for javax.servlet.http HttpServletRequest getRequestURI

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

Introduction

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

Prototype

public String getRequestURI();

Source Link

Document

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Usage

From source file:com.surevine.alfresco.audit.listeners.EditDiscussionReplyAuditEventListener.java

@Override
public boolean isEventFired(final HttpServletRequest request) {

    JSONObject json = parseJSONFromPostContent(request);
    if (json != null) {
        return request.getRequestURI().contains(URI_DESIGNATOR) && !json.has(AlfrescoJSONKeys.TITLE);
    }/*from w  w w . j  a  va  2  s  .  c  o  m*/

    return false;

}

From source file:com.hastybox.lesscss.compileservice.controller.spring.UrlBasedSpringLessController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String requestUri = request.getRequestURI();

    LOGGER.debug("Handling request to {}", requestUri);

    Matcher matcher = pathPattern.matcher(requestUri);

    if (!matcher.find()) {
        // no match found, return 404
        LOGGER.info("Request URI {} not mathing pattern, returning 404");

        response.sendError(404);//from   w w w  . j  a  v  a  2 s.  co m
        return null;
    }

    String resourcePath = matcher.group(1) + ".less";

    // compile the LESS code
    compileLess(resourcePath, response);

    return null;
}

From source file:mx.com.sagarpa.snics.SeguridadFiltro.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    String requestURI = request.getRequestURI();
    // LOG.info(requestURI);

    //hardcodear la request uri
    requestURI = "testteooo";
    ///*from w  ww  . j  a  v a 2  s .  co  m*/
    System.out.println(requestURI);
    RestClientImpl clienteRest = new RestClientImpl();
    // usr 4 para que truene
    String respuesta = clienteRest.POST("{\"token\":1,\"ruta\":\"" + requestURI + "\"}",
            "http://localhost:8081/snics-services/Usuario/validarPermiso.do", "");
    System.out.println(respuesta);
    JSONParser parser = new JSONParser();
    JSONObject jsonRespuesta = null;
    try {
        jsonRespuesta = (JSONObject) parser.parse(respuesta);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Boolean autorizacion = (Boolean) jsonRespuesta.get("autorizacion");
    String token = (String) jsonRespuesta.get("token");
    System.out.println(autorizacion);
    //validacion del token tiempo de espera
    if (token.length() != 0) {
        //validacion de los permisos
        if (autorizacion == true) {

            chain.doFilter(req, res);
        } else {
            ((HttpServletResponse) res)
                    .sendRedirect(((HttpServletRequest) req).getContextPath() + "/views/admin/forbidden.jsp");

        }
    } else {
        ((HttpServletResponse) res)
                .sendRedirect(((HttpServletRequest) req).getContextPath() + "/views/admin/login.jsp");
    }
    //           if (requestURI.startsWith("/Check_License/Dir_My_App/")) {
    //               String toReplace = requestURI.substring(requestURI.indexOf("/Dir_My_App"), requestURI.lastIndexOf("/") + 1);
    //               String newURI = requestURI.replace(toReplace, "?Contact_Id=");
    //               req.getRequestDispatcher(newURI).forward(req, res);
    //           } else {
    //               chain.doFilter(req, res);
    //           }
    //           HttpServletResponse resp = (HttpServletResponse) res;
    //           resp.reset();
    //           resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    //           resp.setHeader("Location", "/mus-web/views/admin/diagnostico.jsp");
    //           return;

}

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

/**
 * If a file corresponding to the request is on the filesystem return it,
 * otherwise return <code>null</code>.
 *///from   www  .ja va2  s.  c o m
private File retrieveFile(HttpServletRequest request) {
    String filename = request.getRequestURI().substring(request.getContextPath().length());
    try {
        filename = URLDecoder.decode(filename, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // this doesn't happen - UTF-8 is always supported
    }
    File file = new File(Environment.getValue(Environment.PROP_BASE_FILE_DIR), filename);
    return (file.exists()) ? file : null;
}

From source file:com.zjzcn.web.LogInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    Map<String, LogNode> logConfigs = ConfigHelper.getLogConfigs();
    String username = userService.getUsername();
    if (logConfigs != null && StringUtils.isNotBlank(username)) {
        HttpServletRequest req = (HttpServletRequest) request;
        String uri = req.getRequestURI().split("[?]")[0];
        String[] strs = uri.split("[\\/\\.]");
        if (strs.length < 2) {
            return;
        }// w w  w . j a  va2  s  . com
        String perm = strs[strs.length - 2];

        if (logConfigs.containsKey(perm)) {
            StringBuffer param = 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) {
                                param.append(parameterName + " = " + parameterValue + "\n");
                            }
                        }
                    }
                }
            }
            LogNode logConfig = logConfigs.get(perm);
            Log log = new Log();
            log.setLogType(0);
            log.setName(logConfig.getName());
            log.setUsername(username);
            log.setCreateTime(DateUtils.getCurrentTime(null));
            log.setContent(param.toString());
            log.setIp(request.getRemoteAddr());
            //logService.save(log);
        }
    }
}

From source file:de.elomagic.mag.ServletMock.java

@Override
protected void doHead(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getRequestURI().endsWith("TestFile.pdf")) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {/*from   www  .  ja  v a  2s  . com*/
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:io.github.microcks.web.filter.StaticResourcesFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
    String contextPath = httpRequest.getContextPath();
    String requestURI = httpRequest.getRequestURI();
    requestURI = StringUtils.substringAfter(requestURI, contextPath);
    if (StringUtils.equals("/", requestURI)) {
        requestURI = "/index.html";
    }//ww w.ja v a  2s .  c om
    String newURI = "/dist" + requestURI;
    log.debug("Dispatching to URI: {}", newURI);
    servletRequest.getRequestDispatcher(newURI).forward(servletRequest, servletResponse);
}

From source file:net.duckling.ddl.web.interceptor.access.FetchCodeInterceptor.java

private int getShareRid(HttpServletRequest request) {
    String requestURI = request.getRequestURI();
    int index = requestURI.lastIndexOf("/");
    String ridS = requestURI.substring(index + 1);
    return ShareRidCodeUtil.decode(ridS);
}

From source file:com.example.notes.RestNotesControllerAdvice.java

@ExceptionHandler(ResourceDoesNotExistException.class)
public void handleResourceDoesNotExistException(ResourceDoesNotExistException ex, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    response.sendError(HttpStatus.NOT_FOUND.value(),
            "The resource '" + request.getRequestURI() + "' does not exist");
}

From source file:de.otto.jsonhome.controller.DocController.java

/**
 * Returns the source code of the requested document.
 *
 * @param request the HttpServletRequest.
 * @return source of the documentation./*from www .  j  ava  2  s  .c  om*/
 * @throws IOException if the resource can not be found.
 */
private String getSourceFor(final HttpServletRequest request) throws IOException {
    final String requestURI = request.getRequestURI().substring(request.getRequestURI().indexOf("/docs/") + 6);
    final InputStream file = rootDir.createRelative(requestURI).getInputStream();
    try {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(file));
        String line;
        final StringBuilder markdown = new StringBuilder();

        while ((line = reader.readLine()) != null) {
            markdown.append(line);
            markdown.append(LINE_SEPARATOR);
        }

        return markdown.toString();
    } finally {
        file.close();
    }
}