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:gov.nih.nci.ispy.web.taglib.CatCorrPlotTag.java

public int doStartTag() {

    ServletRequest request = pageContext.getRequest();
    HttpSession session = pageContext.getSession();
    Object o = request.getAttribute(beanName);
    JspWriter out = pageContext.getOut();
    ServletResponse response = pageContext.getResponse();

    ISPYCategoricalCorrelationFinding corrFinding = (ISPYCategoricalCorrelationFinding) businessTierCache
            .getSessionFinding(session.getId(), taskId);

    try {/*from   w  w  w  .  ja v a  2 s . c o m*/
        List<DataPointVector> dataSet = corrFinding.getDataVectors();
        List<ReporterInfo> reporterInfoList = corrFinding.getCatCorrRequest().getReporters();

        //get better labels for X and Y axis.
        ContinuousType ct = corrFinding.getContType();
        String xLabel, yLabel;
        if (ct == ContinuousType.GENE) {
            yLabel = "Log base 2 expression value";
        } else {
            yLabel = ct.toString();
        }

        //if there are reporters involved then send them in so that they can be used to create
        //a series.

        ISPYCategoricalCorrelationPlot plot = new ISPYCategoricalCorrelationPlot(dataSet, reporterInfoList,
                "Category", yLabel, corrFinding.getContType(), ColorByType.CLINICALRESPONSE);

        chart = plot.getChart();
        ISPYImageFileHandler imageHandler = new ISPYImageFileHandler(session.getId(), "png", 650, 600);
        //The final complete path to be used by the webapplication
        String finalPath = imageHandler.getSessionTempFolder();
        String finalURLpath = imageHandler.getFinalURLPath();
        /*
         * Create the actual charts, writing it to the session temp folder
        */
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        String mapName = imageHandler.createUniqueMapName();
        //PrintWriter writer = new PrintWriter(new FileWriter(mapName));
        ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info);
        //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true);
        //writer.close();

        /*   This is here to put the thread into a loop while it waits for the
         *   image to be available.  It has an unsophisticated timer but at 
         *   least it is something to avoid an endless loop.
         **/
        boolean imageReady = false;
        int timeout = 1000;
        FileInputStream inputStream = null;
        while (!imageReady) {
            timeout--;
            try {
                inputStream = new FileInputStream(finalPath);
                inputStream.available();
                imageReady = true;
                inputStream.close();
            } catch (IOException ioe) {
                imageReady = false;
                if (inputStream != null) {
                    inputStream.close();
                }
            }
            if (timeout <= 1) {

                break;
            }
        }

        out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, true, info));
        finalURLpath = finalURLpath.replace("\\", "/");
        long randomness = System.currentTimeMillis(); //prevent image caching
        out.print("<img id=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness
                + "\" usemap=\"#" + mapName + "\" border=\"0\" />");

        //(imageHandler.getImageTag(mapFileName));

    } catch (IOException e) {
        logger.error(e);
    } catch (Exception e) {
        logger.error(e);
    } catch (Throwable t) {
        logger.error(t);
    }

    return EVAL_BODY_INCLUDE;
}

From source file:de.itsvs.cwtrpc.controller.CacheControlFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    /* filter must not be applied on an internal forward or on error */
    if (request.getAttribute(PROCESSED_ALREADY_ATTR_NAME) == null) {
        final PreparedCacheControlUriConfig uriConfig;

        uriConfig = getPreparedUriConfig((HttpServletRequest) request);
        if (uriConfig != null) {
            addHeaders((HttpServletResponse) response, uriConfig);
        }/*from  w w w .  j  a  va 2 s .  com*/

        request.setAttribute(PROCESSED_ALREADY_ATTR_NAME, Boolean.TRUE);
    }

    chain.doFilter(request, response);
}

From source file:jp.terasoluna.fw.web.thin.ServerBlockageControlFilter.java

/**
 * T?[o?`FbN?s?B/*ww  w.j  ava  2s.co m*/
 * 
 * @param req
 *            HTTPNGXg
 * @param res
 *            HTTPX|X
 * @param chain
 *            tB^`F?[
 * @throws IOException
 *             I/OG?[
 * @throws ServletException
 *             T?[ubgO
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *                                    javax.servlet.ServletResponse,
 *                                    javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    // NGXgtB^?B
    if (req.getAttribute(SERVER_BLOCKAGE_THRU_KEY) == null) {

        // tB^?Zbg
        req.setAttribute(SERVER_BLOCKAGE_THRU_KEY, "true");

        // T?[o?`FbN
        if (controller.isBlockaded(RequestUtil.getPathInfo(req))) {
            if (log.isDebugEnabled()) {
                log.debug("isBlockaded() failed.");
            }
            throw new ServerBlockageException();
        }
    }

    // tB^T?[ubg
    chain.doFilter(req, res);
}

From source file:org.jenkinsci.plugins.certificate_auth.CertificateSecurityRealm.java

@Override
public Filter createFilter(FilterConfig filterConfig) {
    return new Filter() {
        public void init(FilterConfig filterConfig) throws ServletException {
        }/*w w w  .  j a  v a  2s  . c o m*/

        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException {
            HttpServletRequest r = (HttpServletRequest) request;
            final X509Certificate[] certChain = (X509Certificate[]) request
                    .getAttribute("javax.servlet.request.X509Certificate");

            Authentication a;
            if (certChain == null || certChain[0] == null) {
                a = Hudson.ANONYMOUS;
            } else {

                final String dn = certChain[0].getSubjectDN().getName();

                final String username = dn.split(getUserField() + "=")[1].split(",")[0];
                final String group = dn.split(getGroupField() + "=")[1].split(",")[0];

                GrantedAuthority[] authorities = new GrantedAuthority[] { SecurityRealm.AUTHENTICATED_AUTHORITY,
                        new GrantedAuthorityImpl(group) };

                a = new UsernamePasswordAuthenticationToken(username, "", authorities);
            }

            SecurityContextHolder.getContext().setAuthentication(a);

            chain.doFilter(request, response);
        }

        public void destroy() {
        }
    };
}

From source file:jp.terasoluna.fw.web.thin.ExtensionFilter.java

/**
 * gq`FbN?s?B// ww  w.ja v  a  2 s  .c  o m
 *
 * @param req HTTPNGXg
 * @param res HTTPX|X
 * @param chain tB^`F?[
 * 
 * @throws IOException I/OG?[
 * @throws ServletException T?[ubgO
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    //NGXgtB^?B
    if (req.getAttribute(EXTENSION_THRU_KEY) == null) {

        //tB^?Zbg
        req.setAttribute(EXTENSION_THRU_KEY, "true");

        //NGXgpXgq`FbN?spXXg
        //v?????I
        String pathInfo = RequestUtil.getPathInfo(req);
        if (pathInfo != null && !restrictionEscapePaths.contains(pathInfo)) {

            //gq`FbN?s
            //NGXgpXgq?B
            String extension = StringUtil.getExtension(pathInfo);
            if (prohibitedExtensionList.contains(extension)) {

                if (log.isDebugEnabled()) {
                    log.debug("requestURI[" + pathInfo + "] has prohibited extension");
                }

                // HTTPG?[404
                ((HttpServletResponse) res).sendError(HttpServletResponse.SC_NOT_FOUND);
                return; // ?~?s
            }
        }
    }

    // tB^T?[ubg
    chain.doFilter(req, res);
}

From source file:jp.terasoluna.fw.web.thin.AuthorizationControlFilter.java

/**
 * ANZX`FbN?s?B/*  ww w  .j  av a 2s.  c  o  m*/
 * 
 * @param req HTTPNGXg
 * @param res HTTPX|X
 * @param chain tB^`F?[
 * 
 * @throws IOException I/OG?[
 * @throws ServletException T?[ubgO
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, 
 *                                    javax.servlet.ServletResponse,
 *                                    javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    // NGXgtB^?B
    if (req.getAttribute(AUTHORIZATION_THRU_KEY) == null) {

        // tB^?Zbg
        req.setAttribute(AUTHORIZATION_THRU_KEY, "true");

        // pX`FbN?B
        if (controller.isCheckRequired(req)) {

            // ANZX`FbN
            if (!controller.isAuthorized(RequestUtil.getPathInfo(req), req)) {
                if (log.isDebugEnabled()) {
                    log.debug("isAuthorized() failed.");
                }
                throw new UnauthorizedException();
            }
        }
    }

    // tB^T?[ubg
    chain.doFilter(req, res);
}

From source file:com.adobe.acs.commons.wcm.impl.ComponentErrorHandlerImpl.java

private boolean isComponentErrorHandlingSuppressed(final ServletRequest request) {
    final Boolean suppress = (Boolean) request.getAttribute(SUPPRESS_ATTR);

    if (suppress != null) {
        return suppress.booleanValue();
    } else {/* w w  w  .ja v  a2s  . c  om*/
        return false;
    }
}

From source file:jp.terasoluna.fw.web.thin.AuthenticationControlFilter.java

/**
 * ?OI?`FbN?s?B// w  w w  .  j a  va 2  s  .  com
 * 
 * @param req HTTPNGXg
 * @param res HTTPX|X
 * @param chain tB^`F?[
 * 
 * @throws IOException I/OG?[
 * @throws ServletException T?[ubgO
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *                                    javax.servlet.ServletResponse,
 *                                    javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    // NGXgtB^?B
    if (req.getAttribute(AUTHENTICATION_THRU_KEY) == null) {

        // tB^?Zbg
        req.setAttribute(AUTHENTICATION_THRU_KEY, "true");

        // pX`FbN?B
        if (controller.isCheckRequired(req)) {

            // ?OI?`FbN
            if (!controller.isAuthenticated(RequestUtil.getPathInfo(req), req)) {
                if (log.isDebugEnabled()) {
                    log.debug("isAuthenticated() failed.");
                }
                throw new UnauthenticatedException();
            }
        }
    }

    // tB^T?[ubg
    chain.doFilter(req, res);
}

From source file:jp.terasoluna.fw.web.thin.BlockageControlFilter.java

/**
 * ?`FbN?s?B// w ww .  j a v  a 2s  .  co  m
 *
 * @param req HTTPNGXg
 * @param res HTTPX|X
 * @param chain tB^`F?[
 *
 * @throws IOException I/OG?[
 * @throws ServletException T?[ubgO
 *
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    // NGXgtB^?B
    if (req.getAttribute(BLOCKAGE_THRU_KEY) == null) {

        // tB^?Zbg
        req.setAttribute(BLOCKAGE_THRU_KEY, "true");

        if (controller.isCheckRequired(req)) {
            // ?`FbN
            if (controller.isBlockaded(RequestUtil.getPathInfo(req), req)) {
                if (log.isDebugEnabled()) {
                    log.debug("isBlockaded() failed.");
                }
                throw new BlockageException();
            }
        }
    }

    // tB^T?[ubg
    chain.doFilter(req, res);

}

From source file:edu.cornell.mannlib.vitro.webapp.filters.WebappDaoFactorySparqlPrep.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    if (request.getAttribute("WebappDaoFactorySDBPrep.setup") != null) {
        // don't run multiple times
        filterChain.doFilter(request, response);
        return;/*  w w w.  ja  v  a2  s.com*/
    }

    for (Pattern skipPattern : skipPatterns) {
        Matcher match = skipPattern.matcher(((HttpServletRequest) request).getRequestURI());
        if (match.matches()) {
            log.debug("request matched a skipPattern, skipping VitroRequestPrep");
            filterChain.doFilter(request, response);
            return;
        }
    }

    javax.sql.DataSource ds = JenaDataSourceSetupBase.getApplicationDataSource(_ctx);
    StoreDesc storeDesc = (StoreDesc) _ctx.getAttribute("storeDesc");
    OntModelSelector oms = (OntModelSelector) _ctx.getAttribute("unionOntModelSelector");
    String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace");
    Connection sqlConn = null;
    SDBConnection conn = null;
    Store store = null;
    Dataset dataset = null;
    WebappDaoFactory wadf = null;

    try {
        if (ds == null || storeDesc == null || oms == null) {
            throw new RuntimeException("SDB store not property set up");
        }

        try {
            sqlConn = ds.getConnection();
            conn = new SDBConnection(sqlConn);
        } catch (SQLException sqe) {
            throw new RuntimeException("Unable to connect to database", sqe);
        }
        if (conn != null) {
            store = SDBFactory.connectStore(conn, storeDesc);
            dataset = SDBFactory.connectDataset(store);
            VitroRequest vreq = new VitroRequest((HttpServletRequest) request);

            log.info("---------");

            Enumeration<String> headStrs = vreq.getHeaderNames();
            while (headStrs.hasMoreElements()) {
                String head = headStrs.nextElement();
                log.info(head + " : " + vreq.getHeader(head));
            }

            List<String> langs = new ArrayList<String>();

            log.info("Accept-Language: " + vreq.getHeader("Accept-Language"));
            Enumeration<Locale> locs = vreq.getLocales();
            while (locs.hasMoreElements()) {
                Locale locale = locs.nextElement();
                langs.add(locale.toString().replace("_", "-"));
                log.info(locale.toString() + " / " + locale.getLanguage() + " + " + locale.getCountry() + " : "
                        + locale.getDisplayCountry() + " | " + locale.getLanguage() + " : "
                        + locale.getDisplayLanguage());
            }
            WebappDaoFactoryConfig config = new WebappDaoFactoryConfig();
            config.setDefaultNamespace(defaultNamespace);
            config.setPreferredLanguages(langs);

            //okay let's make a graph-backed model
            String endpointURI = ConfigurationProperties.getBean(request)
                    .getProperty("VitroConnection.DataSource.endpointURI");

            Graph g = new SparqlGraphMultilingual(endpointURI, langs);
            //Graph g = new SparqlGraph(endpointURI);

            Model m = ModelFactory.createModelForGraph(g);
            OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, m);
            oms = new SingleContentOntModelSelector(om, oms.getDisplayModel(), oms.getUserAccountsModel());

            dataset = DatasetFactory.create(new SparqlDatasetGraph(endpointURI));

            //DataSource datasource = DatasetFactory.create();
            //datasource.addNamedModel("fake:fake", m);
            //dataset = datasource;         

            vreq.setAssertionsWebappDaoFactory(wadf);

            wadf = new WebappDaoFactoryJena(oms, config);
            //wadf = new WebappDaoFactorySDB(oms, dataset, config);
            vreq.setWebappDaoFactory(wadf);
            vreq.setFullWebappDaoFactory(wadf);
            vreq.setUnfilteredWebappDaoFactory(wadf);
            vreq.setWebappDaoFactory(wadf);
            vreq.setDataset(dataset);
            vreq.setJenaOntModel(om);
            vreq.setOntModelSelector(oms);
        }
    } catch (Throwable t) {
        log.error("Unable to filter request to set up SDB connection", t);
    }

    request.setAttribute("WebappDaoFactorySDBPrep.setup", 1);

    try {
        filterChain.doFilter(request, response);
        return;
    } finally {
        if (conn != null) {
            conn.close();
        }
        if (dataset != null) {
            dataset.close();
        }
        if (store != null) {
            store.close();
        }
        if (wadf != null) {
            wadf.close();
        }
    }

}