views:

220

answers:

2

Hello everyone!

I've often read StackOverflow as a source to get answers; but now I have a very specific question and I can't really find any data on the internet. I trust you to be as helpful as always! :D

Basically, I'm relying on Mozilla's XULRunner and its XPCOM objects to analyze the HTTP stream of an SWT browser in a Java application on Linux.

Heavily based on Snippet128 and Snippet321 from the Java SWT website (can't post more than 1 URL sorry :/ ), my browser so far can parse all of the HTTP headers using an nsIHttpHeaderVisitor - and do some pretty stuff like printing them on a tree and such.

Full source is here.

Now... That's already pretty good. It covers the majority of what I want to do (school assignment at first, going a bit further than asked!).

But what I would really like is to be able to get the raw "content" data from every HTTP request: HTML of course ; but also CSS and images.

I've been trying different ways to achieve this goal, but everything failed so far:

  1. Using an XPCOM object - which one?

    • nsIInputStream would be a good one. But I can't seem to find where the good stream actually is... The nsIHttpChannel open() method (who gives back an nsIInputStream) seems to be called by the SWT browser, leaving me with no way of getting the stream back.
    • nsIRequest : no luck.
    • another Listener that I'd have missed? I just spent an hour trying to use the nsIHttpActivityObserver interface, but it doesn't give me any HTTP content (merely GETs and 200 OK).
  2. Using another object

    • the SWT's browser for instance. Well it kinda works: its getText() method gives me the html source of the page I'm visiting. But I want more!

I'm really stuck here, and I would greatly appreciate any help.

Cheers!

Florent

A: 

Perhaps nsITraceableChannel can help you?

Neil
A: 

I have the same question. I have read over 200 pages/idl's/etc. searching for XPCOM, XULRUNNER, nsIStreamListener, nsITraceableChannel, nsIChannel, nsISocket, "http-on-examine-response", "http-on-modify-request", "nsIObserverService", "nsIObserver", etc., etc., etc.. I found some scripts (see "http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/") that gave some hints on what is necessary to do to trace the data, but in Java SWT it doesn't seem to work... Is there a way to attach a default nsIStreamListener to the browser (Using JavaXPCOM)? I wish to sniff the data browsed and dump it to a file. Thanks.

David