Fabrizio Giudici is a Senior Java Architect with a long Java experience in the industrial field. He runs Tidalwave, his own consultancy company, and has contributed to Java success stories in a number of fields, including Formula One. Fabrizio often appears as a speaker at international Java conferences such as JavaOne and Devoxx and is member of JUG Milano and the NetBeans Dream Team. Fabrizio is a DZone MVB and is not an employee of DZone and has posted 67 posts at DZone. You can read more from them at their website. View Full User Profile

Using the NetBeans Platform on the Server with Wicket on the Client

01.07.2009
| 34616 views |
  • submit to reddit
Step 4: Configure the Web Deployment Descriptor

The Web deployment descriptor is up to you, since it depends on how many and which frameworks you want to use with your application; each one will need a specific configuration. This is why the code I've just introduced has been packaged as a simple .jar library, rather than a complete .war application. 

For instance, this is how I integrated Wicket in blueOcean:

    <filter>
<filter-name>WicketFilter</filter-name>
<filter-class>it.tidalwave.netbeans.servlet.NetBeansPlatformDecoratorFilter</filter-class>
<init-param>
<param-name>netbeans.filter.delegate</param-name>
<param-value>org.apache.wicket.protocol.http.WicketFilter</param-value>
</init-param>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>it.tidalwave.blueocean.webapp.BlueOceanWebApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>WicketFilter</filter-name>
<url-pattern>/app/*</url-pattern>
</filter-mapping>

As you can see, the instantiated Filter is the decorated one, while the name of the real Wicket filter is passed as a parameter; applicationClassName is instead a Wicket-specific configuration, and of course it is specified too. It's the name of the class that represents the whole application; it's part of a regular Platform module.

This is how I integrated Milton, a server-side WebDAV implementation, that is based on a servlet front controller:

    <servlet>
<servlet-name>MiltonServlet</servlet-name>
<servlet-class>it.tidalwave.netbeans.servlet.NetBeansPlatformDecoratorServlet</servlet-class>
<init-param>
<param-name>netbeans.servlet.delegate</param-name>
<param-value>it.tidalwave.blueocean.milton.MiltonPatchedServlet</param-value>
</init-param>
<init-param>
<param-name>resource.factory.class</param-name>
<param-value>it.tidalwave.blueocean.milton.MiltonResourceFactory</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MiltonServlet</servlet-name>
<url-pattern>/webdav/*</url-pattern>
</servlet-mapping>

In this case, I had to provide a patched version of the Servlet, since Milton unfortunately uses Class.forName(...) to dynamically instantiate classes, instead of using the current class loader (consider this a bug/missing feature of Milton). resource.factory.class is a configuration parameter of Milton somewhat similar to the applicationClassName of Wicket.

REST is not used in blueOcean yet, but it is already used in the customer's project based on it. This is how the web.xml for it looks like:

    <servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>it.tidalwave.netbeans.servlet.NetBeansPlatformDecoratorServlet</servlet-class>
<init-param>
<param-name>netbeans.servlet.delegate</param-name>
<param-value>com.sun.jersey.spi.container.servlet.ServletContainer</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>customer.package1;customer.package2</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

The ServletContainer in Jersey contains an annotation processor (called ResourceConfig), which scans all the classes in the classpath looking for JSR-311-specific annotations. Unfortunately the default implementation expects the classpath to be the default one for web-applications (WEB-INF/lib etc...) so it doesn't work for the integrated Platform. An alternate annotation processor (PackagesResourceConfig) had to be used, in which you explicitly specify the names of the packages that contains JSR-311 annotations. It's an acceptable trade-off for now; it is clearly possible to write a customized ResourceConfig that scans a Platform classpath - but I need to learn more from Jersey before I'm able to write it. 

Published at DZone with permission of Fabrizio Giudici, author and DZone MVB.

(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

In a Wicket application, what is some of the typical functionality that I could let the NetBeans Platform handle?

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.

Aldo Brucale replied on Mon, 2009/01/19 - 8:49am

How can I access org.netbeans.Main from 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

Actually I've never used the o.n.Main from a Platform module - since it's boot code, I've used it from plain JSE code, and of course I've just included the relevant .jar in the path. For what reason do you need to access o.n.Main from a _Platform_ module? Before searching for you a solution to your question, maybe we can find another, better way to do the thing you're trying.

Aldo Brucale replied on Mon, 2009/01/19 - 11:22am in response to: Fabrizio Giudici

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.

Matthew Dempesy replied on Sat, 2011/01/08 - 9:30pm

The module which I was planning to work was purely based on server side application only. I would prefer to use netbeans on my Cloud Hosting server platforms. I have not tried it fully. I would hope that things go cool, without creating much of problems to my head. This writeup which is concerned with the server side process would certainly help me in achieving my goals. If any help I would need I would be here to clear that.

Matt Coleman replied on Thu, 2013/02/21 - 1:09am in response to: Fabrizio Giudici

thanks for explaining this issue Fabrizio..I now understand why

buffalo freelance web designer 

Cata Nic replied on Tue, 2013/09/03 - 3:17am

 Is it possible to use a CDN solution for that. I mean... it will be useful to offer a part of the data via a CDN.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.