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.RevertWikiPageAuditEventListener.java

@Override
public void setSpecificAuditMetadata(final Auditable audit, final HttpServletRequest request,
        final JSONObject json, final BufferedHttpServletResponse response) {
    setMetadataFromNodeRef(audit, nodeRefResolver.getNodeRef(request.getRequestURI()));
}

From source file:it.vige.greenarea.sgaplconsole.controllers.utils.RelativeViewHandler.java

/**
 * Get the url-path from the given request.
 * // ww w.j a  v a 2  s .  c  o m
 * @param request
 * @return clean path
 */
private String getPath(final HttpServletRequest request) {
    try {
        // TODO handle more than two '/'
        return StringUtils.replace(new URI(request.getRequestURI()).getPath(), "//", "/");
    } catch (final URISyntaxException e) {
        // XXX URISyntaxException ignored
        return StringUtils.EMPTY;
    }
}

From source file:team.curise.filter.LoginFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    String reqUri = request.getRequestURI();
    HttpSession session = request.getSession();
    String account = (String) session.getAttribute("account");
    if (reqUri.contains("ogin")) {
        System.out.println(reqUri + "...............");
    }//w w w  .  j  a v  a 2  s .  co  m
    ApplicationContext ac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(request.getSession().getServletContext());
    CuriseInfoService c = (CuriseInfoService) ac.getBean("curiseInfoService");
    String url = request.getContextPath();

    //manageLogin??manageLogin
    if (reqUri.contains("login")) {
        List r = c.find("from CuriseInfo");
        List<CuriseInfo> list = (List<CuriseInfo>) r;
        List<String> curiseNames = new ArrayList<>();
        for (CuriseInfo ci : list) {
            curiseNames.add(ci.getName());
        }
        session.setAttribute("curiseNames", curiseNames);
        fc.doFilter(req, resp);
    }

    if (reqUri.contains("ogin") || reqUri.contains("js") || reqUri.contains("css") || reqUri.contains("icon")
            || reqUri.contains("font") || reqUri.contains("icon")) {
        fc.doFilter(req, resp);
        return;
    }

    if (account == null || "".equals(account)) {
        List r = c.find("from CuriseInfo");
        List<CuriseInfo> list = (List<CuriseInfo>) r;
        List<String> curiseNames = new ArrayList<>();
        for (CuriseInfo ci : list) {
            curiseNames.add(ci.getName());
        }
        session.setAttribute("curiseNames", curiseNames);
        response.sendRedirect("login");
    } else {
        fc.doFilter(req, resp);
    }
}

From source file:com.autentia.tnt.servlet.DocRootServlet.java

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

    String uri = request.getRequestURI();
    log.debug("doGet - uri='" + uri + "'");

    int i = uri.indexOf(URL_PREFIX);
    if (i != -1) {
        String relPath = uri.substring(i + URL_PREFIX.length());

        relPath = URLDecoder.decode(relPath, "UTF-8");
        log.debug("doGet - relPath='" + relPath + "'");

        File f = new File(ConfigurationUtil.getDefault().getDocumentRootPath() + relPath);
        if (f.exists()) {
            response.setContentLength((int) f.length());

            String mime = request.getParameter(ARG_MIME);
            if (mime != null && !mime.equals("")) {
                response.setContentType(mime);
            }/*from   www . j  a v  a  2s . c om*/
            OutputStream out = response.getOutputStream();
            InputStream in = null;
            try {
                in = new FileInputStream(f);
                byte[] buffer = new byte[8192];
                int nr;
                while ((nr = in.read(buffer)) != -1) {
                    out.write(buffer, 0, nr);
                }
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } else {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Bad URL prefix for servlet: check your web.xml file");
    }
}

From source file:com.cognifide.aet.executor.SuiteStatusServlet.java

/**
 * Returns JSON with suite status defined by {@link SuiteStatusResult} for a given correlation ID.
 *
 * @param request//from w ww.  ja  va  2  s . com
 * @param response
 * @throws ServletException
 * @throws IOException
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String correlationId = StringUtils.substringAfter(request.getRequestURI(), SERVLET_PATH).replace("/", "");
    SuiteStatusResult suiteStatusResult = suiteExecutor.getExecutionStatus(correlationId);

    if (suiteStatusResult != null) {
        Gson gson = new Gson();
        String responseBody = gson.toJson(suiteStatusResult);

        response.setStatus(200);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(responseBody);
    } else {
        response.sendError(404, "Suite status not found");
    }
}

From source file:com.asual.summer.core.spring.ViewNameTranslator.java

public String getViewName(HttpServletRequest request) {

    String uri = StringUtils/*from  ww w .ja v  a  2 s .  co  m*/
            .stripFilenameExtension(
                    RequestUtils.contextRelative(request.getRequestURI().replaceAll("/+", "/"), false))
            .replaceFirst("/$", "");

    ExtendedInternalResourceViewResolver pagesResolver = null;

    ViewResolverConfiguration viewResolverConfiguraton = BeanUtils
            .getBeanOfType(ViewResolverConfiguration.class);
    List<ViewResolver> viewResolvers = viewResolverConfiguraton.getViewResolvers();

    for (ViewResolver vr : viewResolvers) {
        if (vr instanceof ExtendedInternalResourceViewResolver) {
            ExtendedInternalResourceViewResolver resolver = (ExtendedInternalResourceViewResolver) vr;
            if (resolver.getPrefix().endsWith("/pages")) {
                pagesResolver = resolver;
            }
        }
    }

    String prefix = pagesResolver.getPrefix().replaceAll("/$", "");
    String suffix = pagesResolver.getSuffix();

    String viewName = findViewName(prefix, uri, suffix, false);
    if (viewName != null) {
        return viewName;
    }

    throw new ViewNotFoundException();
}

From source file:com.yuga.ygplatform.modules.sys.interceptor.LogInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {

    String requestRri = request.getRequestURI();
    String uriPrefix = request.getContextPath() + Global.getAdminPath();

    if ((StringUtils.startsWith(requestRri, uriPrefix) && (StringUtils.endsWith(requestRri, "/save")
            || StringUtils.endsWith(requestRri, "/delete") || StringUtils.endsWith(requestRri, "/import")
            || StringUtils.endsWith(requestRri, "/updateSort"))) || ex != null) {

        User user = UserUtils.getUser();
        if (user != null && user.getId() != null) {

            StringBuilder params = new StringBuilder();
            int index = 0;
            for (Object param : request.getParameterMap().keySet()) {
                params.append((index++ == 0 ? "" : "&") + param + "=");
                params.append(StringUtils.abbr(StringUtils.endsWithIgnoreCase((String) param, "password") ? ""
                        : request.getParameter((String) param), 100));
            }/*www.j a  va 2 s . c o  m*/

            Log log = new Log();
            log.setType(ex == null ? Log.TYPE_ACCESS : Log.TYPE_EXCEPTION);
            log.setCreateBy(user);
            log.setCreateDate(new Date());
            log.setRemoteAddr(StringUtils.getRemoteAddr(request));
            log.setUserAgent(request.getHeader("user-agent"));
            log.setRequestUri(request.getRequestURI());
            log.setMethod(request.getMethod());
            log.setParams(params.toString());
            log.setException(ex != null ? ex.toString() : "");
            logDao.save(log);

            logger.debug("save log {type: {}, loginName: {}, uri: {}}, ", log.getType(), user.getLoginName(),
                    log.getRequestUri());

        }
    }

    //      logger.debug(": {}, ?: {}, ?: {}, ?: {}", 
    //            Runtime.getRuntime().maxMemory(), Runtime.getRuntime().totalMemory(), Runtime.getRuntime().freeMemory(), 
    //            Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory()); 

}

From source file:com.earldouglas.filtre.Filtre.java

private void logResult(ServletRequest servletRequest, boolean accessGranted) {
    StringBuffer logStringBuffer = new StringBuffer();
    logStringBuffer.append("Access ");

    if (servletRequest instanceof HttpServletRequest) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

        logStringBuffer.append(" to '");
        logStringBuffer.append(httpServletRequest.getRequestURI());
        logStringBuffer.append("' ");
    }/*from   w  w  w.jav  a2  s.c o m*/

    logStringBuffer.append("from ");
    logStringBuffer.append(servletRequest.getRemoteAddr());
    logStringBuffer.append(" ");

    if (accessGranted) {
        logStringBuffer.append("granted.");
    } else {
        logStringBuffer.append("denied.");
    }

    log.info(logStringBuffer);
}

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

@Override
public void setSpecificAuditMetadata(final Auditable auditable, final HttpServletRequest request,
        final JSONObject json, final BufferedHttpServletResponse response) throws JSONException {
    setMetadataFromNodeRef(auditable, nodeRefResolver.getNodeRef(request.getRequestURI()));
}

From source file:org.smigo.log.LogHandler.java

public void log(HttpServletRequest request, HttpServletResponse response) {
    String requestURI = request.getRequestURI();
    if (!requestURI.endsWith(".png")) {
        log.info(getRequestDump(request, response, ",  "));
        logDao.log(Log.create(request, response));
    }/*from  ww  w . j  a v a 2 s  .c o m*/
}