0

ZK and OSGi in Springsource DM Server - almost got it

asked 2009-06-16 07:55:28 +0800

galdasc gravatar image galdasc
33 2

Hello,

I want to use the ZK framework in a Springsource DM Server. Has anyone got this to work or has a suggestion how to go about it?

This is a very important issue to me, since I really want this to work, so I ask you kindly to follow me and try to give me some hints.

Here are the steps I took so far:

I tried to make OSGi bundles out of the ZK jars using the BND tool. After putting them in the \repository\bundles\usr directory, they were properly accepted by the DM Server and listet as ACTIVE. I made a sample ZK application which should just show a window with "Hello World" in it and deployed it onto the server, which didn't thorw any exceptions. I also put in a simple HTML file which I could load without any problems. But when I try to load the .zul file, I get an "javax.servlet.ServletException: Only one layout servlet is allowed in one context" exception. This shows to me, that the ZK servlet is loaded at least twice.

Can anyone please explain, what this message acctually means and give me at least hints (of course solutions are better ;) about how I could solve this problem? What exactly is the "context" the exception refers to?

Thank yout very much in advance!

delete flag offensive retag edit

17 Replies

Sort by ยป oldest newest

answered 2009-06-17 11:00:59 +0800

galdasc gravatar image galdasc
33 2

Well I got it to work (so far, haven't really had time to test it much).

If anyone is interessted in making Spring DM Server resp. OSGi Web applications work with ZK, here ist what I did:

It's pretty much all about making ZKs libraries OSGi-enabled. I used Eclipse for doing this (New Plugin Project from existing JAR, and let Eclipse unpack and analyze the JAR). It generates the MAINFEST.MF automatically. Also do this for the BSH library. Check the MANIFEST.MF files if there are explicit versions on the imports. I removed these and marked some packages optional (e.g. the hibernate ones). Afterwards export each Project as a JAR and explicitly tell Eclipse to use the generated MANIFEST.MF. Put the JARs in "repository\bundles\usr" in your Spring DM Server and they should be available as OSGi bundles.
In your ZK application import these bundles in the MANIFEST.MF and the application should run fine.

link publish delete flag offensive edit

answered 2009-06-18 03:02:54 +0800

PeterKuo gravatar image PeterKuo
481 2

Fantastic !!!
Would you like to write a smalltalk about it?
Our wiki is open and welcome your participation.

link publish delete flag offensive edit

answered 2009-06-19 14:39:25 +0800

galdasc gravatar image galdasc
33 2

I will need to try it out a little bit more and find out a convenient way to work with bigger ZK projects in OSGi environmets. But when I feel like I found a nice solution I will consider writing a smalltalk.

My problem so far is that I want to modularize my web application. I found a similar post in this forum related to pretty much the same thing:
http://www.zkoss.org/forum/index.zul#path%3DlistComment%3BdiscussionId%3D5128%3BcategoryId%3D14%3B
Unfortunatelly this post is one year old, so I will start a new one.

I want to split my whole appilcation into bundles. My vision is to have a main bundle, which provides a basic framework and layout for my ZK application. The only function this bundle should have, is listening for other "addon" bundles and dynamically implementing them into the whole application. The "addon" bundles provide the actual functionality, e.g. one "addon" bundle provides a dialog to input data and stores it into a database, another "addon" bundle retrieves data from the database and displays it on a webpage. These "addon" bundles should be recognized by the listener in the main bundle and automatically included in the application, e.g. with a button or an entry in a menu to show the Dialog and another button or entry in a menu to show the data.

In short terms, I really want to make use of the modular and dynamic approach of OSGi.

Right now I need to figure out how to make the .zul files from one bundle available in another bundle. I haven't found a nice way to handle resources like the .zul files in OSGi well. Has any one an idea how to make this work? I tried exporting the path to the resource as a package (with Export-Package: MODULE-INF.ZUL) and I actually got a valid URL to the .zul files in my MODULE-INF/ZUL/ folder of another bundle. I tried to create the component using

Executions.createComponents(url.toString(),null,null);

where url.toString() gives me the absolute path to the .zul file, but ZK didn't find the file, instead it gave me an exception:

org.zkoss.zk.ui.UiException: Page not found: /file:/C:/springdmserver/.../MODULE-INF/ZUL/north.zul

It seems that ZK automatically adds a / in front of the path, which in this case seems to lead to an invalid path.
Is there a posibility to make the path relative instead of absolute? Are there better ways in ZK to load the ZK component?

link publish delete flag offensive edit

answered 2009-07-25 21:23:17 +0800

tomcat07 gravatar image tomcat07
21 1

Hello,
I also try to run a zk webapplication within an osgi container which is extend by spring webextender. I wrapped all zk and ext jars and the bundles show the status active. If I call a html file it works fine. However when I use a *.zul file it complains something about missing language definition zul even all zk bundles are active and imported.

I found somewhere in the web that zk wont work within an osgi application but you guys seem to have the solution. Can you give some sourcecode as sample?

Thx in advance,
Peter

link publish delete flag offensive edit

answered 2009-08-06 09:18:48 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-08-06 09:19:27 +0800

Yes, all information and experience are welcome.

Like galdasc expalantions of his needs are similar to mine. The planned web application
should have addons and on the other side there are often changes in the code
because legal changes from the market/government.

So it's absolute interessting to update only a little single osgi bundle instead of
deploying the whole .war-file with about 30 MB.

regards
Stephan

link publish delete flag offensive edit

answered 2009-08-08 10:02:05 +0800

galdasc gravatar image galdasc
33 2

Hello,

well to me ZK seems to work with OSGi, I successfully use it. I don't know if you can use all the functionality of ZK, because I just use a smaller subset of it and didn't do any tests yet.

tomcat07, the problem is that ZK doesn't find some of the lang(-addons).xml|*.xml files in other bundles. I used eclipse to turn all the ZK bundles into OSGi bundles (like I described above), except for the zkex jar where I used the bnd tool to create it. The bdn tool seems to export all folders, so the .xml files are exported, too.
I am sorry its been a while and I hope this works for you. If not, I can upload my bundles for you, just let me know.

This works fine for me, I can split my web application into bundles, like one for the model, one for the api, the logic, ..., and one for the web frontend with ZK. This enables you to just update a single "unit" like only the logic or the web frontend, and it is easier and more comfortable than deplyoing "the whole .war-file with about 30 MB." :)

Btw can I configure to get a notification email when someone answeres to my posts? I can't find this option anywhere.

link publish delete flag offensive edit

answered 2009-08-09 14:35:05 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Hmmmm, i mean the notification option is missing in the forum.

At time i have only read about the dm server . I will test it in 2 weeks. For me it's interesting to seperate the frontend in modules too.

regards
Stephan

PS: Can you send me your email adddress.
sge(at)forsthaus(dot)de

link publish delete flag offensive edit

answered 2009-08-11 08:30:01 +0800

Cal gravatar image Cal
6

updated 2009-08-11 08:34:24 +0800

Hi,

I found a way to register both .zul files and richlets on osgi (Felix + Pax Web)

I wrote it here : http://bundle-exception.blogspot.com/2009/07/zk-on-osgi-dynamic-asynchronous.html

link publish delete flag offensive edit

answered 2009-08-13 08:07:43 +0800

galdasc gravatar image galdasc
33 2

Cal, interessting approach. I never worked with Felix or Pax Web, but to me it seems to be a lot of configuration, especially when the web application gets bigger.

I also used to bundelize each zk jar seperatly, which worked fine at the beginning. But I noticed that under some circumstances this doesn't work due to the osgi class and bundle loading mechanism. This is especially the case, when I tried injecting a class derived from the zk Component class into one of my zul files using apply or use, but this class is proxied by another one which does not reside in the zk jars. This results in a "Language not found for extension zul" error because zk seems to look only in the dependent bundles of the current one (the proxy one), but the bundle in which the proxy resides has no dependency to the zk bundles. So I decided to put all the zk jars into one bundle and put these jars onto the bundle-classpath. Then I copied all the export-package and import-package statements from each zk jar bundle into the manifest of the new bundle. This way zk always seems to find the needed .xml configuration files (like lang.xml, lang-addon.xml).

This way it is also easier to update your zk jars to a newer version, since you only have to change the jar files in the bundle (as long as the package structure of the zk jars doesn't change).

link publish delete flag offensive edit

answered 2009-08-13 08:52:15 +0800

Cal gravatar image Cal
6

Yes I ran exactly on the same issue, and I finally copied all zk jars in the bundle of the project. Anyway your solution of making one pure zk bundle that way is definitely nicer :)

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-06-16 07:55:28 +0800

Seen: 1,366 times

Last updated: Apr 06 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More