Example usage for javax.servlet ServletRequest getAttribute

List of usage examples for javax.servlet ServletRequest getAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletRequest 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.agiletec.plugins.jpblog.aps.tags.util.BlogPagerTagHelper.java

private String getPagerId(String pagerId, boolean pagerIdFromFrame, ServletRequest request) {
    String truePagerId = pagerId;
    if (null == truePagerId && pagerIdFromFrame) {
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        if (reqCtx != null) {
            int currentFrame = this.getCurrentFrame(reqCtx);
            truePagerId = "frame" + currentFrame;
        }//from w  w w  . j  ava  2 s . c  om
    }
    return truePagerId;
}

From source file:nl.surfnet.coin.shared.filter.LoggingFilter.java

private void postHandle(ServletRequest request, HttpServletResponse response, Exception e) {

    String responseData = ((ByteArrayOutputStream) request.getAttribute(OUTPUT_STREAM_COPY_ATTR)).toString();

    MemorizingResponseWrapper responseWrapper = (MemorizingResponseWrapper) response;

    if (RESPONSE_LOG.isDebugEnabled()) {
        String requestId = (String) request.getAttribute(REQUEST_ID_ATTR);
        RESPONSE_LOG.debug("{} Response status: {}", requestId, responseWrapper.getStatus());

        if (RESPONSE_LOG.isTraceEnabled()) {
            RESPONSE_LOG.trace("{} Response data: {}", requestId, responseData);
        }//  ww w . j  a  v  a 2 s. c  o  m
    }
    if (e != null) {
        String requestId = (String) request.getAttribute(REQUEST_ID_ATTR);
        RESPONSE_LOG.info("Exception in request {}: {}", requestId, e.getMessage());
    }
}

From source file:com.agiletec.aps.tags.ExecWidgetTag.java

protected void buildWidgetOutput(IPage page, String[] widgetOutput) throws JspException {
    ServletRequest req = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
    try {/*w  w w  . j av  a  2  s. c o m*/
        List<IFrameDecoratorContainer> decorators = this.extractDecorators();
        BodyContent body = this.pageContext.pushBody();
        Widget[] widgets = page.getWidgets();
        for (int frame = 0; frame < widgets.length; frame++) {
            reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME, new Integer(frame));
            Widget widget = widgets[frame];
            body.clearBody();
            this.includeWidget(reqCtx, widget, decorators);
            widgetOutput[frame] = body.getString();
        }
    } catch (Throwable t) {
        String msg = "Error detected during widget preprocessing";
        throw new JspException(msg, t);
    }
}

From source file:com.agiletec.plugins.jpcrowdsourcing.aps.tags.CurrentPageWidgetTag.java

private Widget extractShowlet() {
    ServletRequest req = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
    Widget showlet = null;//from   w w  w  .  j  a  va2  s. c o m
    if (this.getFrame() < 0 && StringUtils.isBlank(this.getWidget())) {
        showlet = (Widget) reqCtx.getExtraParam((SystemConstants.EXTRAPAR_CURRENT_WIDGET));
    } else {
        IPage currentPage = (IPage) reqCtx.getExtraParam((SystemConstants.EXTRAPAR_CURRENT_PAGE));
        Widget[] showlets = currentPage.getWidgets();
        if (this.getFrame() >= 0) {
            if (showlets.length > this.getFrame()) {
                showlet = showlets[this.getFrame()];
            }
        } else {
            for (int i = 0; i < showlets.length; i++) {
                Widget currentWidget = showlets[i];
                if (null != currentWidget && currentWidget.getType().getCode().equals(this.getWidget())) {
                    showlet = currentWidget;
                    break;
                }
            }
        }
    }
    return showlet;
}

From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java

private String getControllerName(ServletRequest request) {
    String controllerName = (String) request
            .getAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE);
    if (controllerName == null || controllerName.length() == 0) {
        GroovyObject controller = getController(request);
        if (controller != null) {
            controllerName = (String) controller.getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY);
            request.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE, controllerName);
        }//from ww  w. ja  va 2s  .c o m
    }
    return controllerName != null ? controllerName : "";
}

From source file:com.agiletec.aps.tags.ExecWidgetTag.java

/**
 * Invoke the widget configured in the page.
 *
 * @throws JspException In case of errors in this method or in the included
 * JSPs/*  w ww . j  a  v  a  2  s. co m*/
 */
@Override
public int doEndTag() throws JspException {
    ServletRequest req = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
    try {
        reqCtx.addExtraParam(SystemConstants.EXTRAPAR_HEAD_INFO_CONTAINER, new HeadInfoContainer());
        IPage page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        String[] widgetOutput = new String[page.getWidgets().length];
        reqCtx.addExtraParam("ShowletOutput", widgetOutput);
        this.buildWidgetOutput(page, widgetOutput);
        String redirect = (String) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXTERNAL_REDIRECT);
        if (null != redirect) {
            HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse();
            response.sendRedirect(redirect);
            return SKIP_PAGE;
        }
        this.pageContext.popBody();
    } catch (Throwable t) {
        String msg = "Error detected during widget preprocessing";
        ApsSystemUtils.logThrowable(t, this, "doEndTag", msg);
        throw new JspException(msg, t);
    }
    return super.doEndTag();
}

From source file:com.agiletec.aps.tags.URLTag.java

/**
 * Prepares a PageURL object; this object may comprehend several sub-tags
 *///from w  w w  .java2s . c o  m
@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {
        IURLManager urlManager = (IURLManager) ApsWebApplicationUtils.getBean(SystemConstants.URL_MANAGER,
                this.pageContext);
        this._pageUrl = urlManager.createURL(reqCtx);
        if (_pageCode != null) {
            _pageUrl.setPageCode(_pageCode);
        }
        if (_langCode != null) {
            _pageUrl.setLangCode(_langCode);
        }
        if (this.isParamRepeat()) {
            List<String> exclusion = this.getParametersToExclude();
            _pageUrl.setParamRepeat(exclusion);
        }
    } catch (Throwable t) {
        _logger.error("Error during tag initialization", t);
        throw new JspException("Error during tag initialization", t);
    }
    return EVAL_BODY_INCLUDE;
}

From source file:org.etudes.jforum.util.legacy.clickstream.ClickstreamFilter.java

/**
 * Processes the given request and/or response.
 * //ww w.ja v  a 2 s . com
 * @param request The request
 * @param response The response
 * @param chain The processing chain
 * @throws IOException If an error occurs
 * @throws ServletException If an error occurs
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    // Ensure that filter is only applied once per request.
    if (request.getAttribute(FILTER_APPLIED) == null) {
        request.setAttribute(FILTER_APPLIED, Boolean.TRUE);

        String bot = BotChecker.isBot((HttpServletRequest) request);

        if (bot != null && log.isInfoEnabled()) {
            log.info("Found a bot: " + bot);
        }

        request.setAttribute(ConfigKeys.IS_BOT, new Boolean(bot != null));
    }

    // Pass the request on
    chain.doFilter(request, response);
}

From source file:org.forgerock.openidm.jaspi.modules.IDMUserAuthModule.java

/**
 * Gets the client certificates from the request.
 *
 * @param request The ServletRequest.//ww w . j a v a 2 s. co m
 * @return An array of X509Certificates.
 */
// This is currently Jetty specific
private X509Certificate[] getClientCerts(ServletRequest request) {

    Object checkCerts = request.getAttribute("javax.servlet.request.X509Certificate");
    if (checkCerts instanceof X509Certificate[]) {
        return (X509Certificate[]) checkCerts;
    } else {
        logger.warn("Unknown certificate type retrieved {}", checkCerts);
        return null;
    }
}

From source file:org.grails.web.servlet.DefaultGrailsApplicationAttributes.java

private String getControllerName(ServletRequest request) {
    String controllerName = (String) request
            .getAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE);
    if (controllerName == null || controllerName.length() == 0) {
        GroovyObject controller = getController(request);
        if (controller != null) {
            controllerName = (String) controller.getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY);
            request.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE, controllerName);
            if (controller instanceof GrailsControllerClass) {
                String namespace = ((GrailsControllerClass) controller).getNamespace();
                if (namespace != null) {
                    request.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAMESPACE_ATTRIBUTE, namespace);
                }/*from w ww  . jav a  2 s .co m*/
            }

        }
    }
    return controllerName != null ? controllerName : "";
}