The cviewer-javaee6 sample includes a JSP file that calls a servlet. A form allows the user to enter a java class name.Then a filter will catch the class name and turn null or invalid class name into fully qualified class name. The servlet uses java reflection to extract information about the class which, in turn, is returned to the user.
This sample will demonstrate the programmatically adding and configuring servlets and filters features in Servlet 3.0.
The ability to programmatically add a servlet to a context is useful for framework developers. A framework could declare a controller servlet using this method. The return value of this method is a ServletRegistration.Dynamic object further allows you to set up the other parameters of the servlet like init-params, url-mappings during ServletContext initialization.
The cviewer application consists of following list of packages and classes.
The list of web application files in the application is depicted in the following.
geronimo-web.xml specifies the module's information and the url for the web application
Information about the project sucha as module's unique identification, dependencies is described inside the <sys:environment/> tags. It is a good practise to give a module an unique identification, so that it can later be referenced by some other deployable application. This module is in the group org.apache.geronimo.samples. The path specified in the <context-root> tag will be the entry point of this web application. Therefore you can access this web application at http://<hostname>:<port>/cviewer-javaee6.
CviewerServletListener.java is a web listener which implements ServletContextListen,it will programmatically register a servlet and filter.
Please reference Samples General Information for information on obtaining and building the source for this and other samples.
Once all the sources get checked out the next step is to build cviewer-javaee6. It requires Maven 2 for building the binaries.
From the <cviewer-javaee6_home> directory run the following command.
mvn clean install
This process will take a couple of minutes. The binaries will be generated in the corresponding target directory .
Deploying sample application is pretty straight forward as we are going to use the Geronimo Console.
The app is visible at http://localhost:8080/cviewer-javaee6/
Input java class name you want to query for detail information,for example java.util.ArrayList.
If the class name is null or in bad format,filter will change it to java.lang.Integer or java.lang.String by default.The servlet will display detail information of the class.