Monitor HTTP Requests on JBoss 4 from NetBeans IDE 4.1
By Geertjan on Apr 19, 2005
NetBeans IDE provides a built-in HTTP Monitor to help isolate problems with data flow from JSP and servlet execution on a Web server. There is no need to add logic to your Web application to trace HTTP requests and associated state information. The NetBeans IDE built-in HTTP Monitor can do this for you. When the IDE is configured with a Web container or a Web application is deployed with a NetBeans HTTP Monitor servlet filter and filter mapping, the HTTP Monitor will automatically record all HTTP requests made to the Web container. For each HTTP request that is processed by the Web container, the HTTP Monitor not only records the request, it also records state information maintained in the Web container. By using the HTTP Monitor, you can analyze HTTP requests, and store HTTP GET and HTTP POST requests for future analysis sessions. You can also edit these stored requests and replay them. This is a powerful feature to help isolate data flow and state information passed within an HTTP request to a Web container. HTTP requests are stored until you exit the IDE unless you explicitly save them.The HTTP Monitor is easily enabled if the server you're using is registered in NetBeans IDE 4.1. Only the Sun Java System Application Server and the Tomcat Web Server can be registered in IDE 4.1. JBoss can't. But does that mean that we can't use the HTTP Monitor with JBoss? No, it doesn't. The steps to set it up are reasonably simple (and are also described in the IDE's own help system):
Right-click the project's Libraries node in the Projects window. Choose Add JAR/Folder and add the following JARs:
Build the project. When you build a standard project, the JARs get moved to the build/web/WEB-INF/lib folder. This is very important to know because, when you build the project to JBoss's deployment directory, at the end of these instructions, you must include these JAR files. Knowing the exact location to which the IDE moves the JAR files allows you to create the appropriate Ant build script to copy them to JBoss.
In the IDE, go to the web.xml file and double-click it. The cool (new in NetBeans IDE 4.1) web.xml Visual Editor opens in the Source Editor. Go to the Filters tab at the top of the editor, click Add Filter Element, and add the following values:
- Filter Name: HTTPMonitorFilter
- Filter Class: org.netbeans.modules.web.monitor.server.MonitorFilter
Click OK, click on Add in the "Initialization Parameters" subsection, and add the following values:
- Param Name: netbeans.monitor.ide
- Param Value: name-of-host-that-runs-IDE:port-of-internal-HTTP-server
To find out the port of the internal HTTP Server, go to the Runtime window, right-click the HTTP Server node, choose Properties, et voila, there it is. For me, it is set to 8086 (probably the default, at least for Windows).
Click OK, click on the Filter Mappings header below, click Add, and add the following values:
- Filter Name: HTTPMonitorFilter
- URL Pattern: /\*
- Dispatcher Types: REQUEST, FORWARD, INCLUDE, ERROR
Click OK. You should now have the following in the web.xml Visual Editor:
And when you click XML at the top of the editor, the following will be included in the web.xml file:
<filter> <filter-name>HTTPMonitorFilter</filter-name> <filter-class>org.netbeans.modules.web.monitor.server.MonitorFilter</filter-class> <init-param> <param-name>netbeans.monitor.ide</param-name> <param-value>localhost:8086</param-value> </init-param> </filter> <filter-mapping> <filter-name>HTTPMonitorFilter</filter-name> <url-pattern>/\*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping>
Go to the Runtime window, right-click the HTTP Server, and click Start Server.
Now build and deploy your application to JBoss. Remember that you need the JAR files that you picked up in step 1 to be included with the resources that you've copied to JBoss's deployment directory! When you run the application, the HTTP Monitor will start up in the IDE:
Now you can do any and all of the following:
- Analyze HTTP requests records.
- Save HTTP request records.
- Edit HTTP request records.
- Refresh request records.
- Sort HTTP request records.
- Delete HTTP request records.
- Replay HTTP request records.
Two very important notes:
- Whenever you restart the IDE, you should also restart the HTTP Server, if you want to use the HTTP Monitor with JBoss (or any other server other than the Tomcat Web Server). What I did, a few times, is exit the IDE, restart the IDE, build and deploy to JBoss, and then wonder: "Huh? Where's the HTTP Monitor?" The reason why it didn't appear was because I hadn't restarted the HTTP Server...
- Since the HTTP Monitor is used to debug in the pre-production phase of your development cycle, remember that when you deploy the application to a production server, you should remove the JAR files from your project and remove the filter and filter mapping declarations from the web.xml file.
A good application to test all of this out on is the "Midnight Cookie" application, which is what you end up with at the end of the NetBeans IDE 4.1 Tutorial for Web Applications. In fact, the second part of that tutorial provides extensive information, including many screenshots, on the various things you can do with the HTTP Monitor.