Re: In Bed with Vaadin and OSGi

191 views
Skip to first unread message

robinh

unread,
Jun 12, 2010, 2:12:07 AM6/12/10
to Vaadin OSGi Collaboration
Chris et al.
I have just (nearly) completed something very similar to that
described by Chris (http://www.perplentropy.com/2010/02/in-bed-with-
vaadin-and-osgi.html), that is, running Vaadin on bare httpservice
with no web.xml, etc web container. If only I had seen Chris & Neils
work a few days earlier!

I just wrote a simple static server, then a forwarder (to another
server) then hitched in Vaadin Application.
HelloWorldApplication was OK, the static server handled VAADIN. In no
time I had SimpleAddressBook going and then the three tab panels
example that is around. Then I used the Vaadin visual editor to make
a CustomComponent. Great until ...

I came unstuck when I tried to load some images using classes
ExternalResource & Embedded. My code doesn't seem to handle that.

Neil's comment "The Application objects cannot directly be registered
as services since they have session lifecycle, so instead we need a
factory registered as a service" probably points to my problem.

Worse, I then found the vaadin source code for Embedded doesn't seem
to line up with that in the vaadin class so I'm stepping through
comment and then it's hard to see what is broken.

So I thought my simple approach may be too simple and that I should
give Chris' code a try, and so I downloaded it.

I got annotation-0.0.384.jar from Aqute and that seemed to fix
aQute.bnd....Activate. Then I added osgi-4.2.cmpn.jar and satisfied
framework stuff by including felix.jar in the classpath.

When I use bnd to build com.vaadin.osgi, I get an error:

"Service-Component Component definition refers to a class that is
neither imported nor contained:
org.osgi.service.component.ComponentFactory;Ljava.util.Map"


Looking in .classpath, I see
"name.neilbartlett.eclipse.bndtools.FRAMEWORK_CONTAINER/r4_2/
annotations=true".

What do I need to get past this and where do I get it? Are there any
other bits I need? Thanks in advance for any help. Is Chris' code the
best palce to restart?

I am using JavaSE-1.6, javax,servlet 2.5, felix 2.0.5, felix..jetty
2.04 and vaadin 6.3.3.

I am impressed with how simple and well-decoupled my tab-panel bundles
are from the tab-panel service and my SimpleVaadinServer (which nearly
works!). DS is neat!

I contrast that with fighting with GWT RPC serialisation on OSGi ( I
think GWT still has not been made OSGi class-loader friendly per GWT
issue 1888)???

Vaadin seems a better way (layered on JSON and GWT).

Looking through your discussions, I can summarise what I have been
after & done:

1. A single assembly of bundles that does everything requiring no
Tomcat or whatever.

2. Plug-in pages (like the tab panel example) where a page is a bundle
is a Topic and is pretty much independent of others.

3. Low throughput with no more than two or three concurrent sessions.

4. Live ajax widgets & pretty.

5. Simple so I don't have to worry about learning how to configure an
Apache, Tomcat or Glassfish with a single startup point.

so I have

1. A SimpleServer bundle that uses httpService to do (1) static vaadin
& plain html pages & (2) forwarding to other server and (3) vaadin
"system".

2. A TopicService bundle which listens for topics and lays out the top
level layout, in my case a grid, a whiteboard.

3. A bundle for each Topic class with an inner TopicComponent extends
CustomComponent populated
with widgets.

4. Felix ( Equinox is just too Eclipsy and shoehorns me to the Eclipse
way))

Its all a bit of a skeleton so far, but looks a good way to organise
stuff.


robinh

unread,
Jun 12, 2010, 9:58:28 PM6/12/10
to Vaadin OSGi Collaboration
Continuing form my previous post. I figured I might have been missing
org.apache.felix.scr-1.4.0.jar, but I am not. It is in the classpath
and in the jar I see:

org/osgi/service/component
ComponentConstants.class
ComponentContext.class
ComponentException.class
ComponentFactory.class
ComponentInstance.class
package.html
packageinfo

So I am not really understanding the bnd error message:

"Service-Component Component definition refers to a class that is
neither imported nor contained:
org.osgi.service.component.ComponentFactory;Ljava.util.Map"

So its missing the class

ComponentFactory;Ljava.util.Map

I do not yet understand what this is saying.

I googled a quote by bjhargrave

"In DS, when you declare a factory component (with the factory
attribute), you are telling DS to register a ComponentFactory service
on your behalf. DS provides the ComponentFactory object. Not you. When
someone calls newInstance on the ComponentFactory object, a new
instance of the declared implementation class ... will be declared."

but I still don't see what the problem is.

robinh

unread,
Jun 13, 2010, 12:45:16 PM6/13/10
to Vaadin OSGi Collaboration
I have now built all three jars.

I did this by commenting out the bnd annotations and instead putting
component directives into the VaadinOSGiApplicationManager bnd file. I
could not figure out from bnd docs how to specify the reference entry
and exit points. The bnd document says how do it "according to
standard bean rules" but I could not find how to do it when bean rules
do not apply. I fixed the problem by changing signature of the two
methods to
setApplicationRegistered and unsetApplicationRegistered.

Now I have a jar. The other two jars were straightforward.
Now I will test the jars.

So the original problem seems to be something to do with bnd
annotations.


My bnd file now looks like:

Bundle-SymbolicName: com.vaadin.osgi
Bundle-Version: 1.0.0
Private-Package: com.vaadin.osgi
Service-Component: com.vaadin.osgi.StaticResources,\
com.vaadin.osgi.VaadinOSGiApplicationManager
Import-Bundle: com.vaadin
# Import-Package: *,org.osgi.service.component;

Service-Component=com.vaadin.osgi.StaticResources;\
bind=org.osgi.service.http.HttpService; \
#log=org.osgi.service.log.LogService;\
properties: = "http.alias=/VAADIN";
activate:=start;\
deactivate:=stop

Service-Component=com.vaadin.osgi.VaadinOSGiApplicationManager;\
activate:=start;\
deactivate:=stop;\
http=org.osgi.service.http.HttpService; \
applicationRemoved=org.osgi.service.component.ComponentFactory"; \
(component.factory=vaadin.app)*", \

Neil Bartlett

unread,
Jun 14, 2010, 5:18:04 AM6/14/10
to vaadi...@googlegroups.com
Hi Robin,

Sorry that nobody has replied to your emails yet. I think that, like
me, the other people in this group prefer to spend time with their
families rather than their computers on the weekend ;-)

I must admit that I'm quite confused by your description of the
problem. It seems that you have shot off on a number of tangents that
are not related to the original issue. Let's go back to the
beginning... it seems that the initial problem you had was as follows:

> I came unstuck when I tried to load some images using classes
> ExternalResource & Embedded. My code doesn't seem to handle that.

What exactly is happening? Is there an error message or stack trace
that you could send us? Can you include your bundle, so we can check
that the manifest is correct etc.?

Kind regards,
Neil.

robinh

unread,
Jun 14, 2010, 11:48:06 AM6/14/10
to Vaadin OSGi Collaboration
For me, every day is a weekend!

I have been carefully through Chris' code where he uses a factory for
Applications. I see that my own version was too simple. Also I have
just read your page http://njbartlett.github.com/#VaadinOSGi saying
"The Application objects cannot directly be registered as services
since they have session lifecycle".

So I need a factory! It seems easiest now to continue with Chris'
code as it has a factory.

For now I, have worked around the initial problem I had with
annotations ( I think that is where the problem is). I thought I
would get everything else working and then go back to that later.

I now have Chris' code well on the way to working. I put in a few more
println's and so I see his VaadinOSGiApplicationManager and
StaticResources being started up by DS.

I think now my issue is somehow the factory instance is not getting
created.

I see that helloworld.theme is just resolved and not active. I
thought this might be OK because it is just a resource. If I say
-> start 3
I get
-> org.osgi.framework.BundleException: Fragment bundles can not be
started.
To me that seems OK.

It seems to me I am nearly there.

I don't know if you are familiar with his code. I understand you
helped him on it.

The static servlet is going OK. I can specify a theme URL with firefox
http://localhost:8183/VAADIN/themes/helloworld/styles.css and see the
css. So the helloworld fragment is hitching to vaadin.jar correctly.


My analysis
=======

DS has called VaadinOSGiApplicationManager twice, first to set the
httpService, then to start. But it is not being called at
setApplicationRegistered with an instance of a factory. So the
current problem seems to be that the HelloWorld factory service is not
being created and DS has not called setApplicationRegistered.

scr info 2 prints lines ...

State: factory
Activation: delayed

I don't know if 'delayed' is correct.
Properties: component.factory = vaadin.app

So is it that the filter spec is not allowing the connection?

I am not quite sure what initiates creating the actual factory
instance. HelloWorld is saying I am a factory component.
VaadinOSGiApplicationManager specifies it needs a factory instance
with the xml tag
target='(component.factory=vaadin.app)'.

Can you spot something wrong??

Thanks for any help.

P.S. I see your Bndtools. I do find using bnd hard work, so I shall
take a look.

=========================================



Below are some console outputs and dumps of the component xml from the
jars I am running:

Felix console println output:

Welcome to Felix
================

->
VaadinOSGiApplicationManager: bound to httpService

VaadinOSGiApplicationManager.start:
{component.name=com.vaadin.osgi.VaadinOSGiApplicationManager,
component.id=1,
applicationRegistered.target=(component.factory=vaadin.app)}

VaadinOSGiApplicationManager.start: waiting = 0

VaadinOSGiApplicationManager.start: state = started & waiting for
registrations

StaticResources: bound to httpService

StaticResources: start

_____________________________________

START LEVEL 1
ID State Level Name
[ 0] [Active ] [ 0] System Bundle (2.0.5)
[ 1] [Active ] [ 1] com.vaadin.osgi (1.0.0)
[ 2] [Active ] [ 1] helloworld (1.0.0)
[ 3] [Resolved ] [ 1] helloworld.theme (6.2.3)
[ 4] [Active ] [ 1] JAXP XML (1.3.4.v200902170245)
[ 5] [Active ] [ 1] Apache Felix Bundle Repository (1.4.3)
[ 6] [Active ] [ 1] Apache Felix Configuration Admin Service
(1.2.4)
[ 7] [Active ] [ 1] Apache Felix Http Jetty (2.0.4)
[ 8] [Active ] [ 1] Apache Felix Log Service (1.0.0)
[ 9] [Active ] [ 1] Apache Felix Declarative Services (1.4.0)
[ 10] [Active ] [ 1] Apache Felix Shell Service (1.4.2)
[ 11] [Active ] [ 1] Apache Felix Shell TUI (1.4.1)
[ 12] [Active ] [ 1] JavaUtil (0)
[ 13] [Active ] [ 1] Vaadin (6.1.0.development)
->

__________________________________________________
-> scr list
Id State Name
[ 0] [active ] com.vaadin.osgi.StaticResources
[ 1] [active ] com.vaadin.osgi.VaadinOSGiApplicationManager
[ 2] [factory ] helloworld

_____________________________________________________
-> scr info 0
=========
ID: 0
Name: com.vaadin.osgi.StaticResources
Bundle: com.vaadin.osgi (1)
State: active
Default State: enabled
Activation: immediate
Configuration Policy: optional
Activate Method: start (declared in the descriptor)
Deactivate Method: stop (declared in the descriptor)
Modified Method: -
Reference: http
Satisfied: satisfied
Service Name: org.osgi.service.http.HttpService
Multiple: single
Optional: mandatory
Policy: static
Properties:
component.id = 0
component.name = com.vaadin.osgi.StaticResources
http.alias = /VAADIN
->
______________________________________________________
-> scr info 1
=========
ID: 1
Name: com.vaadin.osgi.VaadinOSGiApplicationManager
Bundle: com.vaadin.osgi (1)
State: active
Default State: enabled
Activation: immediate
Configuration Policy: optional
Activate Method: start (declared in the descriptor)
Deactivate Method: stop (declared in the descriptor)
Modified Method: -
Reference: http
Satisfied: satisfied
Service Name: org.osgi.service.http.HttpService
Multiple: single
Optional: mandatory
Policy: static
Reference: applicationRegistered
Satisfied: satisfied
Service Name: org.osgi.service.component.ComponentFactory
Target Filter: (component.factory=vaadin.app)
Multiple: multiple
Optional: optional
Policy: dynamic
Properties:
applicationRegistered.target = (component.factory=vaadin.app)
component.id = 1
component.name = com.vaadin.osgi.VaadinOSGiApplicationManager
-_______________________________________________________________
-> scr info 2
=========
ID: 2
Name: helloworld
Bundle: helloworld (2)
State: factory
Default State: enabled
Activation: delayed
Configuration Policy: optional
Activate Method: activate
Deactivate Method: deactivate
Modified Method: -
Factory: vaadin.app
Services: com.vaadin.Application
Service Type: service
Properties:
component.factory = vaadin.app
component.name = helloworld
service.description = ManagedServiceFactory for Factory
Componenthelloworld
service.pid = helloworld
service.vendor = The Apache Software Foundation
->
_____________________________________________________________
In my jars I see:

com.vaadin.osgi.jar
==============
[COMPONENTS]
OSGI-INF/com.vaadin.osgi.StaticResources.xml
<?xml version='1.0' encoding='utf-8'?>
<component name='com.vaadin.osgi.StaticResources' xmlns='http://
www.osgi.org/xmlns/scr/v1.1.0' activate='start' deactivate='stop'>
<implementation class='com.vaadin.osgi.StaticResources'/>
<property name='http.alias' value='/VAADIN'/>
<reference name='http' interface='org.osgi.service.http.HttpService'
bind='setHttp' unbind='unsetHttp'/>
</component>
OSGI-INF/com.vaadin.osgi.VaadinOSGiApplicationManager.xml
<?xml version='1.0' encoding='utf-8'?>
<component name='com.vaadin.osgi.VaadinOSGiApplicationManager'
xmlns='http://www.osgi.org/xmlns/scr/v1.1.0' activate='start'
deactivate='stop'>
<implementation class='com.vaadin.osgi.VaadinOSGiApplicationManager'/
>
<reference name='http' interface='org.osgi.service.http.HttpService'
bind='setHttp' unbind='unsetHttp'/>
<reference name='applicationRegistered'
interface='org.osgi.service.component.ComponentFactory '
cardinality='0..n' bind='setApplicationRegistered'
unbind='unsetApplicationRegistered' policy='dynamic'
target='(component.factory=vaadin.app)'/>
</component>

________________________________________________________
helloworld.jar
=========
[COMPONENTS]
OSGI-INF/helloworld.xml
<?xml version='1.0' encoding='utf-8'?>
<component name='helloworld' factory='vaadin.app'>
<implementation class='helloworld.HelloWorldApplication'/>
<service>
<provide interface='com.vaadin.Application'/>
</service>
</component>

robinh

unread,
Jun 14, 2010, 10:24:50 PM6/14/10
to Vaadin OSGi Collaboration
Problem Solved:

I have made things work and get HelloWorld! firstly by omitting the
target reference, just putting

foo=org.osgi.service.component.ComponentFactory

in place of

foo=org.osgi.service.component.ComponentFactory
"(component.factory=vaadin.app)*"

which did not work.

I then replaced

foo=org.osgi.service.component.ComponentFactory
"(component.factory=vaadin.app)*"

with

foo=org.osgi.service.component.ComponentFactory"(component.factory=vaadin.app)*"

and everything seems to work.

So my problem was a space character in the argument, I suppose
chopping one argument into two.



Did I read something by Neil in BndTools saying OSGi needs better and
more forgiving tools!!!



I don't think I have the energy to figure out why I was getting the
error message:

"Service-Component Component definition refers to a class that is
neither imported nor contained:
org.osgi.service.component.ComponentFactory;Ljava.util.Map".

Maybe I have an old version of bnd (384) that has a problem??? Or
perhaps in the annotation jar.
Or perhaps another space character somewhere!!!

robinh

unread,
Jun 14, 2010, 6:29:04 PM6/14/10
to Vaadin OSGi Collaboration
New information.

I tried some systematic trouble-shooting. I have Chris' 3 jars that
work and mine that don't! So I tried various combinations.

My jars of helloworld.jar and helloworld.theme.jar are interchangeable
with his, so my problem is in building com.osgi.vaadin.jar.

... I wonder if some of my problems are versions. I am using newer
versions of some jars and older versions of others.

My problems with annotation may be related to using bnd version 384
which Peter Kriens site says is current. I see Chris used 393. The
most current seems to be 401?

So now I will focus on osgi.vaadin.jar and what I am doing wrong.



Reply all
Reply to author
Forward
0 new messages