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.mtgi.analytics.servlet.BehaviorTrackingListener.java

public void requestDestroyed(ServletRequestEvent event) {
    if (adapters != null) {
        ServletRequest request = event.getServletRequest();
        BehaviorEvent[] events = (BehaviorEvent[]) request.getAttribute(ATT_EVENTS);
        if (events == null) {
            log.error("no behavior events stored in the current request ("
                    + ((HttpServletRequest) request).getRequestURI());
        } else {//from  w  ww .j  a  v a2s. com
            request.removeAttribute(ATT_EVENTS);
            for (int i = adapters.length - 1; i >= 0; --i)
                try {
                    adapters[i].stop(events[i]);
                } catch (Exception e) {
                    log.error("Error stopping http event", e);
                }
        }
    }
}

From source file:org.opencms.util.CmsRequestUtil.java

/**
 * Returns a map with all request attributes.<p>
 * /*from   w  ww. j  ava  2 s.  com*/
 * @param req the request
 * 
 * @return the attribute map
 */
public static Map<String, Object> getAtrributeMap(ServletRequest req) {

    if (req instanceof CmsFlexRequest) {
        return ((CmsFlexRequest) req).getAttributeMap();
    }
    Map<String, Object> attrs = new HashMap<String, Object>();
    Enumeration<String> atrrEnum = CmsCollectionsGenericWrapper.enumeration(req.getAttributeNames());
    while (atrrEnum.hasMoreElements()) {
        String key = atrrEnum.nextElement();
        Object value = req.getAttribute(key);
        attrs.put(key, value);
    }
    return attrs;
}

From source file:com.ace.erp.filter.user.SysUserFilter.java

@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
        throws Exception {
    User user = (User) request.getAttribute(Constants.CURRENT_USER);
    if (user == null) {
        return true;
    }/*  www.  j  a  v  a  2  s  .  com*/

    if (Boolean.TRUE.equals(user.getDeleted()) || user.getStatus() == UserStatus.blocked) {
        getSubject(request, response).logout();
        saveRequestAndRedirectToLogin(request, response);
        return false;
    }
    return true;
}

From source file:org.ambraproject.admin.filter.RedirectToAmbraFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String currentJournal = ((VirtualJournalContext) request
            .getAttribute(VirtualJournalContext.PUB_VIRTUALJOURNAL_CONTEXT)).getJournal();
    String journalURL = journalUrls.get(currentJournal);
    if (journalURL == null) {
        journalURL = defaultJournalUrl;//w ww.  j a v a  2s. c  om
    }

    String requestUri = ((HttpServletRequest) request).getRequestURI();
    String queryString = ((HttpServletRequest) request).getQueryString();
    //the context of the admin app, which we want to replace
    String currentContext = ((HttpServletRequest) request).getContextPath();
    String redirectUrl = journalURL + '/' + requestUri.replaceFirst(currentContext + '/', "") + '?'
            + queryString;

    log.debug("Redirecting request for {} to {}", requestUri, redirectUrl);
    ((HttpServletResponse) response).sendRedirect(redirectUrl);
}

From source file:org.entando.entando.aps.tags.GuiFragmentTag.java

@Override
public int doStartTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    try {/*from ww  w  .  j  a v  a  2 s  .c om*/
        Object extractedValue = this.extractFragmentOutput(reqCtx);
        if (null == extractedValue) {
            _logger.info("The fragment '{}' is not available", this.getCode());
            extractedValue = "The fragment '" + this.getCode() + "' is not available";
        }
        if (this.getVar() != null) {
            this.pageContext.setAttribute(this.getVar(), extractedValue);
        } else {
            if (this.getEscapeXml()) {
                out(this.pageContext, this.getEscapeXml(), extractedValue);
            } else {
                this.pageContext.getOut().print(extractedValue);
            }
        }
    } catch (Throwable t) {
        _logger.error("error in doStartTag", t);
        throw new JspException("Error during tag initialization", t);
    }
    return super.doStartTag();
}

From source file:com.agiletec.plugins.jpcmstagcloud.aps.tags.TagCloudBuilderTag.java

private List<CloudInfoBean> buildCloudsInfoBeans(Map<ITreeNode, Integer> occurrences) throws Throwable {
    List<CloudInfoBean> beans = new ArrayList<CloudInfoBean>();
    try {//from w ww .j ava2  s . c om
        ServletRequest request = this.pageContext.getRequest();
        RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        int[] minMax = this.extractMinMax(occurrences);
        int interval = (minMax[1] - minMax[0]);
        double delta = ((double) interval) / 9d;
        Iterator<ITreeNode> iter = occurrences.keySet().iterator();
        while (iter.hasNext()) {
            ITreeNode treeNode = iter.next();
            int occurrence = occurrences.get(treeNode).intValue();
            double position = ((double) (occurrence - minMax[0])) / delta;
            long positionInt = Math.round(position);
            String classId = String.valueOf(((int) positionInt + 1));
            CloudInfoBean bean = new CloudInfoBean(treeNode, occurrence, classId, currentLang);
            beans.add(bean);
        }
        BeanComparator comparator = new BeanComparator("title");
        Collections.sort(beans, comparator);
    } catch (Throwable t) {
        _logger.error("Error building Cloud info", t);
        throw new ApsSystemException("Error building Cloud info", t);
    }
    return beans;
}

From source file:org.ops4j.gaderian.servlet.GaderianFilter.java

private synchronized void checkRegistryRebuild(ServletRequest request) {
    if (request.getAttribute(REBUILD_REQUEST_KEY) == null)
        return;//from   w  w w. j a  v  a2 s .c om

    Registry oldRegistry = _registry;

    // Replace the old Registry with a new one. All other threads, but this
    // one, will begin using the new Registry. Hopefully, we didn't get
    // rebuild requests on multiple threads.

    initializeRegistry();

    // Shutdown the old Registry. Perhaps we should sleep for a moment, first,
    // to help ensure that other threads have "cleared out". If not, we'll see some
    // instability at the instant we shutdown (i.e., all the proxies will get disabled).
    // Alternately, we should create a WeakReference based monitor that shuts down the
    // old registry when it is no longer used by any other threads. For the moment,
    // this functionality is limited to development-time only (not production), so it isn't
    // urgent.

    oldRegistry.shutdown();
}

From source file:org.seasar.teeda.extension.filter.MultipartFormDataFilter.java

public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    if (request.getAttribute(DOFILTER_CALLED) != null) {
        chain.doFilter(request, response);
        return;// ww w  .  j  a v  a  2 s  .  com
    }
    request.setAttribute(DOFILTER_CALLED, "true");

    if (!(response instanceof HttpServletResponse)) {
        chain.doFilter(request, response);
        return;
    }

    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    if (!ServletFileUpload.isMultipartContent(httpRequest)) {
        chain.doFilter(request, response);
        return;
    }

    final HttpServletRequest multipartRequest = new MultipartFormDataRequestWrapper(httpRequest, maxSize,
            maxFileSize, thresholdSize, repositoryPath);
    chain.doFilter(multipartRequest, response);
}

From source file:com.agiletec.plugins.jpblog.aps.tags.BlogCategoryTag.java

private List<CategoryInfoBean> buildCategoryInfoBeanList(Map<Category, Integer> occurrences) throws Throwable {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    List<CategoryInfoBean> beans = new ArrayList<CategoryInfoBean>();
    try {/*from   w w  w. j  a  va 2  s. c  o  m*/
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        Iterator<Category> iter = occurrences.keySet().iterator();
        while (iter.hasNext()) {
            Category treeNode = iter.next();
            beans.add(new CategoryInfoBean(treeNode, currentLang.getCode(), occurrences.get(treeNode)));
        }
        BeanComparator comparator = new BeanComparator("title");
        Collections.sort(beans, comparator);
    } catch (Throwable t) {
        _logger.error("error in Error building buildCategoryInfoBeanList", t);
        throw new ApsSystemException("Error building buildCategoryInfoBeanList ", t);
    }
    return beans;
}

From source file:com.agiletec.plugins.jpblog.aps.tags.BlogCategoryTag.java

@Override
public int doEndTag() throws JspException {
    ServletRequest request = this.pageContext.getRequest();
    RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
    IBlogManager blogManager = (IBlogManager) ApsWebApplicationUtils.getBean(JpblogSystemConstants.BLOG_MANAGER,
            this.pageContext);
    try {//  w w  w  .  ja v a 2s  . co  m
        if (null == this.getTypeCode())
            this.setTypeCode(this.extractContentType());
        List<String> userGroupCodes = new ArrayList<String>(this.getAllowedGroups(reqCtx));
        //List<String> facetNodeCodes = blogManager.getSpecialCategories();
        List<String> contentTypeCodes = new ArrayList<String>();
        contentTypeCodes.add(this.getTypeCode());

        Map<Category, Integer> blogCategories = blogManager.getOccurrences(contentTypeCodes, userGroupCodes);
        //this.pageContext.setAttribute(this.getVar(), blogCategories);
        this.pageContext.setAttribute(this.getVar(), this.buildCategoryInfoBeanList(blogCategories));
    } catch (Throwable t) {
        _logger.error("error in doEndTag", t);
        throw new JspException("Error closing tag ", t);
    }
    this.release();
    return EVAL_PAGE;
}