users@glassfish.java.net

Re: OSGI Web bundle

From: Pavel Kuzin <pk_at_nodex.ru>
Date: Wed, 21 Oct 2009 11:59:33 +0400

Hello!

I found one way to start my webapp with Spring OSGI references.

First i must to install hack to ContextLoaderListener that will set bundle for context.(in attachment).

Spring searching bundle context in "String BUNDLE_CONTEXT_ATTRIBUTE = "org.springframework.osgi.web." + BundleContext.class.getName();"
property.

And then i can initialise my webapp with Spring OSGI references.

/WEB-INF/applicationContext.xml must contain beans and osgi references.

Spring extender initialisation of bundle is not necessary, because all references and beans
is already started by osgi web container. Config files for Spring extender initialisation(/META-INF/spring/*.xml can be safely deleted
because they not needed any more.

Thank you for tip with ContextLoaderListener :-)

Sahoo пишет:
> Hi Pavel,
>
> I have changed OSGi Web Container in GlassFish to set osgi-bundlecontext
> attribute in ServletContext before the web app initialization event is
> fired [1], so hopefully Spring context listener can now function as long
> as it is looking for the attribute named osgi-bundlecontext. This
> attribute is named as per OSGi rfc #66.
>
> Thanks,
> Sahoo
>
> [1] https://glassfish.dev.java.net/issues/show_bug.cgi?id=10439
>
> Pavel Kuzin wrote:
>> Hello!
>>
>> In this time glassfish do this:
>>
>>
>> 1. Catching new bundle by autodeploy (autodeploy/bundles)
>> INFO: Installed
>> /usr/local/glassfish/glassfish/domains/domain1/autodeploy/bundles/RemotePayments-0.0.2.jar
>>
>> 2. Resolving it. -> RESOLVED STATE
>> 3. bundle->start -> STARTING STATE
>> 4. osgi-web-container installing webapp to container and tries
>> initialise ServletContext.
>> Webapp initialise Spring WebApplication context without OSGI.
>> 5. get error because webapp needs OsgiBundleXmlWebApplicationContext
>> java.lang.Exception: java.lang.IllegalStateException:
>> ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
>> java.lang.IllegalArgumentException: bundle context should be set
>> before refreshing the application context
>> at
>> com.sun.enterprise.web.WebApplication.start(WebApplication.java:118)
>> at
>> org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
>> at
>> org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:219)
>> at
>> org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:240)
>>
>> at
>> com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:308)
>>
>> at
>> com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:169)
>>
>> at
>> org.glassfish.web.osgi.JavaEEDeploymentRequest.deploy(JavaEEDeploymentRequest.java:167)
>>
>> at
>> org.glassfish.web.osgi.JavaEEDeploymentRequest.execute(JavaEEDeploymentRequest.java:119)
>>
>> at
>> org.glassfish.web.osgi.OSGiWebContainer.deployJavaEEArtifacts(OSGiWebContainer.java:141)
>>
>> at
>> org.glassfish.web.osgi.OSGiWebContainer.deploy(OSGiWebContainer.java:106)
>> at
>> org.glassfish.web.osgi.WebExtender.deploy(WebExtender.java:158)
>> at
>> org.glassfish.web.osgi.WebExtender.bundleChanged(WebExtender.java:110)
>> at
>> org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:919)
>>
>> at
>> org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
>>
>> at
>> org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
>>
>> at
>> org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1350)
>>
>> at
>> org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1301)
>>
>> at
>> org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:338)
>>
>> at
>> org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
>>
>> at
>> org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
>>
>> at
>> org.apache.felix.fileinstall.DirectoryWatcher.start(DirectoryWatcher.java:823)
>>
>> at
>> org.apache.felix.fileinstall.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:844)
>>
>> at
>> org.apache.felix.fileinstall.DirectoryWatcher.doInstalled(DirectoryWatcher.java:401)
>>
>> at
>> org.apache.felix.fileinstall.DirectoryWatcher.run(DirectoryWatcher.java:123)
>>
>>
>> 6. bundle goes to STARTED STATE
>> 7. extender starts Spring and OsgiBundleXmlApplicationContext
>> INFO: Application context successfully refreshed
>> (OsgiBundleXmlApplicationContext(bundle=ndx.billing.RemotePayments,
>> config=osgibundle:/META-INF/spring/*.xml))
>>
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>

-- 
Pavel D. Kuzin
pk_at_nodex.ru
Nodex LTD.
Saint-Petersburg, Russia