Tuesday August 11, 2009
TOTD #91: Applying Java EE 6 "web-fragment.xml" to Apache Wicket - Deploy on GlassFish v3
"Extensibility" is a major theme of Java EE 6.
This theme enables seamless pluggability of other popular Web
frameworks with Java EE 6.
Before
Java EE 6, these frameworks have to rely upon registering servlet
listeners/filters in "web.xml" or some other similar mechanism to
register the framework with the Web container. Thus your application
and framework deployment descriptors are mixed together. As an
application developer you need to figure out the magical descriptors of
the framework that will make this registration.
What if you are
using multiple frameworks ? Then "web.xml" need to have multiple of
those listeners/servlets. So your deployment descriptor becomes
daunting and maintenance nightmare even before any application
deployment artifacts are added.
Instead you should focus on your
application descriptors and let the framework developer provide the
descriptors along with their jar file so that the registration is
indeed magical.
For that, the Servlet
3.0 specification introduces "web module deployment
descriptor fragment" (aka "web-fragment.xml"). The spec defines it as:
A
web fragment is a logical partitioning of the web app in such a way
that the frameworks being used within the web app can define all the
artifacts without asking devlopers to edit or add information in the
web.xml.
Basically, the framework configuration
deployment descriptor can now be defined in "META-INF/web-fragment.xml"
in the JAR file of the framework. The Web container picks up and use
the configuration for registering the framework. The spec clearly
defines the rules around ordering, duplicates and other complexities.
TOTD
#86 explained how to get started with Apache Wicket on
GlassFish. This Tip Of The Day (TOTD) explains
how to
leverage "web-fragment.xml" to deploy a Wicket application on
GlassFish v3. The basic concepts are also discussed here.
For the "Hello World" app discussed in TOTD
#86, the generated "web.xml" looks like:
| <?xml version="1.0"
encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>helloworld</display-name> <!-- There are three means to configure Wickets configuration mode and they are tested in the order given. 1) A system property: -Dwicket.configuration 2) servlet specific <init-param> 3) context specific <context-param> The value might be either "development" (reloading when templates change) or "deployment". If no configuration is found, "development" is the default. --> <filter> <filter-name>wicket.helloworld</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>org.glassfish.samples.WicketApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.helloworld</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> |
|
<dependencies> . . . <!-- web-fragment --> <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>wicket-quickstart-web-fragment</artifactId> <version>1.0</version> <scope>runtime</scope> </dependency> </dependencies> . . . <repositories> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/2/</url> </repository> </repositories> |
| <web-fragment> <filter> <filter-name>wicket.helloworld</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>org.glassfish.samples.WicketApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.helloworld</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-fragment> |
|
<plugins> . . . <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> . . . </plugins> |
| helloworld-1.0-SNAPSHOT helloworld-1.0-SNAPSHOT/META-INF helloworld-1.0-SNAPSHOT/WEB-INF helloworld-1.0-SNAPSHOT/WEB-INF/classes helloworld-1.0-SNAPSHOT/WEB-INF/classes/log4j.properties helloworld-1.0-SNAPSHOT/WEB-INF/classes/org helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/HomePage.class helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/HomePage.html helloworld-1.0-SNAPSHOT/WEB-INF/classes/org/glassfish/samples/WicketApplication.class helloworld-1.0-SNAPSHOT/WEB-INF/lib helloworld-1.0-SNAPSHOT/WEB-INF/lib/log4j-1.2.14.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/slf4j-api-1.4.2.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/slf4j-log4j12-1.4.2.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/wicket-1.4.0.jar helloworld-1.0-SNAPSHOT/WEB-INF/lib/wicket-quickstart-web-fragment-1.0.jar |

Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Today's Page Hits: 2031
Total # blog entries: 1024
Thanks for keeping us up to date with Java EE and Wicket. Yes I am deploying Wicket on GlassFish. However there is an issue with @EJB annotation, where developer productivity becomes poor, and we need support and clarification there otherwise Wicket is probably not going to co-exist with Glassfish and probably not even with EJB in general. Please refer to https://issues.apache.org/jira/browse/WICKET-2416.
Best regards
Bernard
Posted by Bernard on August 11, 2009 at 02:18 PM PDT #
https://issues.apache.org/jira/browse/WICKET-2416
No dot this time
Posted by Bernard on August 11, 2009 at 02:20 PM PDT #
Bernard, Thanks for your response.
I'm following up with the team and let you know after I hear back.
Posted by Arun Gupta on August 11, 2009 at 03:35 PM PDT #
Nice blog, Arun!
Note that org.apache.wicket.protocol.http.WicketFilter could be simplified substantially by using some of the new Servlet 3.0 registration and lookup APIs.
In its current form, WicketFilter#init attempts to parse the web.xml to see if it contains any <filter-mapping> elements with url patterns for the filter named wicket.helloworld.
Servlet 3.0 would simplify this job. All that is needed is the following code snippet inside WicketFilter#init:
FilterRegistration reg = filterConfig.getServletContext().getFilterRegistration("wicket.helloworld");
if (reg != null) {
Collection<String> urlPatterns = reg.getUrlPatternMappings();
[...]
}
Posted by Jan Luehe on August 11, 2009 at 06:33 PM PDT #
Visa hänsyn till din partners barn om hon/han har barn sedan tidigare. Finns inget vidrigare en make som behandlar barn illa.
Posted by skilsmässa on August 12, 2009 at 03:04 AM PDT #