Monitoring HTTP connections

Another tool that NetBeans provides users without all of the fuss of installing many different plugins and configuration files is the HTTP Server Monitor.

Although basic it mostly covers the main needs of a developer on the day-to-day case.

The NetBeans HTTP Server Monitor helps the developer to interact with HTTP requests, analyze cookies and headers, save and replay sessions, and more.

Getting ready

NetBeans HTTP Monitor is enabled by default if the project is deployed onto Apache Tomcat.

This is a bit different if using GlassFish.

Since we will use GlassFish for this recipe follow the instructions below:

  1. Navigate to the Services window.
  2. Expand the Servers node, right-click on GlassFish Server and select Properties.
  3. On Servers dialog under the Common tab select Enable HTTP Monitor.
    Getting ready
  4. Click Close.

How to do it...

Now follow the steps below to create a project that will be used to demonstrate the HTTP Monitor:

  1. Create a New Project, by either; clicking File and then New Project or pressing Ctrl+Shift+N.
  2. On New Project window on categories side choose Java Web and on Projects side select Web Application and click Next >.
  3. Under Name and Location: Name the project as WebApplicationCookbook and click Next >.
  4. Under Server and Settings: Click Finish.
  5. With the project created, right-click WebApplicationCookbook and select Run.

How it works...

When running the application, NetBeans fires up the HTTP Server Monitor (if it's not visible, hit Ctrl+Shift+5). The HTTP Server Monitor is used to analyze the information that is exchanged between the browser and the Application Server in real-time.

How it works...

On the left-hand side of the panel, under Current Records, are listed the requests made from the client to the browser. By clicking on a request, the information related to that particular request is presented. There are a number of tabs that can be used to filter the information:

  • Request
  • Cookies
  • Session
  • Context
  • Client and Server
  • Headers

There's more...

It is possible to edit requests and re-use them.

Editing HTTP requests from within NetBeans

It is also possible to right-click on each individual request and choose Save, Replay, Edit and Replay..., and Delete.

To perform any of these actions, right-click on the request and choose the desired action.

The Save action will move the request from the Current Records folder into the Saved Records:

Editing HTTP requests from within NetBeans

Replay will re-send the selected request to the server. This is useful when checking the outcome of the selected functionality.

Selecting Edit and Replay..., will let the user edit the request, change parameters, request methods, request URI, and so on before re-sending.

The Edit and Replay tab lets the developer add query parameters simply by clicking the Add Parameter button, then selecting a name and value for the given parameter.

Editing HTTP requests from within NetBeans

The Request tab gives the developer the power to change the request to one of these three HTTP request methods:

  • PUT
  • POST
  • GET

Changing the URI and the Protocol can be done by double-clicking the rightmost part of the parameter in the UI.

This will make the IDE pop up a dialog asking for the corrected value.

Editing HTTP requests from within NetBeans

The Cookies tab, as with the Query tab, has a very straightforward operation; click on the Add Cookie button and enter the request information to add a cookie to your next request.

The Server tab relates to where the request will be heading. Mostly this information won't change since the development and deployment is done mainly on the localhost machine, but supposing that some machine in the same network might also be holding the application this is where to "redirect" the request to the other machine.

Here Hostname and Port Number of HTTP Service are the options. Double-clicking the rightmost part of the row, denoted by the three dots (...), will display a dialog where the information can be changed.

Editing HTTP requests from within NetBeans

Various headers are present in the Headers tab and the addition, editing, and deletion of headers is possible.

Both addition and deletion can be executed by the down most buttons and the edition by double-click the rightmost part of the row, denoted by the three dots (…).

Editing HTTP requests from within NetBeans

Once a request has been edited, just click on Send HTTP Request and the modified request will be on its way.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.167.161