Sunday, 29 April 2007

Handy JDeveloper utility: the Http Analyzer

One of the useful little tools included with JDeveloper is the Http Analyzer, accessible via the View -> Http Analyzer menu option.

The Http Analyzer acts very similar to a network packet sniffer, allowing you to capture and inspect HTTP request and response pairs sent between a web client and web server.

One example where you would use the Http Analyzer is when developing ADF Faces applications in JDeveloper, where the Http Analyzer is sniffing the information flowing between your browser and the active FacesServlet in the Embedded OC4J. You can also use it between any web client request on your machine and any web server anywhere assuming you can normally connect to the service via your browser/local-machine.

There are other Http Analyzers out there, but given with JDeveloper its free and you don't have to download and install yet another tool.

Starting the Http Analyzer

I'll describe a typical scenario in developing an ADF Faces application and using the Http Analyzer to help describe how it's used.

I have an ADF Faces web application that is currently running in JDeveloper and displayed in my local browser at the following URL:

http://127.0.0.1:8988/HttpAnalyzerDemo/faces/editEvents.jspx

http://127.0.0.1:8988 is the port number the Embedded OC4J is currently listening on from my localhost. Accessing this sub-URL directly in my browser displays the Welcome page for the running Embedded OC4J server. The Embedded OC4J port number can be changed via the Tools -> Embedded OC4J Server Preferences menu option, selecting the Global -> Startup dialog options, then the HTTP field.

Next we open the Http Analyzer window via the View -> Http Analyzer menu option:

In order for the Http Analyzer to work we need to start a listener process, by selecting the Start Http Analyzer button (the green arrow button) in the Http Analyzer window. By default this will start the listener on your localhost's hostname on port 8098. These default settings can be changed via selecting the New Listener button in the Http Analyzer window:

In this example you can see the Http Analyzer listener process will be listening at the following URL: http://acute:8098 .... where acute is my localhost name. In turn the listener options configure any request to this URL will be redirected to the Target URL: http://127.0.0.1:8988

As this is the URL of my running Embedded OC4J server from previous, any access to the Http Analyzer listener at http://acute:8098 will be redirected to the Embedded OC4J URL at http://127.0.0.1:8988

Note when you run the Analyzer you may see a warning message. I'm still not sure why this message displays as the Analyzer appears to work regardless.

Now with the Http Analyzer listener running, if I change my original URL in my browser to use the Http Analyzer instead and load the page:

http://acute:8098/HttpAnalyzerDemo/faces/editEvents.jspx

....I see two effects. First the ADF Faces web-page is correctly displayed in the browser from this alternative URL, and secondly the Http Analyzer window is now showing my first Http request-response as requested by my browser, and served via the FacesServlet running in my Embedded OC4J.

Using the Http Analyzer

This layout in the Http Analyzer is by default the history view. As you interact with your application through the browser, a number of request/responses in chronological order will display in the Http Analyzer history view.

The history view reveals a number of interesting elements:

  • Call Time - the total time of the request/response in milliseconds
  • Method - the type of Http request/response method
  • Url - the specific URL that was requested
  • Query - dunno
  • Cookie - any cookies passed between the client to the server
  • Status - the Http error code
  • Set-Cookie - any cookies set by the server and passed to the client
  • Type - type of request, for example Html, Images etc
  • Size - the size of the response in bytes

From here you may select a specific request/response and switch the Http Analyzer into the data view. You do this by double clicking on one of the entries in the history view, or selecting the Data tab at the bottom of the Http Analyzer window.

The data view is divided vertically into 2 areas, on the left hand-side the request sent from the client to the server, and on the right hand-side the response from server to the client.

If for both areas the Show Headers checkbox is also checked, the window is further divided horizontally showing on top the Http header information passed between the client and server on each request/response, and on the bottom the actual data body of the Http request or response between the client and server respectively.

Further to this the data represented on the client or server side can be represented differently visually by selecting the View dropdown on each side. Its options include:

  • Content - displays a visual representation of the data packet passed in the request/response -- for a Html page it will show a visual representation of the Html components, or for images the actual image itself.
  • Raw - displays the pure data flowing backwards and forwards as text
  • Hex - shows the data as hex values

Personally I find the Content and Hex views less useful than the Raw option when viewing a Html request/response. However the Raw option doesn't wrap in the Http Analyzer window making it poorly readable, and I typically copy & paste the Raw text data into my favourite text editor with wrapping turned on to read the response.

Interesting things to do with Http Analyzer

So why is the Http Analyzer useful? Some uses include:

  1. Recording a history of request/responses to detect and replicate bugs
  2. Analyzing the time taken for a request/response on a particular page
  3. Analyzing the size of a page and its effect on client's with slow internet connections
  4. Inspecting and detecting issues with the Http request/response headers
  5. Estimating the bandwidth required for a popular page requested by your application
  6. Detecting unusual error conditions returned by the server beyond 404 Page not found
  7. Analyzing issues where the client POST request is terminated 1/2 way

.... also, and not discussed here, the Http Analyzer can be used for debugging Web Service calls, and actually modifying the Soap packet.

I'd be curious to know what uses others have found for the Http Analyzer. I've seen some particularly tricky debugging made simple by this tool.

Further documentation

The Http Analyzer documentation is not well indexed in Oracle's JDeveloper online documentation. Rather than searching for entries under the online Index help option, instead under the help Search option, search for "Analyzer" to find more documentation, including the "About the Http Analyzer" help page.

4 comments:

Gerard Davison said...

Chris,

Nice article, I work in the team that implements this feature and would be interested to hear about any enhancement requests you might have.

Also we are working on a preview release for JavaOne which may include some ehancements in the HTTP Analyzer that you might find usefull.

Gerard Davison
Gerard.Davison@oracle.com

Anonymous said...

Chris,

Your article is very interesting.
I have your steps but with jdev11 tp2.
With a very simple case, I get this error message :
JDeveloper HTTP Analyzer encountered an error retrieving:

GET http://vaio-portable:8099/Protectia1-ViewController-context-root/faces/pprDeclaratif2.jspx?_adf.winId=1826625445_4&_adf.ctrl-state=1826625445_3 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: fr-FR,en-GB;q=0.7,en-US;q=0.3
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1)
Host: 192.168.1.4:8099
Connection: Keep-Alive
Cookie: JSESSIONID=cd191ac74967837766100ee4743ce7c0e7e8e6a86f9a0c813e3a0d969188df68; oracle.uix=0^^GMT+1:00
X-Forwarded-For: 192.168.1.4

The error was:

The request URL http://vaio-portable:8099/Protectia1-ViewController-context-root/faces/pprDeclaratif2.jspx?_adf.winId=1826625445_4&_adf.ctrl-state=1826625445_3 handled by instance vaio-portable:8099 cannot be serviced, as it would result in looped invocation of the instance

Have you got an idea ?

Thanks you very much,

Christophe,

Chris Muir said...

Yep, you hit the nail on the head, my instructions only work for JDev 10.1.3. JDev 11g's HTTP Analyzer has changed.

For JDev 11g in the HTTP Analyzer:

1) Say you have an app running at http://127.0.0.1:8080/blah/blah
2) Open the HTTP Analyzer preferences
3) Add a URL Substitution rule
4) Make sure the Substitution rule come before the Pass through rule that already exists
5) In the substitution rule set:
5.1) Host = localhost
5.2) Listen on port = 8099
5.3) URL filter = http://localhost:8099.*
5.4) Filter test = (leave blank)
5.5) String to replace = localhost:8099
5.6) String to replace is reg expression = unchecked
5.7) Replacement String = 127.0.0.1:8080

I have rushed writing these instructions somewhere so let me know if you have any issues.

Note that Gerard Davison at Oracle has some guidelines on his blog to help you understand what you're actually doing.

CM.

Clive Jefferies said...

I had a nightmare getting http analyzer to work and found your post was very helpful. I am not sure why JDeveloper cannot make this a one click process.

Thank you.