users@glassfish.java.net

Re: Using Struts2 OSGi plugin with GlassFish

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Thu, 10 Jan 2013 09:45:59 +0530

I have responded to stackoverflow thread to avoid cross-posting.

Sahoo

On Thursday 10 January 2013 04:45 AM, Martin Gainty wrote:
> correct
>
> yes for all intents and purposes struts-osgi-plugin *is* a functional
> struts plugin
>
> in order to interface to maven (plexus framework) we'll need to
>
> 1) port these attributes to \META-INF\maven\plugin.xml
>
> <constant name="struts.objectFactory" value="osgi" />
>
> <constant name="struts.objectFactory.delegate" value="struts" />
>
> <constant name="struts.freemarker.manager.classname"
> value="org.apache.struts2.osgi.BundleFreemarkerManager" />
> <!-- TBD: which FreemarkerManager to use with Maven 3.x -->
>
> <constant name="struts.staticContentLoader"
>
> value="org.apache.struts2.osgi.loaders.StaticContentBundleResourceLoader"
> />
> <!-- TBD: which StaticContentBundleResourceLoader to use with Maven
> 3.x -->
>
> <constant name="struts.convention.action.includeJars"
> value="jar:file:.*?/bundles/.*?\.jar(!/)?" />
>
> 2) convert Struts methods for org.apache.struts2.osgi.OsgiUtil.java
> translateBundleURLToJarURL
> and or org.apache.struts2.osgi.interceptor.OsgiInterceptor intercept
> method to goal annotation which will extends AbstractMojo
> @goal build
> Struts2OSGIMojo extends org.apache.maven.plugin.AbstractMojo
> (execute method)
>
> 3)populate \META-INF\maven\plugin.xml
>
> so..in order to participate in maven lifecycle ...
>
> a)defaultGoal will be 'build'
>
> b)default binding will bind to 'package' phase
>
> community..what are we missing ?
>
> Martin
> ______________________________________________
> ...place long-winded disclaimer here...
>
> > Date: Wed, 9 Jan 2013 09:37:02 +0200
> > From: christina.kaskoura_at_eurodyn.com
> > To: mgainty_at_hotmail.com
> > CC: user_at_struts.apache.org; users_at_maven.apache.org
> > Subject: Re: Using Struts2 OSGi plugin with GlassFish
> >
> > Hi Martin.
> >
> > In struts2-osgi-plugin.jar there is no .\META-INF\maven\plugin.xml
> file.
> > I assume you mean the .\struts-plugin.xml file? Also if I understand
> > correctly there is no existing implementation of the PackageProvider
> > which can work with GlassFish, I will just have to implement my own, is
> > that right?
> >
> >
> > On 08/01/2013 21:30, Martin Gainty wrote:
> > > 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 interfaces
> > > com.opensymphony.xwork2.config.PackageProvider
> > > org.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_at_eurodyn.com
> > > > To: user_at_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_at_struts.apache.org
> > > > For additional commands, e-mail: user-help_at_struts.apache.org
> > > >
> >