You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Evan Ruff <ev...@hendersonsawmill.com> on 2012/06/14 23:03:02 UTC

Getting Started with Felix/Jetty

Hey guys,

I'm just getting started with Felix and OSGi in general. I've
been cursing around trying to find some information about using Felix and
I've gotten stuck on the most trivial example! I think I must be missing
some sort of basic concept and I was hoping someone could tell me what I'm
doing wrong?

For a little background, I'm trying to migrate a web-app to a more modular,
OSGi based, installable application. I want to distribute my application
and currently, that requires the administrator to set up a Jetty server and
install my Webapp. I'd much rather have a single application that contains
it's own Jetty server and then have the web-apps and their supporting J2EE
pieces be installed as OSGi modules.

To start, I've created a new Java Project, added felix to the class path
and spun up the following main:
public static void main( String[] args ) throws BundleException
 {
FrameworkFactory frameworkFactory = ServiceLoader.load(
FrameworkFactory.class ).iterator().next();
 Map<String, String> config = new HashMap<String, String>();
Framework framework = frameworkFactory.newFramework( config );
 framework.start();
 BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();

installedBundles.add( context.installBundle(
"file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
 installedBundles.add( context.installBundle(
"file:lib/org.apache.felix.log-1.0.1.jar" ) );
 installedBundles.add( context.installBundle(
"file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );

for ( Bundle bundle : installedBundles )
{
 System.out.println( "Starting Bundle: " + bundle.getSymbolicName() );
bundle.start();
 }
}

Which I pulled out of a  tutorial about embedding Felix.

I'm running into trouble when I get to the HelloServlet bundle. The
HelloServlet bundle is the simpliest thing I could write based off of the
HelloOSGi tutorials that were around. It's a pretty basic Activator,
registering the servlet as described in the Felix docs:

public void start( BundleContext context ) throws Exception
{
 ServiceReference<HttpService> sRef = context.getServiceReference(
HttpService.class );
if (sRef != null)
 {
HttpService service = (HttpService) context.getService( sRef );
 service.registerServlet( "/hello", new HelloServlet(), null, null );
}
 }

The HelloServlet bundle has org.osgi.framework and org.osgi.service.http in
the "Import-Package" part of the manifest.

When I run everything, I get a "Unable to resolve 4.0: missing requirement
[4.0] osgi.wiring.package;
(&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))" exception
when starting the HelloServlet bundle. I assume this is because my Felix
container isn't registering th http-bundle properly.

How do I get this sort of thing to work in an embedded scenario like this?

FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"org.osgi.service.http; version=4.0.0" ); Iin there and, when that
happened, I was getting a NoClassDefFoundError NamespaceException, assuming
that it was looking for something other than the felix.http.bundle.

I really appreciate any help you guys can give me. Thanks!

E

Re: Getting Started with Felix/Jetty

Posted by Evan Ruff <ev...@hendersonsawmill.com>.
Achim,

Really appreciate the guidance. I'll take a look at Karaf immediately!

Thanks,

E

On Mon, Jun 18, 2012 at 7:16 AM, Achim Nierbeck <bc...@googlemail.com>wrote:

> Hi Evan,
>
> see my comments inline.
>
> regards, Achim
>
> 2012/6/15 Evan Ruff <ev...@hendersonsawmill.com>:
> > Guys,
> >
> > Thanks for the pointer to Pax Web. I've been looking over the
> documentation
> > and have a couple of questions:
> >
> > 1. is Pax-Web mainly just an extension of the OSGi HTTPService with
> awesome
> > Jetty connectivity?
>
> it's much more, it gives you the war-extender to deploy std. and/or
> osgi-fied wars.
> it does have a whitebaord-extender to publish all kinds of
> "Web-services" as Servlets,
> filters and jsps. And much more ...
>
> > 2. Can I configure multiple connectors? My application relies on SSL set
> up
> > using the embedded SslSocketConnector/SelectChannelConnector classes of
> > jetty.
>
> Yes this can be done. You have the ability to configure this through
> the configuration admin service.
> Another reason to take a look at Karaf, cause it will bring you all
> the needed parts out-of-the-box,
> and you are still able to "down-strip" it if you like.
>
> > 3. Can I harden it strictly for my application? I have some security
> > requirements that I need to be very careful with... mainly that would
> mean
> > insuring that there is not any external facing servlets other than mine
> > (aka, no admin) etc...
> >
>
> well right now Pax Web only gives you the possibility to deploy all kinds
> of
> web artefacts, either through std. OSGi Jars with Activator, through
> blueprint.xml definitions - using the whiteboard-pattern
> or by deploying either WARs with and without OSGi Manifests.
> What ever you deploy is up to you.
> So the hardening is mainly your part in either allowing or disallowing
> to install certain bundles
> after the system is up-to date.
>
> > What are the disadvantages of using embedded Felix? I assumed that it
> would
> > facilitate easier packaging and deployment, is that not true?
>
> I'm repeating myself, I suggest taking a look at Apache Karaf it uses
> Felix as the
> OSGi Framework and it'll give you a lot of other extra features that
> come very handy
> when migrating a application to the osgi world.
>
>
>
> >
> > Thanks,
> >
> > E
> >
> > On Fri, Jun 15, 2012 at 2:57 AM, Achim Nierbeck <bcanhome@googlemail.com
> >wrote:
> >
> >> And if you want to have some more stuff like JAAS or Logging out of
> >> the box working for you
> >> use Apache Karaf which uses Felix as the OSGi framework and brings
> >> along everything you need for Pax Web :)
> >>
> >> regards, Achim
> >>
> >> 2012/6/15 Allen Lau <al...@gmail.com>:
> >> > Unless you really need to embed Felix, why not run the Felix
> distribution
> >> > and add something like Pax-Web which embeds Jetty to be
> >> > your WAR/WAB web container?
> >> >
> >> > On Thu, Jun 14, 2012 at 2:03 PM, Evan Ruff
> >> > <ev...@hendersonsawmill.com>wrote:
> >> >
> >> >> Hey guys,
> >> >>
> >> >> I'm just getting started with Felix and OSGi in general. I've
> >> >> been cursing around trying to find some information about using Felix
> >> and
> >> >> I've gotten stuck on the most trivial example! I think I must be
> missing
> >> >> some sort of basic concept and I was hoping someone could tell me
> what
> >> I'm
> >> >> doing wrong?
> >> >>
> >> >> For a little background, I'm trying to migrate a web-app to a more
> >> modular,
> >> >> OSGi based, installable application. I want to distribute my
> application
> >> >> and currently, that requires the administrator to set up a Jetty
> server
> >> and
> >> >> install my Webapp. I'd much rather have a single application that
> >> contains
> >> >> it's own Jetty server and then have the web-apps and their supporting
> >> J2EE
> >> >> pieces be installed as OSGi modules.
> >> >>
> >> >> To start, I've created a new Java Project, added felix to the class
> path
> >> >> and spun up the following main:
> >> >> public static void main( String[] args ) throws BundleException
> >> >>  {
> >> >> FrameworkFactory frameworkFactory = ServiceLoader.load(
> >> >> FrameworkFactory.class ).iterator().next();
> >> >>  Map<String, String> config = new HashMap<String, String>();
> >> >> Framework framework = frameworkFactory.newFramework( config );
> >> >>  framework.start();
> >> >>  BundleContext context = framework.getBundleContext();
> >> >> List<Bundle> installedBundles = new LinkedList<Bundle>();
> >> >>
> >> >> installedBundles.add( context.installBundle(
> >> >> "file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
> >> >>  installedBundles.add( context.installBundle(
> >> >> "file:lib/org.apache.felix.log-1.0.1.jar" ) );
> >> >>  installedBundles.add( context.installBundle(
> >> >> "file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );
> >> >>
> >> >> for ( Bundle bundle : installedBundles )
> >> >> {
> >> >>  System.out.println( "Starting Bundle: " + bundle.getSymbolicName()
> );
> >> >> bundle.start();
> >> >>  }
> >> >> }
> >> >>
> >> >> Which I pulled out of a  tutorial about embedding Felix.
> >> >>
> >> >> I'm running into trouble when I get to the HelloServlet bundle. The
> >> >> HelloServlet bundle is the simpliest thing I could write based off of
> >> the
> >> >> HelloOSGi tutorials that were around. It's a pretty basic Activator,
> >> >> registering the servlet as described in the Felix docs:
> >> >>
> >> >> public void start( BundleContext context ) throws Exception
> >> >> {
> >> >>  ServiceReference<HttpService> sRef = context.getServiceReference(
> >> >> HttpService.class );
> >> >> if (sRef != null)
> >> >>  {
> >> >> HttpService service = (HttpService) context.getService( sRef );
> >> >>  service.registerServlet( "/hello", new HelloServlet(), null, null );
> >> >> }
> >> >>  }
> >> >>
> >> >> The HelloServlet bundle has org.osgi.framework and
> >> org.osgi.service.http in
> >> >> the "Import-Package" part of the manifest.
> >> >>
> >> >> When I run everything, I get a "Unable to resolve 4.0: missing
> >> requirement
> >> >> [4.0] osgi.wiring.package;
> >> >> (&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))"
> >> exception
> >> >> when starting the HelloServlet bundle. I assume this is because my
> Felix
> >> >> container isn't registering th http-bundle properly.
> >> >>
> >> >> How do I get this sort of thing to work in an embedded scenario like
> >> this?
> >> >>
> >> >> FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
> >> >> "org.osgi.service.http; version=4.0.0" ); Iin there and, when that
> >> >> happened, I was getting a NoClassDefFoundError NamespaceException,
> >> assuming
> >> >> that it was looking for something other than the felix.http.bundle.
> >> >>
> >> >> I really appreciate any help you guys can give me. Thanks!
> >> >>
> >> >> E
> >> >>
> >>
> >>
> >>
> >> --
> >>
> >> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> >> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
> >> Committer & Project Lead
> >> OPS4J Pax for Vaadin
> >> <http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
> >> Lead
> >> blog <http://notizblog.nierbeck.de/>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> >> For additional commands, e-mail: users-help@felix.apache.org
> >>
> >>
>
>
>
> --
>
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
> Committer & Project Lead
> OPS4J Pax for Vaadin
> <http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
> Lead
> blog <http://notizblog.nierbeck.de/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: Getting Started with Felix/Jetty

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Evan,

see my comments inline.

regards, Achim

2012/6/15 Evan Ruff <ev...@hendersonsawmill.com>:
> Guys,
>
> Thanks for the pointer to Pax Web. I've been looking over the documentation
> and have a couple of questions:
>
> 1. is Pax-Web mainly just an extension of the OSGi HTTPService with awesome
> Jetty connectivity?

it's much more, it gives you the war-extender to deploy std. and/or
osgi-fied wars.
it does have a whitebaord-extender to publish all kinds of
"Web-services" as Servlets,
filters and jsps. And much more ...

> 2. Can I configure multiple connectors? My application relies on SSL set up
> using the embedded SslSocketConnector/SelectChannelConnector classes of
> jetty.

Yes this can be done. You have the ability to configure this through
the configuration admin service.
Another reason to take a look at Karaf, cause it will bring you all
the needed parts out-of-the-box,
and you are still able to "down-strip" it if you like.

> 3. Can I harden it strictly for my application? I have some security
> requirements that I need to be very careful with... mainly that would mean
> insuring that there is not any external facing servlets other than mine
> (aka, no admin) etc...
>

well right now Pax Web only gives you the possibility to deploy all kinds of
web artefacts, either through std. OSGi Jars with Activator, through
blueprint.xml definitions - using the whiteboard-pattern
or by deploying either WARs with and without OSGi Manifests.
What ever you deploy is up to you.
So the hardening is mainly your part in either allowing or disallowing
to install certain bundles
after the system is up-to date.

> What are the disadvantages of using embedded Felix? I assumed that it would
> facilitate easier packaging and deployment, is that not true?

I'm repeating myself, I suggest taking a look at Apache Karaf it uses
Felix as the
OSGi Framework and it'll give you a lot of other extra features that
come very handy
when migrating a application to the osgi world.



>
> Thanks,
>
> E
>
> On Fri, Jun 15, 2012 at 2:57 AM, Achim Nierbeck <bc...@googlemail.com>wrote:
>
>> And if you want to have some more stuff like JAAS or Logging out of
>> the box working for you
>> use Apache Karaf which uses Felix as the OSGi framework and brings
>> along everything you need for Pax Web :)
>>
>> regards, Achim
>>
>> 2012/6/15 Allen Lau <al...@gmail.com>:
>> > Unless you really need to embed Felix, why not run the Felix distribution
>> > and add something like Pax-Web which embeds Jetty to be
>> > your WAR/WAB web container?
>> >
>> > On Thu, Jun 14, 2012 at 2:03 PM, Evan Ruff
>> > <ev...@hendersonsawmill.com>wrote:
>> >
>> >> Hey guys,
>> >>
>> >> I'm just getting started with Felix and OSGi in general. I've
>> >> been cursing around trying to find some information about using Felix
>> and
>> >> I've gotten stuck on the most trivial example! I think I must be missing
>> >> some sort of basic concept and I was hoping someone could tell me what
>> I'm
>> >> doing wrong?
>> >>
>> >> For a little background, I'm trying to migrate a web-app to a more
>> modular,
>> >> OSGi based, installable application. I want to distribute my application
>> >> and currently, that requires the administrator to set up a Jetty server
>> and
>> >> install my Webapp. I'd much rather have a single application that
>> contains
>> >> it's own Jetty server and then have the web-apps and their supporting
>> J2EE
>> >> pieces be installed as OSGi modules.
>> >>
>> >> To start, I've created a new Java Project, added felix to the class path
>> >> and spun up the following main:
>> >> public static void main( String[] args ) throws BundleException
>> >>  {
>> >> FrameworkFactory frameworkFactory = ServiceLoader.load(
>> >> FrameworkFactory.class ).iterator().next();
>> >>  Map<String, String> config = new HashMap<String, String>();
>> >> Framework framework = frameworkFactory.newFramework( config );
>> >>  framework.start();
>> >>  BundleContext context = framework.getBundleContext();
>> >> List<Bundle> installedBundles = new LinkedList<Bundle>();
>> >>
>> >> installedBundles.add( context.installBundle(
>> >> "file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
>> >>  installedBundles.add( context.installBundle(
>> >> "file:lib/org.apache.felix.log-1.0.1.jar" ) );
>> >>  installedBundles.add( context.installBundle(
>> >> "file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );
>> >>
>> >> for ( Bundle bundle : installedBundles )
>> >> {
>> >>  System.out.println( "Starting Bundle: " + bundle.getSymbolicName() );
>> >> bundle.start();
>> >>  }
>> >> }
>> >>
>> >> Which I pulled out of a  tutorial about embedding Felix.
>> >>
>> >> I'm running into trouble when I get to the HelloServlet bundle. The
>> >> HelloServlet bundle is the simpliest thing I could write based off of
>> the
>> >> HelloOSGi tutorials that were around. It's a pretty basic Activator,
>> >> registering the servlet as described in the Felix docs:
>> >>
>> >> public void start( BundleContext context ) throws Exception
>> >> {
>> >>  ServiceReference<HttpService> sRef = context.getServiceReference(
>> >> HttpService.class );
>> >> if (sRef != null)
>> >>  {
>> >> HttpService service = (HttpService) context.getService( sRef );
>> >>  service.registerServlet( "/hello", new HelloServlet(), null, null );
>> >> }
>> >>  }
>> >>
>> >> The HelloServlet bundle has org.osgi.framework and
>> org.osgi.service.http in
>> >> the "Import-Package" part of the manifest.
>> >>
>> >> When I run everything, I get a "Unable to resolve 4.0: missing
>> requirement
>> >> [4.0] osgi.wiring.package;
>> >> (&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))"
>> exception
>> >> when starting the HelloServlet bundle. I assume this is because my Felix
>> >> container isn't registering th http-bundle properly.
>> >>
>> >> How do I get this sort of thing to work in an embedded scenario like
>> this?
>> >>
>> >> FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
>> >> "org.osgi.service.http; version=4.0.0" ); Iin there and, when that
>> >> happened, I was getting a NoClassDefFoundError NamespaceException,
>> assuming
>> >> that it was looking for something other than the felix.http.bundle.
>> >>
>> >> I really appreciate any help you guys can give me. Thanks!
>> >>
>> >> E
>> >>
>>
>>
>>
>> --
>>
>> Apache Karaf <http://karaf.apache.org/> Committer & PMC
>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
>> Committer & Project Lead
>> OPS4J Pax for Vaadin
>> <http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
>> Lead
>> blog <http://notizblog.nierbeck.de/>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
Committer & Project Lead
OPS4J Pax for Vaadin
<http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
Lead
blog <http://notizblog.nierbeck.de/>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Getting Started with Felix/Jetty

Posted by Don Brown <do...@gmail.com>.
On Wed, Jun 27, 2012 at 7:54 AM,  <Ch...@emc.com> wrote:
> I've been re-architecting an app that embedded a felix container into an existing web app.  This came about because of a requirement for hot deployment that arrived after the "host" app was already built and deployed into the field.  The classloader bit itself is tricky ( actually, though, it's also a great case study deep diving on classloaders).  The biggest problem for me came out of the fact that a lot of classes were needed by both the host app and the bundles that we're going to be installed into the container.
>
> I found myself wishing I had time to re-implement the host app as an OSGi app.

Yeah, that is a common wish from devs in Atlassian.  Correctly
straddling that boundary is a pain.  How we do it is force all api
jars in WEB-INF/lib so both sides can access the classes, expose them
via our package scanner, then allow the web app to register services
(called host components) that will be exposed up to OSGi-land and
along the way, get wrapped in a proxy that will switch the context
classloader so the host components will hopefully work correctly.  All
this is Open Source, so if you ever want to poke around, go nuts:
https://bitbucket.org/atlassian/atlassian-plugins

>> Furthermore, many, if not most, web application libraries are built assuming
>> the context classloader has full access to the whole webapp, which isn't the
>> case in OSGi land where the CCL is actually undefined.
>
> For instance, Hibernate.

Yeah, we use Hibernate a lot, so what we do is just leave that in the
host app and expose services up to OSGi-land.  Not a lot of good ORMs
out there that are OSGi/multiple classloader friendly.

Don

>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Getting Started with Felix/Jetty

Posted by Karl Pauls <ka...@gmail.com>.
On Wed, Jun 27, 2012 at 3:54 PM,  <Ch...@emc.com> wrote:
>
>
>> While I'm the one responsible for using embedded Felix in all Java-based
>> Atlassian products, I would generally agree with my good friend Chad that it
>
> Hi Don!  Interestingly, I've spend the last few months reworking a webapp that hosts an  embedded felix container.

You could have used pojosr :-)

regards,

Karl

>> is generally not advisable unless you have very specific extensibility
>> requirements that could be serviced via OSGi.
>> The main issue has to do with the different "levels" (classloaders) code runs
>> in, so if you have lots of code back down in the web app, you have to be very
>> careful how and where you expose that up to OSGi bundles.  For example, if
>
> I've been re-architecting an app that embedded a felix container into an existing web app.  This came about because of a requirement for hot deployment that arrived after the "host" app was already built and deployed into the field.  The classloader bit itself is tricky ( actually, though, it's also a great case study deep diving on classloaders).  The biggest problem for me came out of the fact that a lot of classes were needed by both the host app and the bundles that we're going to be installed into the container.
>
> I found myself wishing I had time to re-implement the host app as an OSGi app.
>
>> Furthermore, many, if not most, web application libraries are built assuming
>> the context classloader has full access to the whole webapp, which isn't the
>> case in OSGi land where the CCL is actually undefined.
>
> For instance, Hibernate.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>



-- 
Karl Pauls
karlpauls@gmail.com
http://twitter.com/karlpauls
http://www.linkedin.com/in/karlpauls
https://profiles.google.com/karlpauls

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Getting Started with Felix/Jetty

Posted by Christopher BROWN <br...@reflexe.fr>.
Hello,

I'm involved in a project (software used by others, not in-house app)
that uses Felix and Jetty.  We chose the following approach:

- standalone java application that embeds felix (with an equivalent to
"fileinstall" for handling "plugins")

- a bundle defining an API (interfaces only) ; defines something
similar to the servlet api, simplified to match use-cases ; no direct
use or exposure of servlet api

- a bundle containing Jetty, in embedded mode, visible only inside the
bundle using Bundle-Classpath ; neither the servlet api nor the http
osgi service are exposed ; dynamically maps implementations of our api
to jetty

We decided AGAINST :

- embedding felix in a "classic" webapp, because (with particular
concern for osgi framework classes) as many app servers now use and
expose osgi, looked like a support nightmare if our embedded framework
version conflicts with the app server's version

- using the osgi http service, which tries to reuse the "standard"
servlet api, but this seemed not to be a perfect fit (some classes
using the servlet api would make assumptions about classes and
environment that would be incorrect here)

- having a fallback solution of using osgi fragments to bind to our
bundle that embeds jetty if we're ever really stuck (needing to use
something that expects the servlet api) ; have not hit this need yet

Hope that's of some use in your considerations,
Christopher



On 27 June 2012 15:54, <Ch...@emc.com> wrote:
>
>
>
> > While I'm the one responsible for using embedded Felix in all Java-based
> > Atlassian products, I would generally agree with my good friend Chad that it
>
> Hi Don!  Interestingly, I've spend the last few months reworking a webapp that hosts an  embedded felix container.
>
> > is generally not advisable unless you have very specific extensibility
> > requirements that could be serviced via OSGi.
> > The main issue has to do with the different "levels" (classloaders) code runs
> > in, so if you have lots of code back down in the web app, you have to be very
> > careful how and where you expose that up to OSGi bundles.  For example, if
>
> I've been re-architecting an app that embedded a felix container into an existing web app.  This came about because of a requirement for hot deployment that arrived after the "host" app was already built and deployed into the field.  The classloader bit itself is tricky ( actually, though, it's also a great case study deep diving on classloaders).  The biggest problem for me came out of the fact that a lot of classes were needed by both the host app and the bundles that we're going to be installed into the container.
>
> I found myself wishing I had time to re-implement the host app as an OSGi app.
>
> > Furthermore, many, if not most, web application libraries are built assuming
> > the context classloader has full access to the whole webapp, which isn't the
> > case in OSGi land where the CCL is actually undefined.
>
> For instance, Hibernate.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: Getting Started with Felix/Jetty

Posted by Ch...@emc.com.

> While I'm the one responsible for using embedded Felix in all Java-based
> Atlassian products, I would generally agree with my good friend Chad that it

Hi Don!  Interestingly, I've spend the last few months reworking a webapp that hosts an  embedded felix container.  

> is generally not advisable unless you have very specific extensibility
> requirements that could be serviced via OSGi.
> The main issue has to do with the different "levels" (classloaders) code runs
> in, so if you have lots of code back down in the web app, you have to be very
> careful how and where you expose that up to OSGi bundles.  For example, if

I've been re-architecting an app that embedded a felix container into an existing web app.  This came about because of a requirement for hot deployment that arrived after the "host" app was already built and deployed into the field.  The classloader bit itself is tricky ( actually, though, it's also a great case study deep diving on classloaders).  The biggest problem for me came out of the fact that a lot of classes were needed by both the host app and the bundles that we're going to be installed into the container.

I found myself wishing I had time to re-implement the host app as an OSGi app.    

> Furthermore, many, if not most, web application libraries are built assuming
> the context classloader has full access to the whole webapp, which isn't the
> case in OSGi land where the CCL is actually undefined.

For instance, Hibernate. 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Getting Started with Felix/Jetty

Posted by Don Brown <do...@gmail.com>.
While I'm the one responsible for using embedded Felix in all
Java-based Atlassian products, I would generally agree with my good
friend Chad that it is generally not advisable unless you have very
specific extensibility requirements that could be serviced via OSGi.
The main issue has to do with the different "levels" (classloaders)
code runs in, so if you have lots of code back down in the web app,
you have to be very careful how and where you expose that up to OSGi
bundles.  For example, if you have libraries you want exposed to OSGi
bundles, you either have to maintain the package list yourself or do
some fancy scanning (we do the latter), which can be very problematic
in some app servers.

Furthermore, many, if not most, web application libraries are built
assuming the context classloader has full access to the whole webapp,
which isn't the case in OSGi land where the CCL is actually undefined.
 This is a general challenge with OSGi, and while not insurmountable,
you'll definitely want to make sure you absolutely need the
extensibility OSGi delivers.  In our case, we needed a way to
basically let people build applications on top of our apps, and OSGi
is the only way to make that happen.  Along the way, we've had a host
of challenges, but in the end, we have hundreds of OSGi bundles (we
call them plugins) in our Marketplace, many of which are paid enabling
a whole ecosystem of small and large companies, so the pain we've go
through, I think, has been worth it.  However, for the average web
app, I'd guess it wouldn't be.

Don

On Wed, Jun 27, 2012 at 3:57 AM,  <Ch...@emc.com> wrote:
>
>>
>> What are the disadvantages of using embedded Felix? I assumed that it
>> would facilitate easier packaging and deployment, is that not true?
>
> I'm working with an app that embeds felix into a web app . . . not good for various reasons.  I would strongly dissuade you from doing so.  Feel free to ask if you need more info.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: Getting Started with Felix/Jetty

Posted by Ch...@emc.com.
> 
> What are the disadvantages of using embedded Felix? I assumed that it
> would facilitate easier packaging and deployment, is that not true?

I'm working with an app that embeds felix into a web app . . . not good for various reasons.  I would strongly dissuade you from doing so.  Feel free to ask if you need more info.

 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Getting Started with Felix/Jetty

Posted by Evan Ruff <ev...@hendersonsawmill.com>.
Guys,

Thanks for the pointer to Pax Web. I've been looking over the documentation
and have a couple of questions:

1. is Pax-Web mainly just an extension of the OSGi HTTPService with awesome
Jetty connectivity?
2. Can I configure multiple connectors? My application relies on SSL set up
using the embedded SslSocketConnector/SelectChannelConnector classes of
jetty.
3. Can I harden it strictly for my application? I have some security
requirements that I need to be very careful with... mainly that would mean
insuring that there is not any external facing servlets other than mine
(aka, no admin) etc...

What are the disadvantages of using embedded Felix? I assumed that it would
facilitate easier packaging and deployment, is that not true?

Thanks,

E

On Fri, Jun 15, 2012 at 2:57 AM, Achim Nierbeck <bc...@googlemail.com>wrote:

> And if you want to have some more stuff like JAAS or Logging out of
> the box working for you
> use Apache Karaf which uses Felix as the OSGi framework and brings
> along everything you need for Pax Web :)
>
> regards, Achim
>
> 2012/6/15 Allen Lau <al...@gmail.com>:
> > Unless you really need to embed Felix, why not run the Felix distribution
> > and add something like Pax-Web which embeds Jetty to be
> > your WAR/WAB web container?
> >
> > On Thu, Jun 14, 2012 at 2:03 PM, Evan Ruff
> > <ev...@hendersonsawmill.com>wrote:
> >
> >> Hey guys,
> >>
> >> I'm just getting started with Felix and OSGi in general. I've
> >> been cursing around trying to find some information about using Felix
> and
> >> I've gotten stuck on the most trivial example! I think I must be missing
> >> some sort of basic concept and I was hoping someone could tell me what
> I'm
> >> doing wrong?
> >>
> >> For a little background, I'm trying to migrate a web-app to a more
> modular,
> >> OSGi based, installable application. I want to distribute my application
> >> and currently, that requires the administrator to set up a Jetty server
> and
> >> install my Webapp. I'd much rather have a single application that
> contains
> >> it's own Jetty server and then have the web-apps and their supporting
> J2EE
> >> pieces be installed as OSGi modules.
> >>
> >> To start, I've created a new Java Project, added felix to the class path
> >> and spun up the following main:
> >> public static void main( String[] args ) throws BundleException
> >>  {
> >> FrameworkFactory frameworkFactory = ServiceLoader.load(
> >> FrameworkFactory.class ).iterator().next();
> >>  Map<String, String> config = new HashMap<String, String>();
> >> Framework framework = frameworkFactory.newFramework( config );
> >>  framework.start();
> >>  BundleContext context = framework.getBundleContext();
> >> List<Bundle> installedBundles = new LinkedList<Bundle>();
> >>
> >> installedBundles.add( context.installBundle(
> >> "file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
> >>  installedBundles.add( context.installBundle(
> >> "file:lib/org.apache.felix.log-1.0.1.jar" ) );
> >>  installedBundles.add( context.installBundle(
> >> "file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );
> >>
> >> for ( Bundle bundle : installedBundles )
> >> {
> >>  System.out.println( "Starting Bundle: " + bundle.getSymbolicName() );
> >> bundle.start();
> >>  }
> >> }
> >>
> >> Which I pulled out of a  tutorial about embedding Felix.
> >>
> >> I'm running into trouble when I get to the HelloServlet bundle. The
> >> HelloServlet bundle is the simpliest thing I could write based off of
> the
> >> HelloOSGi tutorials that were around. It's a pretty basic Activator,
> >> registering the servlet as described in the Felix docs:
> >>
> >> public void start( BundleContext context ) throws Exception
> >> {
> >>  ServiceReference<HttpService> sRef = context.getServiceReference(
> >> HttpService.class );
> >> if (sRef != null)
> >>  {
> >> HttpService service = (HttpService) context.getService( sRef );
> >>  service.registerServlet( "/hello", new HelloServlet(), null, null );
> >> }
> >>  }
> >>
> >> The HelloServlet bundle has org.osgi.framework and
> org.osgi.service.http in
> >> the "Import-Package" part of the manifest.
> >>
> >> When I run everything, I get a "Unable to resolve 4.0: missing
> requirement
> >> [4.0] osgi.wiring.package;
> >> (&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))"
> exception
> >> when starting the HelloServlet bundle. I assume this is because my Felix
> >> container isn't registering th http-bundle properly.
> >>
> >> How do I get this sort of thing to work in an embedded scenario like
> this?
> >>
> >> FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
> >> "org.osgi.service.http; version=4.0.0" ); Iin there and, when that
> >> happened, I was getting a NoClassDefFoundError NamespaceException,
> assuming
> >> that it was looking for something other than the felix.http.bundle.
> >>
> >> I really appreciate any help you guys can give me. Thanks!
> >>
> >> E
> >>
>
>
>
> --
>
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
> Committer & Project Lead
> OPS4J Pax for Vaadin
> <http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
> Lead
> blog <http://notizblog.nierbeck.de/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: Getting Started with Felix/Jetty

Posted by Achim Nierbeck <bc...@googlemail.com>.
And if you want to have some more stuff like JAAS or Logging out of
the box working for you
use Apache Karaf which uses Felix as the OSGi framework and brings
along everything you need for Pax Web :)

regards, Achim

2012/6/15 Allen Lau <al...@gmail.com>:
> Unless you really need to embed Felix, why not run the Felix distribution
> and add something like Pax-Web which embeds Jetty to be
> your WAR/WAB web container?
>
> On Thu, Jun 14, 2012 at 2:03 PM, Evan Ruff
> <ev...@hendersonsawmill.com>wrote:
>
>> Hey guys,
>>
>> I'm just getting started with Felix and OSGi in general. I've
>> been cursing around trying to find some information about using Felix and
>> I've gotten stuck on the most trivial example! I think I must be missing
>> some sort of basic concept and I was hoping someone could tell me what I'm
>> doing wrong?
>>
>> For a little background, I'm trying to migrate a web-app to a more modular,
>> OSGi based, installable application. I want to distribute my application
>> and currently, that requires the administrator to set up a Jetty server and
>> install my Webapp. I'd much rather have a single application that contains
>> it's own Jetty server and then have the web-apps and their supporting J2EE
>> pieces be installed as OSGi modules.
>>
>> To start, I've created a new Java Project, added felix to the class path
>> and spun up the following main:
>> public static void main( String[] args ) throws BundleException
>>  {
>> FrameworkFactory frameworkFactory = ServiceLoader.load(
>> FrameworkFactory.class ).iterator().next();
>>  Map<String, String> config = new HashMap<String, String>();
>> Framework framework = frameworkFactory.newFramework( config );
>>  framework.start();
>>  BundleContext context = framework.getBundleContext();
>> List<Bundle> installedBundles = new LinkedList<Bundle>();
>>
>> installedBundles.add( context.installBundle(
>> "file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
>>  installedBundles.add( context.installBundle(
>> "file:lib/org.apache.felix.log-1.0.1.jar" ) );
>>  installedBundles.add( context.installBundle(
>> "file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );
>>
>> for ( Bundle bundle : installedBundles )
>> {
>>  System.out.println( "Starting Bundle: " + bundle.getSymbolicName() );
>> bundle.start();
>>  }
>> }
>>
>> Which I pulled out of a  tutorial about embedding Felix.
>>
>> I'm running into trouble when I get to the HelloServlet bundle. The
>> HelloServlet bundle is the simpliest thing I could write based off of the
>> HelloOSGi tutorials that were around. It's a pretty basic Activator,
>> registering the servlet as described in the Felix docs:
>>
>> public void start( BundleContext context ) throws Exception
>> {
>>  ServiceReference<HttpService> sRef = context.getServiceReference(
>> HttpService.class );
>> if (sRef != null)
>>  {
>> HttpService service = (HttpService) context.getService( sRef );
>>  service.registerServlet( "/hello", new HelloServlet(), null, null );
>> }
>>  }
>>
>> The HelloServlet bundle has org.osgi.framework and org.osgi.service.http in
>> the "Import-Package" part of the manifest.
>>
>> When I run everything, I get a "Unable to resolve 4.0: missing requirement
>> [4.0] osgi.wiring.package;
>> (&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))" exception
>> when starting the HelloServlet bundle. I assume this is because my Felix
>> container isn't registering th http-bundle properly.
>>
>> How do I get this sort of thing to work in an embedded scenario like this?
>>
>> FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
>> "org.osgi.service.http; version=4.0.0" ); Iin there and, when that
>> happened, I was getting a NoClassDefFoundError NamespaceException, assuming
>> that it was looking for something other than the felix.http.bundle.
>>
>> I really appreciate any help you guys can give me. Thanks!
>>
>> E
>>



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
Committer & Project Lead
OPS4J Pax for Vaadin
<http://team.ops4j.org/wiki/display/PAXVAADIN/Home> Commiter & Project
Lead
blog <http://notizblog.nierbeck.de/>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Getting Started with Felix/Jetty

Posted by Allen Lau <al...@gmail.com>.
Unless you really need to embed Felix, why not run the Felix distribution
and add something like Pax-Web which embeds Jetty to be
your WAR/WAB web container?

On Thu, Jun 14, 2012 at 2:03 PM, Evan Ruff
<ev...@hendersonsawmill.com>wrote:

> Hey guys,
>
> I'm just getting started with Felix and OSGi in general. I've
> been cursing around trying to find some information about using Felix and
> I've gotten stuck on the most trivial example! I think I must be missing
> some sort of basic concept and I was hoping someone could tell me what I'm
> doing wrong?
>
> For a little background, I'm trying to migrate a web-app to a more modular,
> OSGi based, installable application. I want to distribute my application
> and currently, that requires the administrator to set up a Jetty server and
> install my Webapp. I'd much rather have a single application that contains
> it's own Jetty server and then have the web-apps and their supporting J2EE
> pieces be installed as OSGi modules.
>
> To start, I've created a new Java Project, added felix to the class path
> and spun up the following main:
> public static void main( String[] args ) throws BundleException
>  {
> FrameworkFactory frameworkFactory = ServiceLoader.load(
> FrameworkFactory.class ).iterator().next();
>  Map<String, String> config = new HashMap<String, String>();
> Framework framework = frameworkFactory.newFramework( config );
>  framework.start();
>  BundleContext context = framework.getBundleContext();
> List<Bundle> installedBundles = new LinkedList<Bundle>();
>
> installedBundles.add( context.installBundle(
> "file:lib/org.apache.felix.http.bundle-2.2.0.jar" ) );
>  installedBundles.add( context.installBundle(
> "file:lib/org.apache.felix.log-1.0.1.jar" ) );
>  installedBundles.add( context.installBundle(
> "file:plugins/com.payPlum.HelloServlet_1.0.0.201206141509.jar" ) );
>
> for ( Bundle bundle : installedBundles )
> {
>  System.out.println( "Starting Bundle: " + bundle.getSymbolicName() );
> bundle.start();
>  }
> }
>
> Which I pulled out of a  tutorial about embedding Felix.
>
> I'm running into trouble when I get to the HelloServlet bundle. The
> HelloServlet bundle is the simpliest thing I could write based off of the
> HelloOSGi tutorials that were around. It's a pretty basic Activator,
> registering the servlet as described in the Felix docs:
>
> public void start( BundleContext context ) throws Exception
> {
>  ServiceReference<HttpService> sRef = context.getServiceReference(
> HttpService.class );
> if (sRef != null)
>  {
> HttpService service = (HttpService) context.getService( sRef );
>  service.registerServlet( "/hello", new HelloServlet(), null, null );
> }
>  }
>
> The HelloServlet bundle has org.osgi.framework and org.osgi.service.http in
> the "Import-Package" part of the manifest.
>
> When I run everything, I get a "Unable to resolve 4.0: missing requirement
> [4.0] osgi.wiring.package;
> (&(osgi.wiring.package=org.osgi.service.http)(version>=1.2.1))" exception
> when starting the HelloServlet bundle. I assume this is because my Felix
> container isn't registering th http-bundle properly.
>
> How do I get this sort of thing to work in an embedded scenario like this?
>
> FWIW, I had: config.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
> "org.osgi.service.http; version=4.0.0" ); Iin there and, when that
> happened, I was getting a NoClassDefFoundError NamespaceException, assuming
> that it was looking for something other than the felix.http.bundle.
>
> I really appreciate any help you guys can give me. Thanks!
>
> E
>