alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (StrutsOsgiListener.java)

This example Struts source code file (StrutsOsgiListener.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

apache, apache, exception, exception, felix, felix, felixosgihost, felixosgihost, osgi_host, servlet, servletcontext, servletcontextlistener, string, strutsexception, strutsosgilistener

The Struts StrutsOsgiListener.java source code

package org.apache.struts2.osgi;

import org.apache.struts2.StrutsException;

import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContext;

/**
 * ServletContextListener that starts Apache Felix
 */
public class StrutsOsgiListener implements ServletContextListener {
    public static final String OSGI_HOST = "__struts_osgi_host";
    private FelixOsgiHost osgiHost;

    public void contextInitialized(ServletContextEvent sce) {
        ServletContext servletContext = sce.getServletContext();
        osgiHost = new FelixOsgiHost();
        servletContext.setAttribute(OSGI_HOST, osgiHost);
        try {
            osgiHost.init(servletContext);
        } catch (Exception e) {
            throw new StrutsException("Apache Felix failed to start", e);
        }
    }

    public void contextDestroyed(ServletContextEvent sce) {
        try {
            osgiHost.destroy();
        } catch (Exception e) {
            throw new StrutsException("Apache Felix failed to stop", e);
        }
    }
}

Other Struts examples (source code examples)

Here is a short list of links related to this Struts StrutsOsgiListener.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.