Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > HTTPClient and Progressbar.

Reply
Thread Tools

HTTPClient and Progressbar.

 
 
crazytazo
Guest
Posts: n/a
 
      11-11-2008
PostMethod filePost = new PostMethod(ui.value.getStrEIP());
filePost.getParams().setBooleanParameter(HttpMetho dParams.USE_EXPECT_CONTINUE,
true);

try {
Part[] parts = {
new StringPart("FILENAME", file.m_File.getName()),
new StringPart("DIRFLAG", String.valueOf(0)),
new StringPart("FILEINDEX", String.valueOf(jfidx)),
new StringPart("FILESAVEPATH", ui.value.getStrPath()),
new FilePart(file.m_File.getName(), file.m_File)
};

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

HttpClient client = new HttpClient();

client.getHostConfiguration().setHost(ui.value.get StrEIP(), 80);
client.getHttpConnectionManager().
getParams().setConnectionTimeout(5000);

int status = client.executeMethod(filePost);

if (status == HttpStatus.SC_OK) {
System.out.println("Upload complete, response=" +
filePost.getResponseBodyAsString());
} else {
System.out.println("Upload failed, response=" +
HttpStatus.getStatusText(status));
}

} catch (Exception ex) {
System.out.println("ERROR: " + ex.getClass().getName() + "
" + ex.getMessage());
ex.printStackTrace();
} finally {
filePost.releaseConnection();
}

this is client code using apache.HTTPClient.

it's work well, but follow line is occur blocking until get response
code from server.
int status = client.executeMethod(filePost);

How to check writing bytes in this modules?
The bytes are need to represnt progressbar.
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      11-11-2008
In article
<(E-Mail Removed)>,
crazytazo <(E-Mail Removed)> wrote:

[...]
> [I]t work[s] well, but [the] follow[ing] line block[s]
> until [I] get [a] response code from server.
>
> int status = client.executeMethod(filePost);
>
> How [should I] check writing bytes in this module?
> The bytes are need[ed] to repres[e]nt progress.


Consider using a SwingWorker:

<http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html>
<http://java.sun.com/docs/books/tutorial/uiswing/concurrency/worker.html>

There's a nice prime number example here with a JProgressBar:

<https://swingworker.dev.java.net/>

--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/
 
Reply With Quote
 
 
 
 
rabbits77
Guest
Posts: n/a
 
      11-11-2008
> it's work well, but follow line is occur blocking until get response
> code from server.
> int status = client.executeMethod(filePost);


This is not what you seem to think it is.
status is a http response code and is, of course,
is blocking.
Here is a list of response codes if you are interested
http://kbs.cs.tu-berlin.de/~jutta/ht/responses.html

> How to check writing bytes in this modules?
> The bytes are need to represnt progressbar.


One way to do this is shown on this page which
happens to cover performance optimization
http://hc.apache.org/httpclient-3.x/performance.html
In particular I think something like this would work

HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("http://www.myhost.com/");
try {
httpclient.executeMethod(httpget);
Reader reader = new InputStreamReader(
httpget.getResponseBodyAsStream(),
httpget.getResponseCharSet());

/*get the response byte by byte and update your progress bar
after each response
*/
} finally {
httpget.releaseConnection();
}
 
Reply With Quote
 
crazytazo
Guest
Posts: n/a
 
      11-12-2008
On Nov 12, 3:29*am, rabbits77 <(E-Mail Removed)> wrote:
> > it's work well, but follow line is occur blocking until get response
> > code from server.
> > *int status = client.executeMethod(filePost);

>
> This is not what you seem to think it is.
> status is a http response code and is, of course,
> is blocking.
> Here is a list of response codes if you are interestedhttp://kbs.cs.tu-berlin.de/~jutta/ht/responses.html
>
> > How to check writing bytes in this modules?
> > The bytes are need to represnt progressbar.

>
> One way to do this is shown on this page which
> happens to cover performance optimizationhttp://hc.apache.org/httpclient-3.x/performance.html
> In particular I think something like this would work
>
> * *HttpClient httpclient = new HttpClient();
> * *GetMethod httpget = new GetMethod("http://www.myhost.com/");
> * *try {
> * * *httpclient.executeMethod(httpget);
> * * *Reader reader = new InputStreamReader(
> * * * * * * *httpget.getResponseBodyAsStream(),
> httpget.getResponseCharSet());
>
> * * */*get the response byte by byte and update your progress bar
> * * * *after each response
> * * * **/
> * *} finally {
> * * *httpget.releaseConnection();
> * *}


Thanks rabbits77.

Your code is GET method.
Problem is POST method.

I have solved this problem by override FilePart.sendData(OutputStream
out)
 
Reply With Quote
 
crazytazo
Guest
Posts: n/a
 
      11-12-2008
On Nov 11, 11:13*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
>
> *crazytazo <(E-Mail Removed)> wrote:
>
> [...]
>
> > [I]t work[s] well, but [the] follow[ing] line block[s]
> > until [I] get [a] response code from server.

>
> > *int status = client.executeMethod(filePost);

>
> > How [should I] check writing bytes in this module?
> > The bytes are need[ed] to repres[e]nt progress.

>
> Consider using a SwingWorker:
>
> <http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html>
> <http://java.sun.com/docs/books/tutorial/uiswing/concurrency/worker.html>
>
> There's a nice prime number example here with a JProgressBar:
>
> <https://swingworker.dev.java.net/>
>
> --
> John B. Matthews
> trashgod at gmail dot comhttp://home.roadrunner.com/~jbmatthews/


Thanks John.
It's very good!
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      11-19-2008
On Tue, 11 Nov 2008 13:29:01 -0500, rabbits77 <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

> /*get the response byte by byte and update your progress bar
> after each response
> */


you could also read whatever is available then update progress.

see http://mindprod.com/product1.html#HTTP
--
Roedy Green Canadian Mind Products
http://mindprod.com
Your old road is
Rapidly agin'.
Please get out of the new one
If you can't lend your hand
For the times they are a-changin'.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jakarta Commons HttpClient and a socket reset Joe Linux Java 0 09-15-2006 02:53 PM
Re: xml, windows, utf-8, and httpclient Chris Uppal Java 5 12-21-2005 11:08 AM
Network timeout with HTTPClient and Tomcat Jimi Hullegård Java 1 09-07-2005 10:27 AM
HTTPClient 2.0.2 and HTTP PUT Kevin McMurtrie Java 0 02-15-2005 04:35 AM
HTTPClient - Sessions and cookies what am I doing wrong? Maverick Java 1 02-07-2004 02:25 PM



Advertisments