You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Marcel Schiffel <ma...@googlemail.com> on 2008/09/26 11:22:21 UTC

visualizing upload/download status in a statusbar

Hi,

we're successfully using the HttpClient library for several months now, but
now we need a feature that seems quite hard to implement: Sometimes we need
to transmit large files (up to serveral Mb) and therefore have to give some
feedback about the up- or download status to the user. Unfortunately i
haven't found any information on this.

When downloading a file I tried to tell the client the content size by
setting a response header and then count each byte that is read from the
input stream. Unfortunately I still have the feeling that the whole file is
transmitted and I get an InputStream on the result afterwards. When
uploading a file I'm using method.setRequestEntity(new
ByteArrayRequestEntity(content)); and therefore can't even count the
individual bytes.

Is there an event listener that I can register to get notified whenever
another percent of the file transmitted? Is it even possible to implement it
using HttpClient and where can I find some information on this issue (maybe
even sample code)?

many thanks in advance
Marcel

Re: visualizing upload/download status in a statusbar

Posted by umpirsky <um...@gmail.com>.
Hi. It was long time ago, I don't remember anything.
But my uploader is open source, you can check
http://code.google.com/p/umpirsky-uploader/source/browse/#svn/trunk/src/umpirsky/umpirsky

Hope this helps.


metalheart2003 wrote:
> 
> Hi umpirsky, 
> Sorry, but I'm hard to run this code in my applet. 
> In
> 
> filePost.setRequestEntity(new UmpirskyRequestEntity(
> new MultipartRequestEntity(parts, filePost.getParams()),
> new UmpirskyProgressListener(this, (long)targetFile.length())));
> 
> in "this" I get the failure:
> 
> symbol  : constructor UmpirskyProgressListener(upload,long)
> location: class upload.UmpirskyProgressListener  new
> UmpirskyProgressListener(this, (long)targetFile.length())));
> Note: Some input files use unchecked or unsafe operations. 
> 
> 
> I spend all my code. 
> Thank you very much for your help!
> 
> ...
> import umpirsky.UmpirskyRequestEntity.ProgressListener;
> import umpirsky.UmpirskyUploader;
> import umpirsky.UmpirskyRequestEntity;
> import umpirsky.UmpirskyProgressListener;
> ...
> String targetURL =
> "http://localhost/swfupload/demos/swfobjectdemo/upload.aspx";
> PostMethod filePost = new PostMethod(targetURL);
> filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,true);
> try {
>     File targetFile = new File("C:\\temp\\pruebas\\1_MOV01114.rar"); //
> FICHERO
> 
>     UploadFichero.consola("Uploading #" + targetFileString +  "# to " +
> targetURL);
>     Part[] parts = {new FilePart("file", targetFile)}; //PARAMETROS
> 
>     filePost.setRequestEntity(
>             new MultipartRequestEntity(parts,
>             filePost.getParams())
>             );
> 
>     HttpClient client = new HttpClient();
>    
> client.getHttpConnectionManager().getParams().setConnectionTimeout(50000);
> 
>     filePost.setRequestEntity(new UmpirskyRequestEntity(
>                                 new MultipartRequestEntity(parts,
> filePost.getParams()),
>                                 new UmpirskyProgressListener(this,
> (long)targetFile.length())));
> ...
> public class UmpirskyProgressListener extends Observable implements
> ProgressListener {
>        ...
>         public UmpirskyProgressListener(UmpirskyUploader observer, long
> bytesToSend) {
>                 // for some reson, twice much bytes is sent to server, so
> this is ugly patch
>                 this.bytesToSend = 2 * bytesToSend;
>                 this.addObserver(observer);
>         }
> ...
>         public void transferred(long bytes) {
>                 this.setChanged();
>                 System.out.println("progress="+((float)
> bytes/this.bytesToSend * 100));
>                 //this.notifyObservers();
>         }
> 
> }
> }
> 
> 
> 
> umpirsky wrote:
>> 
>> postMethod.setRequestEntity(new UmpirskyRequestEntity(new
>> MultipartRequestEntity(parts, postMethod.getParams()), new
>> UmpirskyProgressListener(this, bytesToSend)));
>> 
>> and in my case UmpirskyProgressListener :
>> 
>> 
>> package umpirsky;
>> 
>> import java.util.Observable;
>> 
>> import umpirsky.UmpirskyRequestEntity.ProgressListener;
>> 
>> public class UmpirskyProgressListener extends Observable implements
>> ProgressListener {
>> 	/**
>> 	 * Number of bytes to send
>> 	 */
>> 	private long bytesToSend;
>> 
>> 	/**
>> 	 * Progress constructor
>> 	 *
>> 	 * @author Saša Stamenković <um...@gmail.com>
>> 	 * @param UmpirskyUploader observer applet is observer. monitors upload
>> progress
>> 	 * @param long bytesToSend number of bytes that need to be sent
>> 	 */
>> 	public UmpirskyProgressListener(UmpirskyUploader observer, long
>> bytesToSend) {
>> 		// for some reson, twice much bytes is sent to server, so this is ugly
>> patch
>> 		this.bytesToSend = 2 * bytesToSend;
>> 		this.addObserver(observer);
>> 	}
>> 
>> 	/**
>> 	 * Triggered on every byte sent
>> 	 *
>> 	 * @author Saša Stamenković <um...@gmail.com>
>> 	 * @param long bytes number of bytes sent
>> 	 * @return void
>> 	 */
>> 	public void transferred(long bytes) {
>> 		this.setChanged();
>> 		this.notifyObservers((float) bytes/this.bytesToSend * 100);
>> 	}
>> 
>> }
>> 
>> you can implement your own ProgressListener and do what is needed
>> there...in my case that is observable listener which notifies observer to
>> update GUI.
>> 
>> Hope this helps, if not don't be hesitate to ask ;)
>> 
>> 
>> 
>> soapergem wrote:
>>> 
>>> umpirsky,
>>> 
>>> Could you post a complete code example please? I am still not sure how
>>> to use this class. Thanks.
>>> 
>>> Regards,
>>> 
>>> Gordon
>>> 
>>> 
>>> umpirsky wrote:
>>>> 
>>>> Cool, it works!
>>>> 
>>>> Seems like number of bytes sent is about 2Xfile.lenght().
>>>> 
>>>> For file size 105542b it sends 211606b,
>>>> For file size 43062b it sends 86642b
>>>> 
>>>> any explanation???
>>>> 
>>>> 
>>>> Marcel Schiffel wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> it's wrapped around another request entity, for example:
>>>>> 
>>>>> 		PostMethod method = new PostMethod(...);
>>>>> 		FileRequestEntity fre = new FileRequestEntity(someFile,
>>>>> "contentType");
>>>>> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
>>>>> 
>>>>> I've been able to use it with only minor changes (changed the type of
>>>>> the listener to ProgressHandle of the Netbeans Progress API). It's
>>>>> successfully counting the bytes sent, but I'm still not able to
>>>>> determine the total number of bytes that are sent, before executing
>>>>> the request. I'm therefore unable to tell the status bar what number
>>>>> of bytes is equivalent to 100%. Furthermore it is still not clear how
>>>>> to achieve the same thing when downloading a file (evaluating the
>>>>> response body stream).
>>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p23451220.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by metalheart2003 <cl...@gmail.com>.
thank very very very very very very very very very much!
I have worked!
It was not calling the method!
Great!
You are a machine!



metalheart2003 wrote:
> 
> Hi umpirsky, 
> Sorry, but I'm hard to run this code in my applet. 
> In
> 
> filePost.setRequestEntity(new UmpirskyRequestEntity(
> new MultipartRequestEntity(parts, filePost.getParams()),
> new UmpirskyProgressListener(this, (long)targetFile.length())));
> 
> in "this" I get the failure:
> 
> symbol  : constructor UmpirskyProgressListener(upload,long)
> location: class upload.UmpirskyProgressListener  new
> UmpirskyProgressListener(this, (long)targetFile.length())));
> Note: Some input files use unchecked or unsafe operations. 
> 
> 
> I spend all my code. 
> Thank you very much for your help!
> 
> ...
> import umpirsky.UmpirskyRequestEntity.ProgressListener;
> import umpirsky.UmpirskyUploader;
> import umpirsky.UmpirskyRequestEntity;
> import umpirsky.UmpirskyProgressListener;
> ...
> String targetURL =
> "http://localhost/swfupload/demos/swfobjectdemo/upload.aspx";
> PostMethod filePost = new PostMethod(targetURL);
> filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,true);
> try {
>     File targetFile = new File("C:\\temp\\pruebas\\1_MOV01114.rar"); //
> FICHERO
> 
>     UploadFichero.consola("Uploading #" + targetFileString +  "# to " +
> targetURL);
>     Part[] parts = {new FilePart("file", targetFile)}; //PARAMETROS
> 
>     filePost.setRequestEntity(
>             new MultipartRequestEntity(parts,
>             filePost.getParams())
>             );
> 
>     HttpClient client = new HttpClient();
>    
> client.getHttpConnectionManager().getParams().setConnectionTimeout(50000);
> 
>     filePost.setRequestEntity(new UmpirskyRequestEntity(
>                                 new MultipartRequestEntity(parts,
> filePost.getParams()),
>                                 new UmpirskyProgressListener(this,
> (long)targetFile.length())));
> ...
> public class UmpirskyProgressListener extends Observable implements
> ProgressListener {
>        ...
>         public UmpirskyProgressListener(UmpirskyUploader observer, long
> bytesToSend) {
>                 // for some reson, twice much bytes is sent to server, so
> this is ugly patch
>                 this.bytesToSend = 2 * bytesToSend;
>                 this.addObserver(observer);
>         }
> ...
>         public void transferred(long bytes) {
>                 this.setChanged();
>                 System.out.println("progress="+((float)
> bytes/this.bytesToSend * 100));
>                 //this.notifyObservers();
>         }
> 
> }
> }
> 
> 
> 
> umpirsky wrote:
>> 
>> postMethod.setRequestEntity(new UmpirskyRequestEntity(new
>> MultipartRequestEntity(parts, postMethod.getParams()), new
>> UmpirskyProgressListener(this, bytesToSend)));
>> 
>> and in my case UmpirskyProgressListener :
>> 
>> 
>> package umpirsky;
>> 
>> import java.util.Observable;
>> 
>> import umpirsky.UmpirskyRequestEntity.ProgressListener;
>> 
>> public class UmpirskyProgressListener extends Observable implements
>> ProgressListener {
>> 	/**
>> 	 * Number of bytes to send
>> 	 */
>> 	private long bytesToSend;
>> 
>> 	/**
>> 	 * Progress constructor
>> 	 *
>> 	 * @author Saša Stamenković <um...@gmail.com>
>> 	 * @param UmpirskyUploader observer applet is observer. monitors upload
>> progress
>> 	 * @param long bytesToSend number of bytes that need to be sent
>> 	 */
>> 	public UmpirskyProgressListener(UmpirskyUploader observer, long
>> bytesToSend) {
>> 		// for some reson, twice much bytes is sent to server, so this is ugly
>> patch
>> 		this.bytesToSend = 2 * bytesToSend;
>> 		this.addObserver(observer);
>> 	}
>> 
>> 	/**
>> 	 * Triggered on every byte sent
>> 	 *
>> 	 * @author Saša Stamenković <um...@gmail.com>
>> 	 * @param long bytes number of bytes sent
>> 	 * @return void
>> 	 */
>> 	public void transferred(long bytes) {
>> 		this.setChanged();
>> 		this.notifyObservers((float) bytes/this.bytesToSend * 100);
>> 	}
>> 
>> }
>> 
>> you can implement your own ProgressListener and do what is needed
>> there...in my case that is observable listener which notifies observer to
>> update GUI.
>> 
>> Hope this helps, if not don't be hesitate to ask ;)
>> 
>> 
>> 
>> soapergem wrote:
>>> 
>>> umpirsky,
>>> 
>>> Could you post a complete code example please? I am still not sure how
>>> to use this class. Thanks.
>>> 
>>> Regards,
>>> 
>>> Gordon
>>> 
>>> 
>>> umpirsky wrote:
>>>> 
>>>> Cool, it works!
>>>> 
>>>> Seems like number of bytes sent is about 2Xfile.lenght().
>>>> 
>>>> For file size 105542b it sends 211606b,
>>>> For file size 43062b it sends 86642b
>>>> 
>>>> any explanation???
>>>> 
>>>> 
>>>> Marcel Schiffel wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> it's wrapped around another request entity, for example:
>>>>> 
>>>>> 		PostMethod method = new PostMethod(...);
>>>>> 		FileRequestEntity fre = new FileRequestEntity(someFile,
>>>>> "contentType");
>>>>> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
>>>>> 
>>>>> I've been able to use it with only minor changes (changed the type of
>>>>> the listener to ProgressHandle of the Netbeans Progress API). It's
>>>>> successfully counting the bytes sent, but I'm still not able to
>>>>> determine the total number of bytes that are sent, before executing
>>>>> the request. I'm therefore unable to tell the status bar what number
>>>>> of bytes is equivalent to 100%. Furthermore it is still not clear how
>>>>> to achieve the same thing when downloading a file (evaluating the
>>>>> response body stream).
>>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p23422808.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by metalheart2003 <cl...@gmail.com>.
Hi umpirsky, 
Sorry, but I'm hard to run this code in my applet. 
In

filePost.setRequestEntity(new UmpirskyRequestEntity(
new MultipartRequestEntity(parts, filePost.getParams()),
new UmpirskyProgressListener(this, (long)targetFile.length())));

in "this" I get the failure:

symbol  : constructor UmpirskyProgressListener(upload,long)
location: class upload.UmpirskyProgressListener  new
UmpirskyProgressListener(this, (long)targetFile.length())));
Note: Some input files use unchecked or unsafe operations. 


I spend all my code. 
Thank you very much for your help!

...
import umpirsky.UmpirskyRequestEntity.ProgressListener;
import umpirsky.UmpirskyUploader;
import umpirsky.UmpirskyRequestEntity;
import umpirsky.UmpirskyProgressListener;
...
String targetURL =
"http://localhost/swfupload/demos/swfobjectdemo/upload.aspx";
PostMethod filePost = new PostMethod(targetURL);
filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,true);
try {
    File targetFile = new File("C:\\temp\\pruebas\\1_MOV01114.rar"); //
FICHERO

    UploadFichero.consola("Uploading #" + targetFileString +  "# to " +
targetURL);
    Part[] parts = {new FilePart("file", targetFile)}; //PARAMETROS

    filePost.setRequestEntity(
            new MultipartRequestEntity(parts,
            filePost.getParams())
            );

    HttpClient client = new HttpClient();
   
client.getHttpConnectionManager().getParams().setConnectionTimeout(50000);

    filePost.setRequestEntity(new UmpirskyRequestEntity(
                                new MultipartRequestEntity(parts,
filePost.getParams()),
                                new UmpirskyProgressListener(this,
(long)targetFile.length())));
...
public class UmpirskyProgressListener extends Observable implements
ProgressListener {
       ...
        public UmpirskyProgressListener(UmpirskyUploader observer, long
bytesToSend) {
                // for some reson, twice much bytes is sent to server, so
this is ugly patch
                this.bytesToSend = 2 * bytesToSend;
                this.addObserver(observer);
        }
...
        public void transferred(long bytes) {
                this.setChanged();
                System.out.println("progress="+((float)
bytes/this.bytesToSend * 100));
                //this.notifyObservers();
        }

}
}



umpirsky wrote:
> 
> postMethod.setRequestEntity(new UmpirskyRequestEntity(new
> MultipartRequestEntity(parts, postMethod.getParams()), new
> UmpirskyProgressListener(this, bytesToSend)));
> 
> and in my case UmpirskyProgressListener :
> 
> 
> package umpirsky;
> 
> import java.util.Observable;
> 
> import umpirsky.UmpirskyRequestEntity.ProgressListener;
> 
> public class UmpirskyProgressListener extends Observable implements
> ProgressListener {
> 	/**
> 	 * Number of bytes to send
> 	 */
> 	private long bytesToSend;
> 
> 	/**
> 	 * Progress constructor
> 	 *
> 	 * @author Saša Stamenković <um...@gmail.com>
> 	 * @param UmpirskyUploader observer applet is observer. monitors upload
> progress
> 	 * @param long bytesToSend number of bytes that need to be sent
> 	 */
> 	public UmpirskyProgressListener(UmpirskyUploader observer, long
> bytesToSend) {
> 		// for some reson, twice much bytes is sent to server, so this is ugly
> patch
> 		this.bytesToSend = 2 * bytesToSend;
> 		this.addObserver(observer);
> 	}
> 
> 	/**
> 	 * Triggered on every byte sent
> 	 *
> 	 * @author Saša Stamenković <um...@gmail.com>
> 	 * @param long bytes number of bytes sent
> 	 * @return void
> 	 */
> 	public void transferred(long bytes) {
> 		this.setChanged();
> 		this.notifyObservers((float) bytes/this.bytesToSend * 100);
> 	}
> 
> }
> 
> you can implement your own ProgressListener and do what is needed
> there...in my case that is observable listener which notifies observer to
> update GUI.
> 
> Hope this helps, if not don't be hesitate to ask ;)
> 
> 
> 
> soapergem wrote:
>> 
>> umpirsky,
>> 
>> Could you post a complete code example please? I am still not sure how to
>> use this class. Thanks.
>> 
>> Regards,
>> 
>> Gordon
>> 
>> 
>> umpirsky wrote:
>>> 
>>> Cool, it works!
>>> 
>>> Seems like number of bytes sent is about 2Xfile.lenght().
>>> 
>>> For file size 105542b it sends 211606b,
>>> For file size 43062b it sends 86642b
>>> 
>>> any explanation???
>>> 
>>> 
>>> Marcel Schiffel wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> it's wrapped around another request entity, for example:
>>>> 
>>>> 		PostMethod method = new PostMethod(...);
>>>> 		FileRequestEntity fre = new FileRequestEntity(someFile,
>>>> "contentType");
>>>> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
>>>> 
>>>> I've been able to use it with only minor changes (changed the type of
>>>> the listener to ProgressHandle of the Netbeans Progress API). It's
>>>> successfully counting the bytes sent, but I'm still not able to
>>>> determine the total number of bytes that are sent, before executing the
>>>> request. I'm therefore unable to tell the status bar what number of
>>>> bytes is equivalent to 100%. Furthermore it is still not clear how to
>>>> achieve the same thing when downloading a file (evaluating the response
>>>> body stream).
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p23422418.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by umpirsky <um...@gmail.com>.
postMethod.setRequestEntity(new UmpirskyRequestEntity(new
MultipartRequestEntity(parts, postMethod.getParams()), new
UmpirskyProgressListener(this, bytesToSend)));

and in my case UmpirskyProgressListener :


package umpirsky;

import java.util.Observable;

import umpirsky.UmpirskyRequestEntity.ProgressListener;

public class UmpirskyProgressListener extends Observable implements
ProgressListener {
	/**
	 * Number of bytes to send
	 */
	private long bytesToSend;

	/**
	 * Progress constructor
	 *
	 * @author Saša Stamenković <um...@gmail.com>
	 * @param UmpirskyUploader observer applet is observer. monitors upload
progress
	 * @param long bytesToSend number of bytes that need to be sent
	 */
	public UmpirskyProgressListener(UmpirskyUploader observer, long
bytesToSend) {
		// for some reson, twice much bytes is sent to server, so this is ugly
patch
		this.bytesToSend = 2 * bytesToSend;
		this.addObserver(observer);
	}

	/**
	 * Triggered on every byte sent
	 *
	 * @author Saša Stamenković <um...@gmail.com>
	 * @param long bytes number of bytes sent
	 * @return void
	 */
	public void transferred(long bytes) {
		this.setChanged();
		this.notifyObservers((float) bytes/this.bytesToSend * 100);
	}

}

you can implement your own ProgressListener and do what is needed there...in
my case that is observable listener which notifies observer to update GUI.

Hope this helps, if not don't be hesitate to ask ;)



soapergem wrote:
> 
> umpirsky,
> 
> Could you post a complete code example please? I am still not sure how to
> use this class. Thanks.
> 
> Regards,
> 
> Gordon
> 
> 
> umpirsky wrote:
>> 
>> Cool, it works!
>> 
>> Seems like number of bytes sent is about 2Xfile.lenght().
>> 
>> For file size 105542b it sends 211606b,
>> For file size 43062b it sends 86642b
>> 
>> any explanation???
>> 
>> 
>> Marcel Schiffel wrote:
>>> 
>>> Hi,
>>> 
>>> it's wrapped around another request entity, for example:
>>> 
>>> 		PostMethod method = new PostMethod(...);
>>> 		FileRequestEntity fre = new FileRequestEntity(someFile,
>>> "contentType");
>>> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
>>> 
>>> I've been able to use it with only minor changes (changed the type of
>>> the listener to ProgressHandle of the Netbeans Progress API). It's
>>> successfully counting the bytes sent, but I'm still not able to
>>> determine the total number of bytes that are sent, before executing the
>>> request. I'm therefore unable to tell the status bar what number of
>>> bytes is equivalent to 100%. Furthermore it is still not clear how to
>>> achieve the same thing when downloading a file (evaluating the response
>>> body stream).
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20549948.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by soapergem <so...@gmail.com>.
umpirsky,

Could you post a complete code example please? I am still not sure how to
use this class. Thanks.

Regards,

Gordon


umpirsky wrote:
> 
> Cool, it works!
> 
> Seems like number of bytes sent is about 2Xfile.lenght().
> 
> For file size 105542b it sends 211606b,
> For file size 43062b it sends 86642b
> 
> any explanation???
> 
> 
> Marcel Schiffel wrote:
>> 
>> Hi,
>> 
>> it's wrapped around another request entity, for example:
>> 
>> 		PostMethod method = new PostMethod(...);
>> 		FileRequestEntity fre = new FileRequestEntity(someFile, "contentType");
>> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
>> 
>> I've been able to use it with only minor changes (changed the type of the
>> listener to ProgressHandle of the Netbeans Progress API). It's
>> successfully counting the bytes sent, but I'm still not able to determine
>> the total number of bytes that are sent, before executing the request.
>> I'm therefore unable to tell the status bar what number of bytes is
>> equivalent to 100%. Furthermore it is still not clear how to achieve the
>> same thing when downloading a file (evaluating the response body stream).
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20549214.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by umpirsky <um...@gmail.com>.
Cool, it works!

Seems like number of bytes sent is about 2Xfile.lenght().

For file size 105542b it sends 211606b,
For file size 43062b it sends 86642b

any explanation???


Marcel Schiffel wrote:
> 
> Hi,
> 
> it's wrapped around another request entity, for example:
> 
> 		PostMethod method = new PostMethod(...);
> 		FileRequestEntity fre = new FileRequestEntity(someFile, "contentType");
> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
> 
> I've been able to use it with only minor changes (changed the type of the
> listener to ProgressHandle of the Netbeans Progress API). It's
> successfully counting the bytes sent, but I'm still not able to determine
> the total number of bytes that are sent, before executing the request. I'm
> therefore unable to tell the status bar what number of bytes is equivalent
> to 100%. Furthermore it is still not clear how to achieve the same thing
> when downloading a file (evaluating the response body stream).
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20507255.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by soapergem <so...@gmail.com>.
Hi,

I am very new to Java but have been trying to create a web applet that can
upload a file with a progress bar and requires no server-side Java to keep
track of how many bytes have been sent. Is this possible with this
"CountingRequestEntity" class? If so, could you please include some complete
example code of how this would be achieved? Also, you said that you are
unable to determine the total number of bytes that are being sent, but if
you have selected a File object representing the file to upload, can you not
just use File.length() to determine the total number of bytes? Thanks much.

Regards,

Gordon




Marcel Schiffel wrote:
> 
> Hi,
> 
> it's wrapped around another request entity, for example:
> 
> 		PostMethod method = new PostMethod(...);
> 		FileRequestEntity fre = new FileRequestEntity(someFile, "contentType");
> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
> 
> I've been able to use it with only minor changes (changed the type of the
> listener to ProgressHandle of the Netbeans Progress API). It's
> successfully counting the bytes sent, but I'm still not able to determine
> the total number of bytes that are sent, before executing the request. I'm
> therefore unable to tell the status bar what number of bytes is equivalent
> to 100%. Furthermore it is still not clear how to achieve the same thing
> when downloading a file (evaluating the response body stream).
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20283364.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by umpirsky <um...@gmail.com>.
Cool, thanks. Think I'll manage...

Marcel Schiffel wrote:
> 
> Hi,
> 
> it's wrapped around another request entity, for example:
> 
> 		PostMethod method = new PostMethod(...);
> 		FileRequestEntity fre = new FileRequestEntity(someFile, "contentType");
> 		method.setRequestEntity(new CountingRequestEntity(fre, listener));
> 
> I've been able to use it with only minor changes (changed the type of the
> listener to ProgressHandle of the Netbeans Progress API). It's
> successfully counting the bytes sent, but I'm still not able to determine
> the total number of bytes that are sent, before executing the request. I'm
> therefore unable to tell the status bar what number of bytes is equivalent
> to 100%. Furthermore it is still not clear how to achieve the same thing
> when downloading a file (evaluating the response body stream).
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20104744.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by Marcel Schiffel <ma...@googlemail.com>.
Hi,

it's wrapped around another request entity, for example:

		PostMethod method = new PostMethod(...);
		FileRequestEntity fre = new FileRequestEntity(someFile, "contentType");
		method.setRequestEntity(new CountingRequestEntity(fre, listener));

I've been able to use it with only minor changes (changed the type of the
listener to ProgressHandle of the Netbeans Progress API). It's successfully
counting the bytes sent, but I'm still not able to determine the total
number of bytes that are sent, before executing the request. I'm therefore
unable to tell the status bar what number of bytes is equivalent to 100%.
Furthermore it is still not clear how to achieve the same thing when
downloading a file (evaluating the response body stream).
-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20095771.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by umpirsky <um...@gmail.com>.
Excelent, but, how do you use this class?

olegk wrote:
> 
> On Thu, 2008-10-09 at 07:41 -0700, Marcel Schiffel wrote:
>> Hi,
>> hope you had a relaxing vacation. I'm still facing the problems described
>> two weeks ago and would be very grateful for some additional hints.
>> Here's
>> an extract of the client code: 
>> 
> 
> ...
> 
>> 
>> Many Thanks
>> Marcel
>> 
> 
> 
> import java.io.FilterOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> 
> import org.apache.commons.httpclient.methods.RequestEntity;
> 
> public class CoutingRequestEntity implements RequestEntity {
>   
>     private final RequestEntity entity;
>     private final ProgressListener listener;
>     
>     public CoutingRequestEntity(
>             final RequestEntity entity, 
>             final ProgressListener listener) {
>         super();
>         this.entity = entity;
>         this.listener = listener;
>     }
> 
>     public long getContentLength() {
>         return this.entity.getContentLength();
>     }
> 
>     public String getContentType() {
>         return this.entity.getContentType();
>     }
> 
>     public boolean isRepeatable() {
>         return this.entity.isRepeatable();
>     }
> 
>     public void writeRequest(final OutputStream out) throws IOException
> {
>         this.entity.writeRequest(
>                 new CountingOutputStream(out, this.listener));
>     }
>     
>     public static interface ProgressListener {
>         
>         void transferred(long num);
>         
>     }
> 
>     public static class CountingOutputStream extends FilterOutputStream
> {
> 
>         private final ProgressListener listener;
>         private long transferred;
>         
>         public CountingOutputStream(
>                 final OutputStream out, 
>                 final ProgressListener listener) {
>             super(out);
>             this.listener = listener;
>             this.transferred = 0;
>         }
> 
>         public void write(byte[] b, int off, int len) throws IOException
> {
>             super.write(b, off, len);
>             this.transferred += len;
>             this.listener.transferred(this.transferred);
>         }
> 
>         public void write(int b) throws IOException {
>             super.write(b);
>             this.transferred++;
>             this.listener.transferred(this.transferred);
>         }
>         
>     }
> }
> 
> Hope this helps
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20087978.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2008-10-09 at 07:41 -0700, Marcel Schiffel wrote:
> Hi,
> hope you had a relaxing vacation. I'm still facing the problems described
> two weeks ago and would be very grateful for some additional hints. Here's
> an extract of the client code: 
> 

...

> 
> Many Thanks
> Marcel
> 


import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.httpclient.methods.RequestEntity;

public class CoutingRequestEntity implements RequestEntity {
  
    private final RequestEntity entity;
    private final ProgressListener listener;
    
    public CoutingRequestEntity(
            final RequestEntity entity, 
            final ProgressListener listener) {
        super();
        this.entity = entity;
        this.listener = listener;
    }

    public long getContentLength() {
        return this.entity.getContentLength();
    }

    public String getContentType() {
        return this.entity.getContentType();
    }

    public boolean isRepeatable() {
        return this.entity.isRepeatable();
    }

    public void writeRequest(final OutputStream out) throws IOException
{
        this.entity.writeRequest(
                new CountingOutputStream(out, this.listener));
    }
    
    public static interface ProgressListener {
        
        void transferred(long num);
        
    }

    public static class CountingOutputStream extends FilterOutputStream
{

        private final ProgressListener listener;
        private long transferred;
        
        public CountingOutputStream(
                final OutputStream out, 
                final ProgressListener listener) {
            super(out);
            this.listener = listener;
            this.transferred = 0;
        }

        public void write(byte[] b, int off, int len) throws IOException
{
            super.write(b, off, len);
            this.transferred += len;
            this.listener.transferred(this.transferred);
        }

        public void write(int b) throws IOException {
            super.write(b);
            this.transferred++;
            this.listener.transferred(this.transferred);
        }
        
    }
}

Hope this helps

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by Marcel Schiffel <ma...@googlemail.com>.
Hi,
hope you had a relaxing vacation. I'm still facing the problems described
two weeks ago and would be very grateful for some additional hints. Here's
an extract of the client code: 



int size = Integer.valueOf(method.getResponseHeader("size").getValue());
progressHandle.start(100); // start progress bar of Netbeans Platform
int readBytes = 0;
ObjectInputStream in = new ObjectInputStream(new
ZIPInputStream(method.getResponseBodyAsStream()));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
int curByte = -1;
while((curByte=in.read())>=0){                 
    baos.write(curByte);
    readBytes++;      
    int per = (int) 100.0 * readBytes/size; 
    progressHandle.progress(per); // update status bar
}

ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(baos.toByteArray()));                
Object o = ois.readObject();
ois.close();
progressHandle.finish();



Many Thanks
Marcel

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p19900396.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: visualizing upload/download status in a statusbar

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2008-09-26 at 11:22 +0200, Marcel Schiffel wrote:
> Hi,
> 
> we're successfully using the HttpClient library for several months now, but
> now we need a feature that seems quite hard to implement: Sometimes we need
> to transmit large files (up to serveral Mb) and therefore have to give some
> feedback about the up- or download status to the user. Unfortunately i
> haven't found any information on this.
> 
> When downloading a file I tried to tell the client the content size by
> setting a response header and then count each byte that is read from the
> input stream. Unfortunately I still have the feeling that the whole file is
> transmitted and I get an InputStream on the result afterwards. When
> uploading a file I'm using method.setRequestEntity(new
> ByteArrayRequestEntity(content)); and therefore can't even count the
> individual bytes.
> 
> Is there an event listener that I can register to get notified whenever
> another percent of the file transmitted? Is it even possible to implement it
> using HttpClient and where can I find some information on this issue (maybe
> even sample code)?
> 
> many thanks in advance
> Marcel

Marcel,

I have to be very brief. You need to decorate the OutputStream instance
with a wrapper class that counts bytes sent and fires notifications.

I can give you a more detailed answer when I am back from vacation in 10
days.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org