struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: Using Struts2 OSGi plugin with GlassFish
Date Tue, 08 Jan 2013 19:30:52 GMT

The beauty of implementing a maven-plugin is that all attributes of the plugin are configurable

open struts2-osgi-plugin.jar
edit
.\META-INF\maven\plugin.xml
look for<bean name="osgi" type="com.opensymphony.xwork2.config.PackageProvider" class="org.apache.struts2.osgi.OsgiConfigurationProvider"
/>
as long as your com.opensymphony.xwork2.config.PackageProvider (felix provider) implements
interfacescom.opensymphony.xwork2.config.PackageProviderorg.osgi.framework.BundleListener


then substitute in the felix PackageProvider to class attribute at
<bean name="osgi" type="com.opensymphony.xwork2.config.PackageProvider" class="org.apache.struts2.osgi.OsgiConfigurationProvider"
/>
 save .\META-INF\maven\plugin.xml/close/rejar/place struts2-osgi-plugin.jar back into lib
folder (after saving original as struts2-osgi-plugin.jar.original) if you do not redirect
the PackageProvider this Struts-osgi-Listener will be called as seen here from Provider code
org.apache.struts2.osgi.OsgiConfigurationProvider

public class OsgiConfigurationProvider implements PackageProvider, BundleListener {
    private static final Logger LOG = LoggerFactory.getLogger(OsgiConfigurationProvider.class);

    private Configuration configuration;
    private ObjectFactory objectFactory;

    private OsgiHost osgiHost;
    private BundleContext bundleContext;
    private BundleAccessor bundleAccessor;
    private boolean bundlesChanged = false;
    private ServletContext servletContext;

    public void init(Configuration configuration) throws ConfigurationException {
        osgiHost = (OsgiHost) servletContext.getAttribute(StrutsOsgiListener.OSGI_HOST);
        bundleContext = osgiHost.getBundleContext();
        bundleAccessor.setBundleContext(bundleContext);
        bundleAccessor.setOsgiHost(osgiHost);
        this.configuration = configuration;

        //this class loader interface can be used by other plugins to lookup resources
        //from the bundles. A temporary class loader interface is set during other configuration
        //loading as well
        servletContext.setAttribute(ClassLoaderInterface.CLASS_LOADER_INTERFACE, new BundleClassLoaderInterface());
    }
where servletContext Listener is set to 
  org.apache.struts2.osgi.StrutsOsgiListener 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);
        }
    } org.apache.struts2.osgi.FelixOsgiHost init will be called
   public void init(ServletContext servletContext) {
        this.servletContext = servletContext;
        startFelix();
    }
  protected void startFelix() {
        //load properties from felix embedded file
        Properties configProps = getProperties("default.properties");        // Copy framework
properties from the system properties.
        Main.copySystemProperties(configProps);
        replaceSystemPackages(configProps);        //struts, xwork and felix exported packages
        Properties strutsConfigProps = getProperties("struts-osgi.properties");
        addExportedPackages(strutsConfigProps, configProps);        //find bundles and adde
em to autostart property
        addAutoStartBundles(configProps);        // Bundle cache
        String storageDir = System.getProperty("java.io.tmpdir") + ".felix-cache";
        configProps.setProperty(Constants.FRAMEWORK_STORAGE, storageDir);
        if (LOG.isDebugEnabled())
            LOG.debug("Storing bundles at [#0]", storageDir);        String cleanBundleCache
= getServletContextParam("struts.osgi.clearBundleCache", "true");
        if ("true".equalsIgnoreCase(cleanBundleCache)) {
            if (LOG.isDebugEnabled())
                LOG.debug("Clearing bundle cache");
            configProps.put(FelixConstants.FRAMEWORK_STORAGE_CLEAN, FelixConstants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
        }        //other properties
        configProps.put(FelixConstants.SERVICE_URLHANDLERS_PROP, "false");
        configProps.put(FelixConstants.LOG_LEVEL_PROP, getServletContextParam("struts.osgi.logLevel",
"1"));
        configProps.put(FelixConstants.BUNDLE_CLASSPATH, ".");
        configProps.put(FelixConstants.FRAMEWORK_BEGINNING_STARTLEVEL, getServletContextParam("struts.osgi.runLevel",
"3"));        try {
            List<BundleActivator> list = new ArrayList<BundleActivator>();
            list.add(new AutoActivator(configProps));
            configProps.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);          
 felix = new Felix(configProps);
            felix.start();
            if (LOG.isTraceEnabled())
                LOG.trace("Apache Felix is running");
        }
        catch (Exception ex) {
            throw new ConfigurationException("Couldn't start Apache Felix", ex);
        }
http://blogs.atlassian.com/2007/07/osgi_plugin_for_struts_2_lesso/
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.

 > Date: Tue, 8 Jan 2013 12:04:32 +0200
> From: christina.kaskoura@eurodyn.com
> To: user@struts.apache.org
> Subject: Using Struts2 OSGi plugin with GlassFish
> 
> Hello.
> 
> I am trying to use the Struts2 OSGi plugin and have tried creating a web 
> application containing the struts2-osgi-demo-bundle. All goes well when 
> deploying the application on Tomcat, however when I try deploying on 
> GlassFish (which has Felix included) I get a number of errors which I 
> understand are due to the fact that the plugin starts a new Felix 
> instance while another one is already running on GlassFish and that 
> certain Felix classes are present more than one times in the classpath 
> (one from the Felix jars included in the application as dependencies of 
> the plugin and one from the felix.jar already included in GlassFish). 
> More details on the actual errors are available in this stackoverflow 
> post - 
> http://stackoverflow.com/questions/14200300/using-struts2-osgi-plugin-with-glassfish.
> 
> My question is: is there any specific configuration I should make in 
> order to use the OSGi plugin in GlassFish (or any other container 
> including Felix for that matter)?
> 
> Thank you,
> Christina
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message