Using the NetBeans Platform on the Server with Wicket on the Client
Step 1: Prepare the Wrapper Modules
Since you are going to completely develop a web application as a componentized NetBeans Platform application, all of the required libraries and frameworks need to be placed in NetBeans Module Wrappers. These are the ones I prepared for blueOcean (you can see them in the Libraries folder):
- ServletAPI (servlet-api.jar) for the basic web functions.
- Wicket and WicketExtensions for the Wicket framework.
- JSR311, Jersey and Jettison for REST features (plus JSON support).
- Milton for the WebDAV interface.
- Libraries required by the above listed stuff (e.g. SLF4J, ASM, GlazedLists, Apache Commons Fileupload etc..., as specified by each framework documentation).
Be especially careful in step #5, that is, make sure that all the dependencies are satisfied (so, for instance, the Wicket Module declares a dependency on SLF4J, Jersey on JSR311 and ASM, etc), otherwise you'll get some ClassNotFound exceptions / errors that can be tricky to understand (they will refer to classes that actually are in the classpath, but have missing dependencies).
For reasons that will be explained soon, you need an extra thing for each framework: any framework-relevant Servlet or Filter (usually one per framework, described in their documentation) must be registered as a META-INF service. To accomplish that, you need to create a META-INF/services directory with the following files (for Wicket, Jersey and Milton):
org.apache.wicket.protocol.http.WicketFilter
com.bradmcevoy.http.MiltonServlet
com.sun.jersey.spi.container.servlet.ServletContainer
Each file must be composed of a single line containing the same text as the file name.
Step 2: Develop Your Application
Now you can create your application as usual, using the required APIs as appropriate. That is, for creating the User Interface you create new Modules that declare a dependency on Servlet API and Wicket, and so on. A potential source of troubles is where to place the HTML files for the UI: with Wicket (that I like for many reasons, including the one I'm telling you now) they can stay in the same folder as .java sources and get packed into Java binaries, since they will be accessed at runtime as resources. I didn't investigate other scenarios, for instance JSPs, where the web pages must be placed in a specific directory separate from code.
Step 3: Create a Web Application Wrapper
Now, the most interesting part. You need to create the "glue" between Tomcat and your Platform based application; and since I like to do things in the standard way, I like to have this glue to take the form of a regular .war application, that can be deployed as usual. Keep in mind that you have many variants: the .war could be all-inclusive, that is it would include your application AND the platform, or it could merely point to a platform that is placed in some other place. The latter solution, for instance, would allow to add and remove modules by means of the NetBeans Update Centers, instead of redeploying a new .war. It's up to you. As a starting point, and also because at the moment I don't need Update Centers, I've gone the way of the all-inclusive .war file.
The basic point of "glueing" is about class loaders: both Tomcat and the Platform have their own class loaders. How to connect them? The lucky thing is that the interface between Tomcat and a Web Application is mainly composed of only two things: Servlets and/or Filters. Most of the web frameworks around just need to declare a Servlet or a Filter in the web.xml file, and those components will act as a single "front controller" from the framework.
So my solution is to provide a pair of universal decorators (a Servlet and a Filter) that create a bridge between the two worlds. I've put them in a very small JSE library that, as you'll see later, just needs to be included in a .war project and configured (the sources can be checked out from https://blueocean.dev.java.net/svn/blueocean/trunk/src/NetBeansPlatformWebAdapter, revision 11).
- Login or register to post comments
- 10939 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
harris goldstone replied on Fri, 2009/01/09 - 3:25pm
Fabrizio Giudici replied on Sun, 2009/01/11 - 7:12am
Hi Harris.
At the moment, the great advantage is for what concerns the tier of services and models, that is the business tier. It is something that can be best clarified by examples, and I'll post some in future here on DZone (also with other two "series" of posts about NetBeans Platform Idioms etc...); for the moment, take this small one: I have a Metadata infrastructure that allow to extract metadata from media (e.g. photos), eventually store them in a database, where they can be searched for. Every kind of metadata (EXIF, IPTC, whatever) is implemented by separate modules, as well as persistence in the database is enabled by just adding specific modules, without requiring any configuration. This means that I can easily satisfy different needs (blueMarine itself, blueOcean base, blueOcean as used by my customer, and hopefully other future customers) by just assembling different set of modules in specific custom platforms. This has been achieved mostly by means of the Lookup API (and in future I could use more the layer.xml facility). Most of this stuff could be used also by taking simple .jars as libraries out of the NetBeans Platform; but as the number of configurations increases, it is really important to have the capability of checking compatibilities and dependencies among modules. You could be always safe with a good testing, but in any case I appreciate when a static tool finds / prevents problems as early as possible. Furthermore, having the very same process for two different projects is a big time saver for me.
There are two different uses of the Platform that I'll evaluate soon. First is the "Event Bus" (based on "Central Lookup" by Wade Chandler) that I've talked about a few months ago; in blueMarine it introduces another great deal of decoupling that in the customer's project based on blueOcean I don't have yet. While the Event Bus as is works fine with a single user (it is a singleton), it must be adapted in the case of concurrency (it should be enough to write a variant based on ThreadLocal). Second is about the use of Nodes for a number of things, including dynamic generation of menus based on the functions that you have dynamically included in the current configuration. This is more sensible because of the cited potential problem with the AWT Thread, which would be a serious bottleneck on the server side.
aldobrucale replied on Mon, 2009/01/19 - 8:49am
org.netbeans.Mainfrom my module? It belongs to the Bootstrap module, but when I add this dependency and try to compile, the build system says that the module containing NetBeansPlatformUtils "is not a friend of<nb-platform-dir>/nbbuild/netbeans/platform9/lib/boot.jar".Fabrizio Giudici replied on Mon, 2009/01/19 - 9:08am
aldobrucale replied on Mon, 2009/01/19 - 11:22am
in response to: fabriziogiudici
Thank you Fabrizio, of course a module cannot boot the application that is supposed to load it!
I placed the servlet in a regular web project, now it works perfectly. Very interesting, thank you.