Geertjan's Blog

  • April 20, 2005

Monitor HTTP Requests on JBoss 4 from NetBeans IDE 4.1

Geertjan Wielenga
Product Manager
So now that I can start JBoss and stop JBoss from the IDE, generate JBoss deployment descriptors from the IDE, deploy an application from the IDE to JBoss, and use the NetBeans IDE debugger to connect to JBoss and debug my application (as explained in previous blog entries), there's nothing more I can do to integrate JBoss with NetBeans IDE 4.1. Right? Wrong. There's also the cool HTTP Monitor which, according to the final section of "Chapter 6: Web Applications" in the NetBeans IDE Field Guide - Draft Chapters, is cool for the following reasons:

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):

  1. Right-click the project's Libraries node in the Projects window. Choose Add JAR/Folder and add the following JARs:

  2. 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.

  3. 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:

  4. Go to the Runtime window, right-click the HTTP Server, and click Start Server.

  5. 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.

Join the discussion

Comments ( 1 )
  • Shantanu Friday, June 16, 2006
    Hi Expert,
    I am trying to implement SSO using netbeans for my web-based application. Kindly let me know how I can achieve it.
    The client interface is the browser..
    Kindly help me in this regard
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.