Monitoring HTTP Transactions


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, but 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. You can also save them so that they are available in subsequent IDE sessions.

Following are some of the things that you can do with the IDE's HTTP Monitor:

  • Analyze HTTP request records

  • Save HTTP request records

  • Edit HTTP request records

  • Refresh HTTP request records

  • Sort HTTP request records

  • Delete HTTP request records

  • Replay HTTP request records

In the following sections, you will learn how to set up the HTTP Monitor, analyze the data the HTTP Monitor collects, and replay recorded HTTP requests.

Setting up the HTTP Monitor

When you run a web application and the HTTP Monitor is enabled, the HTTP Monitor should appear at the bottom of the IDE. The HTTP Monitor generally is automatically enabled for Tomcat, but not for Sun Java System Application Server or for other application servers.

For JBoss, WebLogic, WebSphere, and other applications servers, the HTTP Monitor can be used by following the instructions to set up the HTTP Monitor for servers started outside NetBeans IDE later in this chapter.


If the HTTP Monitor is not displayed at the bottom of the IDE when you run an application, you can enable it by performing the following tasks.

1.

Expand the Runtime window's Servers node to show your registered web server. Then right-click the server's node and choose Properties.

2.

Select the Enable HTTP Monitor checkbox.

3.

If the registered web server is currently running, stop and restart it by right-clicking your registered web server under the Runtime window's Servers node and selecting Start / Stop Server.

Figure 8-7 shows the Enable HTTP Monitor property in the Sun Java System Application Server 8 Properties dialog box.

Figure 8-7. Properties dialog box for the Sun Java System Application Server


Setting up the HTTP Monitor for Servers Started Outside of the IDE

You can also use the HTTP Monitor on web servers started outside the IDE. To do so, execute the following tasks:

1.

Go to the directory where the IDE is installed, and copy the modules/org-netbeans-modules-schema2beans.jar and modules/org-netbeans-modules-web-httpmonitor.jar files to your web module's WEB-INF/lib directory.

2.

Add a filter declaration that is appropriate for your servlet's version to the top of your web module's WEB-INF/web.xml file.

Filters and filter mapping entries must be specified at the beginning of a deployment descriptor. See the examples below for filters for the servlets corresponding to the 2.3 and 2.4 versions of the Servlet specification.

A Servlet 2.4 filter declaration might look like the following:

   <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>          name-of-host-running NetBeans IDE:http-server-port        </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>


A Servlet 2.3 filter declaration might look like the following:

    <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>           name-of-host-running NetBeans IDE:http-server-port            </param-value>          </init-param>         </filter>         <filter-mapping>           <filter-name>             HTTPMonitorFilter           </filter-name>           <url-pattern>             /*           </url-pattern>         </filter-mapping>


A web application can be monitored with the IDE HTTP Monitor from multiple running NetBeans IDEs by adding more init-param entries to the servlet filter declaration in the web deployment descriptor. For instance, you would add an init-param entry such as the one shown below:

    <init-param>       <param-name>         netbeans.monitor.ide       </param-name>       <param-value>         name-of-2nd-host-running NetBeans IDE:http-server-port       </param-value>     </init-param>


When you deploy the web module you have been monitoring with the HTTP Monitor to a production server, remember to remove the Servlet filter and filter mapping declarations from the web module's deployment descriptor. Otherwise, the web module will be open for HTTP monitoring from those NetBeans IDEs specified in the init-param section(s) of the servlet filter in the web module's deployment descriptor.


Analyzing the Collected Data

After you have set up the HTTP Monitor, you can use the HTTP Monitor to debug your web application by observing data flow from your JSP page and servlet execution on the web server. The HTTP Monitor records data about each incoming request. The HTTP Monitor is automatically displayed at the bottom of the IDE. A snapshot of the HTTP Monitor is shown in Figure 8-8.

Figure 8-8. HTTP Monitor


The HTTP Monitor consists of two panels. On the left is a tree view of HTTP request records. Every HTTP request made to the HTTP server is recorded in the HTTP Monitor. Requests resulting from internal dispatches are reflected by nested nodes under those web containers that support it. In addition, forwarded or included requests are nested under the node corresponding to the main request.

Displayed in the right panel of the HTTP Monitor is additional data for a selected HTTP request record in the left panel. When you select an HTTP request record on the left, session data corresponding to the selected record is displayed in the right panel. The additional session information available in the right panel includes detailed request information; cookie name/value pairs; session data; servlet context attributes; initialization parameters; and client/ server information, such as client protocol, client IP address, server plat-form, and server hostname, along with additional HTTP request header information. The right panel allows you to view specific data in each of these categories by selecting a tab corresponding to the information you would like to see. Figure 8-9 shows the additional session information for a selected HTTP request record.

Figure 8-9. HTTP Monitor with a record selected and its request data displayed


In the tree view (left panel of the HTTP Monitor) are two categories of records that you can view: Current Records and Saved Records. The Current Records category represents HTTP request records collected since the IDE has been started. Current records persist across restarts of the web server but not across restarts of the IDE. To persist current records across IDE restarts, you must save those records. Individual current records may be saved by selecting an HTTP request record, right-clicking the selected current record, and choosing Save from the contextual menu. You can select multiple HTTP request records by pressing the Shift key or Ctrl key. Figure 8-10 illustrates the selecting and saving of multiple HTTP requests.

Figure 8-10. Saving multiple records in the HTTP Monitor


Notice that when you save HTTP requests, the selected records are moved to the Saved Records category. The selected records are not copied. Keep this in mind should you want to replay a sequence of HTTP requests.

The tree view (left panel of the HTTP Monitor) also provides several options for viewing the HTTP requests in the upper-left portion of the panel, in the form of five buttons. For example, you can reload all the HTTP request records, sort the HTTP request records by timestamp in descending or ascending order, sort the records alphabetically, and show or hide the timestamp for each HTTP request record. Table 8-4 summarizes the action of each button.

Table 8-4. HTTP Monitor Toolbar Buttons

Request Record View Button

Action

reload

Reloads all the HTTP request records currently stored

descending sort

Sorts HTTP request records by timestamp in descending order

ascending sort

Sorts HTTP request records by timestamp in ascending order

alphabetically sort

Sorts the HTTP request records alphabetically

time stamp

Hides or displays the timestamps in the list of HTTP requests


In addition to being saved, HTTP records may be deleted. The IDE provides much flexibility for deleting HTTP records. For example, individual and multiple current records or all current records may be deleted. Individual saved records, multiple saved records, or all saved records can also be deleted.

To remove a record, right-click the record to be deleted and choose the Delete option from the contextual menu. To remove multiple records, select additional records, using the Shift or Ctrl key; then right-click the selected records and choose the Delete option from the contextual menu. To remove all current records, right-click the current records folder and choose the Delete option. To remove all Saved Records, right-click the Saved Records folder and choose the Delete option from the contextual menu.

Replaying HTTP Requests

The most powerful feature of the HTTP Monitor is the editing and replaying of HTTP requests. By editing and replaying HTTP requests, you can quickly and easily trace and diagnose problems with the flow of data from JSP pages and servlet execution on the web server. When you replay an HTTP request, the response appears in your web browser. Thus you can track the result of a given HTTP request by having it replayed in your web browser.

The IDE opens your default web browser when you replay HTTP requests. If the IDE cannot find the operating system's default web browser, you can configure the web browser manually. See Changing the IDE's Default Web Browser earlier in this chapter.


Both current records and saved records may be replayed. To replay an HTTP request, select the HTTP request to replay in the left panel (tree view) and choose the Replay option from the contextual menu. Figure 8-11 shows a Current Record being selected for replay.

Figure 8-11. Selecting a record to be replayed in the HTTP Monitor


Notice that the selected record is replayed in your browser after you have chosen Replay from the contextual menu.

In addition to replaying HTTP requests, you can edit an HTTP request before replaying it. To do so, select an HTTP request in the left panel (tree view)either a Current Record or Saved Recordright-click the record, and choose the Edit and Replay option from the contextual menu. After you choose the Edit and Replay option, a dialog box is displayed, where you can make various modifications.

The supported modifications in the edit and replay of an HTTP request include options to edit a parameter to query, modify request URI parameters, modify cookies, modify server execution properties, and modify HTTP request parameters.

On the Query tab (see Figure 8-12), you can add a query parameter or delete a query parameter and modify URI request parameters. On the Request tab, you can modify the request URI by selecting the ellipsis (...) button next to the request parameter value. You can change the request method from a GET to a POST or PUT by selecting from the combo box to the right of the Request Method type in the left column. If you click the ellipsis button in the request protocol's far-right column, the Request Edit Property dialog box appears, which enables you to modify the request protocol. On the Cookies tab, you can add modify or delete cookies associated with the HTTP request. On the Server tab, you can modify server execution values, such as the hostname and port where the HTTP request should be executed. You can add, modify, and delete HTTP headers in the Headers tab.

Figure 8-12. HTTP Monitor Edit and Replay dialog box


After making your desired edits to the HTTP request, you can replay the modified request by clicking the Send HTTP Request button. The resulting HTTP request and response is sent to your web browser, where the results are displayed.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net