### Eclipse Workspace Patch 1.0 #P org.eclipse.atf.mozilla.ide.ui Index: src/org/eclipse/atf/mozilla/ide/ui/netmon/model/impl/MozHTTPRequest.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.atf/components/plugins/org.eclipse.atf.mozilla.ide.ui/src/org/eclipse/atf/mozilla/ide/ui/netmon/model/impl/MozHTTPRequest.java,v retrieving revision 1.3 diff -u -r1.3 MozHTTPRequest.java --- src/org/eclipse/atf/mozilla/ide/ui/netmon/model/impl/MozHTTPRequest.java 17 Oct 2007 22:09:33 -0000 1.3 +++ src/org/eclipse/atf/mozilla/ide/ui/netmon/model/impl/MozHTTPRequest.java 26 Aug 2009 09:55:24 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.atf.mozilla.ide.ui.netmon.model.impl; +import org.eclipse.atf.mozilla.ide.ui.MozIDEUIPlugin; import org.eclipse.atf.mozilla.ide.ui.netmon.model.IHTTPRequest; import org.mozilla.interfaces.nsIHttpChannel; import org.mozilla.interfaces.nsIHttpHeaderVisitor; @@ -30,100 +31,86 @@ //URL of the http request protected String url; - + //HTTP method value protected String method; - + //Body content of the request protected String body = ""; - + //marks if this request is started using XHR protected boolean xhr = false; - - public MozHTTPRequest( nsIHttpChannel httpChannel ){ - this( httpChannel, false ); + + public MozHTTPRequest(nsIHttpChannel httpChannel) { + this(httpChannel, false); } - - public MozHTTPRequest( nsIHttpChannel httpChannel, boolean xhr ){ + + public MozHTTPRequest(nsIHttpChannel httpChannel, boolean xhr) { //creating the local request representation - + this.xhr = xhr; - + //URL of the request this.url = httpChannel.getURI().getAsciiSpec(); - + //HTTP method used this.method = httpChannel.getRequestMethod(); extractBody(httpChannel); - + extractHeaders(httpChannel); } - + /* * Currently handling POSTs and GETs */ - protected void extractBody( nsIHttpChannel httpChannel ) { - if ( POST_METHOD.equals(this.method) || PUT_METHOD.equals(this.method) ) { - + protected void extractBody(nsIHttpChannel httpChannel) { + if (POST_METHOD.equals(this.method) || PUT_METHOD.equals(this.method)) { + // set the POST body as the body - + //The POST body needs to be read from an InputStream nsIScriptableInputStream scriptableIS = null; - + //need it so that we can rewind the stream back nsISeekableStream seekableStream = null; nsIInputStream is = null; try { - nsIUploadChannel upChannel = (nsIUploadChannel) httpChannel - .queryInterface(nsIUploadChannel.NS_IUPLOADCHANNEL_IID); + nsIUploadChannel upChannel = (nsIUploadChannel) httpChannel.queryInterface(nsIUploadChannel.NS_IUPLOADCHANNEL_IID); is = upChannel.getUploadStream(); if (is != null) { - seekableStream= (nsISeekableStream) is.queryInterface(nsISeekableStream.NS_ISEEKABLESTREAM_IID); + seekableStream = (nsISeekableStream) is.queryInterface(nsISeekableStream.NS_ISEEKABLESTREAM_IID); - scriptableIS = (nsIScriptableInputStream) Mozilla - .getInstance() - .getComponentManager() - .createInstanceByContractID( - "@mozilla.org/scriptableinputstream;1", - null, - nsIScriptableInputStream.NS_ISCRIPTABLEINPUTSTREAM_IID); + scriptableIS = (nsIScriptableInputStream) Mozilla.getInstance().getComponentManager().createInstanceByContractID("@mozilla.org/scriptableinputstream;1", null, nsIScriptableInputStream.NS_ISCRIPTABLEINPUTSTREAM_IID); scriptableIS.init(is); - + //read the entire stream into a StringBuffer StringBuffer postBuf = new StringBuffer(); long count; - while( (count = scriptableIS.available()) > 0 )//some left to read{ - postBuf.append( scriptableIS.read(count) ); - - + while ((count = scriptableIS.available()) > 0) + //some left to read{ + postBuf.append(scriptableIS.read(count)); + body = postBuf.toString(); - + } } catch (Exception e) { //Any errors here, the POST body will be empty - } - finally{ - if( scriptableIS != null ) - scriptableIS.close(); - + MozIDEUIPlugin.log(e); + } finally { //rewind - if( seekableStream != null ){ - seekableStream.seek( 0, 0 ); + if (seekableStream != null) { + seekableStream.seek(nsISeekableStream.NS_SEEK_SET, 0); } - - if( is != null ) - is.close(); } - } - else{ + } else { // set the body to the parameters in the URL body = httpChannel.getURI().getPath(); } } - + public String getBody() { return body; } @@ -140,8 +127,7 @@ return xhr; } - protected void visitHeaders(nsIHttpChannel httpChannel, - nsIHttpHeaderVisitor visitor) { - httpChannel.visitRequestHeaders( visitor ); + protected void visitHeaders(nsIHttpChannel httpChannel, nsIHttpHeaderVisitor visitor) { + httpChannel.visitRequestHeaders(visitor); } }