Example usage for javax.servlet ServletContext setAttribute

List of usage examples for javax.servlet ServletContext setAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletContext setAttribute.

Prototype

public void setAttribute(String name, Object object);

Source Link

Document

Binds an object to a given attribute name in this ServletContext.

Usage

From source file:org.apache.openejb.arquillian.tests.listenerenventry.PojoServletContextListener.java

public void contextInitialized(ServletContextEvent event) {
    final String name = "OpenEJB";
    final ServletContext context = event.getServletContext();

    if (car != null) {
        context.setAttribute(ContextAttributeName.KEY_Car.name(), car.drive(name));
    }//  w  w w . j a  v  a  2  s . c o m
    if (localCompany != null) {
        context.setAttribute(ContextAttributeName.KEY_LocalEjb.name(), "Local: " + localCompany.employ(name));
    }
    if (market != null) {
        context.setAttribute(ContextAttributeName.KEY_Market.name(), market.shop(name));
    }
    if (connectionPool != null) {
        context.setAttribute(ContextAttributeName.KEY_ConnPool.name(), "Connection Pool: " + connectionPool);
    }
    if (startCount != null) {
        context.setAttribute(ContextAttributeName.KEY_StartCount.name(),
                "Start Expressions.Count: " + startCount);
    }
    if (initSize != null) {
        context.setAttribute(ContextAttributeName.KEY_InitSize.name(), "Init Size: " + initSize);
    }
    if (totalQuantity != null) {
        context.setAttribute(ContextAttributeName.KEY_TotalQuantity.name(), "Total Quantity: " + totalQuantity);
    }
    if (enableEmail != null) {
        context.setAttribute(ContextAttributeName.KEY_EnableEmail.name(), "Enable Email: " + enableEmail);
    }
    if (optionDefault != null) {
        context.setAttribute(ContextAttributeName.KEY_DefaultOption.name(), "Option Default: " + optionDefault);
    }
    if (StringUtils.isNotEmpty(returnEmail) && returnEmail.equals("tomee@apache.org")) {
        context.setAttribute(ContextAttributeName.KEY_ReturnEmail.name(), returnEmail);
    }
    if (auditWriter != null) {
        context.setAttribute(ContextAttributeName.KEY_AuditWriter.name(), auditWriter.getClass().getName());
    }
    if (defaultCode != null) {
        context.setAttribute(ContextAttributeName.KEY_DefaultCode.name(), "DefaultCode: " + defaultCode);
    }
}

From source file:be.fedict.eid.dss.ws.ServiceConsumerServletContextListener.java

public void contextInitialized(ServletContextEvent event) {

    LOG.debug("context initialized");
    ServletContext servletContext = event.getServletContext();

    LOG.debug("SignatureVerificationService ref available: " + (null != this.signatureVerificationService));
    servletContext.setAttribute(SignatureVerificationService.class.getName(),
            this.signatureVerificationService);

    LOG.debug("DocumentService ref available: " + (null != this.documentService));
    servletContext.setAttribute(DocumentService.class.getName(), this.documentService);
}

From source file:com.socialsite.util.SpringWicketTester.java

/**
 * Create the new ServletContext that will be used with this test session.
 * This method configures the spring web context to be included in your
 * Servlet context. It's the magic that makes everything happy.
 * /*  w w  w. j  av a  2  s  .c om*/
 * @param path
 *            the root context path for URLs
 * 
 * @return a configured ServletContext
 */
@Override
public ServletContext newServletContext(final String path) {
    final ServletContext context = new MockServletContext(getApplication(), path);
    getSpringContext().setServletContext(context);
    context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, spring);
    return context;
}

From source file:org.apache.struts.tiles.TilesUtilImpl.java

/**
 * Make definition factory accessible to Tags.
 * Factory is stored in servlet context.
 * @param factory Factory to be made accessible.
 * @param servletContext Current servlet context.
 *///w  w  w  .  j  ava2  s. c  om
protected void makeDefinitionsFactoryAccessible(DefinitionsFactory factory, ServletContext servletContext) {

    servletContext.setAttribute(DEFINITIONS_FACTORY, factory);
}

From source file:com.openkm.servlet.admin.LogCatServlet.java

/**
 * View log//from   w ww.j a v a 2s  .c  o m
 */
private void view(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("view({}, {})", request, response);
    int begin = WebUtils.getInt(request, "begin");
    int end = WebUtils.getInt(request, "end");
    String str = WebUtils.getString(request, "str");
    String file = WebUtils.getString(request, "file");
    ServletContext sc = getServletContext();
    File lf = new File(logFolder, file);
    sc.setAttribute("file", file);
    sc.setAttribute("begin", begin);
    sc.setAttribute("end", end);
    sc.setAttribute("str", str);
    sc.setAttribute("messages", FormatUtil.parseLog(lf, begin, end, str));
    sc.getRequestDispatcher("/admin/logcat_view.jsp").forward(request, response);

    // Activity log
    UserActivity.log(request.getRemoteUser(), "ADMIN_LOGCAT_VIEW", file, null, str);

    log.debug("view: void");
}

From source file:org.echocat.nodoodle.server.HttpServer.java

@Override
public void afterPropertiesSet() throws Exception {
    if (_applicationContext == null) {
        throw new IllegalStateException("No applicationContext property set.");
    }//w w w.  java2  s.c o m
    if (CollectionUtils.isEmpty(_connectors)) {
        throw new IllegalStateException("No connectors property with connectors set.");
    }
    if (CollectionUtils.isEmpty(_contexts)) {
        throw new IllegalStateException("No contexts property with connectors set.");
    }
    if (_jettyServer == null) {
        final Server server = new Server();
        for (HttpConnector httpConnector : _connectors) {
            final Connector jettyConnector = httpConnector.createJettyConnector();
            server.addConnector(jettyConnector);
        }

        final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();
        for (Context<HttpService> httpContext : _contexts) {
            final String path = httpContext.getPath();
            final HttpService service = httpContext.getService();
            if (isEmpty(path)) {
                throw new IllegalArgumentException(
                        "The httpContext " + httpContext + " has no path configured.");
            }
            if (service == null) {
                throw new IllegalArgumentException(
                        "The httpContext " + httpContext + " has no service configured.");
            }
            final ContextHandler contextHandler = new ContextHandler(path);
            final ServletContext servletContext = contextHandler.getServletContext();
            servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
                    new DelegatingWebApplicationContext(_applicationContext, servletContext));
            service.init(servletContext);
            contextHandler.setHandler(new HandlerImpl(service));
            handlerCollection.addHandler(contextHandler);
        }
        server.setHandler(handlerCollection);

        server.start();
        _jettyServer = server;
    }
}

From source file:com.openkm.servlet.admin.PropertyGroupsServlet.java

/**
 * Edit property groups//from  w  w  w .  ja va  2  s  .c  om
 */
private void edit(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("edit({}, {})", new Object[] { request, response });

    if (WebUtils.getBoolean(request, "persist")) {
        String definition = request.getParameter("definition");
        FileUtils.writeStringToFile(new File(Config.PROPERTY_GROUPS_XML), definition, "UTF-8");

        // Activity log
        UserActivity.log(request.getRemoteUser(), "ADMIN_PROPERTY_GROUP_EDIT", null, null, null);
    } else {
        String xml = FileUtils.readFileToString(new File(Config.PROPERTY_GROUPS_XML), "UTF-8");
        ServletContext sc = getServletContext();
        sc.setAttribute("persist", true);
        sc.setAttribute("action", "edit");
        sc.setAttribute("definition", xml.replace("&", "&amp;"));
        sc.getRequestDispatcher("/admin/property_groups_edit.jsp").forward(request, response);
    }

    log.debug("edit: void");
}

From source file:be.fedict.eid.dss.webapp.StartupServletContextListener.java

private void initDocumentServices(ServletContextEvent event) {

    ServletContext servletContext = event.getServletContext();
    Map<String, String> documentServiceClassNames = this.servicesManager.getDocumentServiceClassNames();
    servletContext.setAttribute(DOCUMENT_SERVICES_CONTEXT_ATTRIBUTE, documentServiceClassNames);
}

From source file:com.ikon.servlet.admin.CssServlet.java

/**
 * List CSS//  w ww. ja va2  s .com
 */
private void list(String userId, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("list({}, {}, {})", new Object[] { userId, request, response });
    ServletContext sc = getServletContext();
    sc.setAttribute("cssList", CssDAO.getInstance().findAll());
    sc.getRequestDispatcher("/admin/css_list.jsp").forward(request, response);
    log.debug("list: void");
}

From source file:be.fedict.eid.dss.webapp.StartupServletContextListener.java

private void initProtocolServices(ServletContextEvent event) {

    /*/*  w w  w .j  ava 2  s.co  m*/
     * We once load the protocol services so we don't have to iterate over
     * all protocol descriptor files upon each DSS request.
     */
    ServletContext servletContext = event.getServletContext();
    Map<String, String> protocolServiceClassNames = this.servicesManager.getProtocolServiceClassNames();
    servletContext.setAttribute(PROTOCOL_SERVICES_CONTEXT_ATTRIBUTE, protocolServiceClassNames);
}