Example usage for javax.servlet.http HttpServletRequest getAttribute

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

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:com.chessix.vas.web.RequestProcessingTimeInterceptor.java

@Override
public void afterCompletion(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception ex) throws Exception {
    if (log.isDebugEnabled()) {
        final long startTime = (Long) request.getAttribute(START_TIME);
        log.debug("Request URL::{}:: Time Taken={} ms", request.getRequestURL(),
                System.currentTimeMillis() - startTime);
    }/*ww  w. j av  a2s  .c  o  m*/
}

From source file:com.sonicle.webtop.core.app.servlet.Login.java

private String getRequestForwardServletPath(HttpServletRequest request) {
    return (String) request.getAttribute(javax.servlet.RequestDispatcher.FORWARD_SERVLET_PATH);
}

From source file:elw.web.ErrController.java

@RequestMapping(value = "*")
public ModelAndView do_handle(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final String url = (String) req.getAttribute("javax.servlet.error.request_uri");
    final Integer statusCode = (Integer) req.getAttribute("javax.servlet.error.status_code");

    if (statusCode != null && 404 == statusCode && ignoredUris.contains(url)) {
        resp.sendError(410, "ignored");
        return null;
    }/*from   w  ww .jav a 2 s.c  om*/

    try {
        final String message = (String) req.getAttribute("javax.servlet.error.message");
        final Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception");
        final String eventId = Long.toString(System.currentTimeMillis(), 36);

        final StringWriter logDest = new StringWriter();
        final PrintWriter logOut = new PrintWriter(logDest);
        final HttpSession session = req.getSession(false);

        logOut.println(
                "web error: eventId=" + eventId + " status=" + statusCode + " message='" + message + "'");
        logOut.println("url: " + url);
        logOut.print("attributes: ");
        final Enumeration reqAttrNames = req.getAttributeNames();
        while (reqAttrNames.hasMoreElements()) {
            final String aName = (String) reqAttrNames.nextElement();
            if (!aName.startsWith("javax.servlet") && !aName.startsWith("org.springframework")) {
                logOut.print(aName + "=" + String.valueOf(req.getAttribute(aName)) + " ");
            }
        }
        logOut.println();

        if (session != null) {
            logOut.println("session id: " + session.getId());
            logOut.print("session: ");
            final Enumeration sessAttrNames = session.getAttributeNames();
            while (sessAttrNames.hasMoreElements()) {
                final String aName = (String) sessAttrNames.nextElement();
                if (!aName.startsWith("javax.servlet") && !aName.startsWith("org.springframework")) {
                    logOut.print(aName + "=" + String.valueOf(session.getAttribute(aName)) + " ");
                }
            }
            logOut.println();
        }

        log.error(logDest.toString(), throwable);

        final PrintWriter out = resp.getWriter();

        out.print("<html><title>HTTP status " + statusCode + " : " + message + "</title>"
                + "<body><h3>HTTP status " + statusCode + " : " + message + "</h3>"
                + "Sorry for inconvenience and thanks for finding just another bug out there.<br/>"
                + "For the time being, you may log out, log in and then try the operation once again.<br/><br/>"
                + "Event reference id: <b>" + eventId + "</b>." + "</body></html>");
    } catch (Throwable t) {
        log.error("failed on reporting error", t);
    }

    return null;
}

From source file:es.logongas.ix3.web.util.ControllerHelper.java

public EndPoint getEndPoint(HttpServletRequest httpServletRequest) {
    String path = (String) httpServletRequest
            .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String method = httpServletRequest.getMethod();
    EndPoint endPoint = EndPoint.getBestEndPoint(
            EndPoint.getMatchEndPoint(endPointsFactory.getEndPoints(), path, method), path, method);

    return endPoint;
}

From source file:io.kahu.hawaii.rest.AbstractController.java

protected RequestLogBuilder requestLog() {

    String method = new Throwable().getStackTrace()[1].getMethodName();
    String type = logTypePrefix + "." + method;
    RequestLogBuilder builder = new RequestLogBuilder(logManager, type);

    try {// ww w  .  j a  va  2 s.  com
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = sra.getRequest();

        // path variables
        Map<String, String> pathVariables = (Map<String, String>) request
                .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        if (pathVariables != null) {
            for (Map.Entry<String, String> entry : pathVariables.entrySet()) {
                builder.param(entry.getKey(), entry.getValue());
            }
        }

        // request parameters
        Enumeration<?> requestParameters = request.getParameterNames();
        while (requestParameters.hasMoreElements()) {
            String key = (String) requestParameters.nextElement();
            String[] values = request.getParameterValues(key);
            builder.param(key, values);
        }

    } catch (Throwable t) {
        logManager.warn(CoreLoggers.SERVER, "Unable to log request", t);
        // ignore
    }
    return builder.excludeParam("_");
}

From source file:br.mdarte.exemplo.academico.accessControl.EntrarLoginValidar.java

/**
 * <p>/*from  w  w  w .ja  va 2s  .  c  om*/
 *  Retrieves the exception handler messages (if any).  Creates a new
 *  ActionMessages instance and returns that if one doesn't already exist.
 * </p>
 */
private org.apache.struts.action.ActionMessages getExceptionHandlerErrors(HttpServletRequest request) {
    org.apache.struts.action.ActionMessages errors = (org.apache.struts.action.ActionMessages) request
            .getAttribute("org.andromda.bpm4struts.errormessages");
    if (errors == null) {
        errors = new org.apache.struts.action.ActionMessages();
        request.setAttribute("org.andromda.bpm4struts.errormessages", errors);
    }
    return errors;
}

From source file:com.adito.extensions.actions.ExtensionBundleInformationAction.java

/**
 * Display information about an extension bundle
 * //from   w ww .ja v  a  2 s  .c  om
 * @param mapping mapping
 * @param form form
 * @param request request
 * @param response response
 * @return forward
 * @throws Exception on any error
 */
public ActionForward extensionBundleInformation(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    ((ExtensionBundleInformationForm) form)
            .initialise((ExtensionBundle) request.getAttribute(Constants.REQ_ATTR_INFO_RESOURCE));
    return mapping.findForward("display");
}

From source file:edu.umd.cs.submitServer.servlets.HandleBuildServerLogMessage.java

/**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to
 * post.//from   w w  w  .j  a  v a 2s  .  c  om
 *
 * @param request
 *            the request send by the client to the server
 * @param response
 *            the response send by the server to the client
 * @throws ServletException
 *             if an error occurred
 * @throws IOException
 *             if an error occurred
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST);
    FileItem fileItem = null;
    LoggingEvent loggingEvent = null;
    ObjectInputStream in = null;
    try {
        fileItem = multipartRequest.getFileItem();
        byte[] data = fileItem.get();

        in = new ObjectInputStream(new ByteArrayInputStream(data));
        loggingEvent = (LoggingEvent) in.readObject();

        buildServerLogger.callAppenders(loggingEvent);
    } catch (ClassNotFoundException e) {
        throw new ServletException("Cannot find class: " + e.getMessage(), e);
    } finally {
        if (fileItem != null)
            fileItem.delete();
        if (in != null)
            in.close();
    }
}

From source file:com.epam.cme.storefront.controllers.cms.AbstractCMSComponentController.java

@RequestMapping
public String handleGet(final HttpServletRequest request, final HttpServletResponse response, final Model model)
        throws Exception {
    String componentUid = (String) request.getAttribute(COMPONENT_UID);
    if (StringUtils.isEmpty(componentUid)) {
        componentUid = request.getParameter(COMPONENT_UID);
    }//from w w  w  . j a v a2  s. c o  m

    if (StringUtils.isEmpty(componentUid)) {
        LOG.error("No component specified in [" + COMPONENT_UID + "]");
        throw new AbstractPageController.HttpNotFoundException();
    }

    try {
        final T component = (T) cmsComponentService.getSimpleCMSComponent(componentUid);
        if (component == null) {
            LOG.error("Component with UID [" + componentUid + "] is null");
            throw new AbstractPageController.HttpNotFoundException();
        } else {
            // Add the component to the model
            model.addAttribute("component", component);

            // Allow subclasses to handle the component
            return handleComponent(request, response, model, component);
        }
    } catch (final CMSItemNotFoundException e) {
        LOG.error("Could not find component with UID [" + componentUid + "]");
        throw new AbstractPageController.HttpNotFoundException(e);
    }
}