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 Francesco Marchetti-Stasi <fm...@linux.it> on 2011/03/08 14:08:03 UTC

HttpPut (4.1) vs. PutMethod (3.1)

Hello,

in one of the servlet of my web application I receive a multipart form, 
from which I have to extract the file input stream and send it via PUT 
to an existing servlet on an Alfresco repository.

I managed to accomplish this with httpclient 4.1, with the following 
code fragment:

                         HttpClient httpclient = new DefaultHttpClient();
                         HttpPut httpput = new HttpPut(uploadUrl) ;
                         InputStreamEntity entity = new 
InputStreamEntity(is, -1) ;
                         httpput.setEntity(entity);
                         HttpResponse alfResponse = 
httpclient.execute(httpput);
                         HttpEntity resEntity = alfResponse.getEntity();
                         System.out.println("Status Line from alfresco: 
" + alfResponse.getStatusLine().toString());
                         resEntity.getContent().close() ;

Unfortunately I have to use httpclient 3.1, since I also have to use a 
third parti library (Remote Alfresco Access by Rivet logic) which needs 
this version. So I tried to translate the above into the following:

                         HttpClient httpclient = new HttpClient();
                         PutMethod method = new PutMethod(uploadUrl);
                         RequestEntity entity = new 
InputStreamRequestEntity(is) ;
                         method.setRequestEntity(entity) ;
                         int statusCode = httpclient.executeMethod(method);
                         is.close() ;
                         System.out.println("Status code: " + statusCode) ;

but in ths case I get a "417" status code, corresponding to the dreadful 
"Expectation Failed" message (I have seen it a few times during my first 
attempts, in which I was using 4.0).

There are still a few tests I can try (first and foremost, sniffing the 
network traffic in the two cases), but in the meantime I thought I could 
ask if anybody has experience using PutMethod with 3.1, and if there is 
something clearly wrong with my code...



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


Re: HttpPut (4.1) vs. PutMethod (3.1)

Posted by Francesco Marchetti-Stasi <fm...@linux.it>.
Ok, I traced the problem. I had written the URL in a bad form, 
http://hostname:8080//alfresco/[...] instead of 
http://hostname:8080/alfresco/[...], i.e. there was a double slash at 
the wrong place; apparently, in httpclient 4.1 there is some feature to 
normalize such a URL, while in 3.1 there is none, so the parsing of the 
URL failed with 4.1. Of course, the reason to signal an error in the 
parsing of the servlet URL with a 417 error code is a mistery.

Sorry for the noise on this list, I hope this little experience may be 
useful to somebody else...

Francesco.

Il 08/03/2011 18.36, Francesco Marchetti-Stasi ha scritto:
> I extracted the fragments to two standalone programs reading a file, 
> and again, with 4.1 the upload succeeds, with 3.1 it fails. I sniffed 
> the network traffic, and I found two relevant differences: with 4.1 
> the transfer encoding is chunked, and connection is set to keep-alive. 
> So I set the transfer encoding and a "Connection" header in 3.1, but 
> the problem persists.
>
> Two differences persist, and I couldn't find a way to backport them to 
> 3.1: chunk size is 800 in 4.1 and 1000 in 3.1; and the order of HTTP 
> headers is different in each case.
>
> I have no other idea, any suggestion is welcome.
>
> Francesco.
>
>
> Il 08/03/2011 14.08, Francesco Marchetti-Stasi ha scritto:
>>
>> Hello,
>>
>> in one of the servlet of my web application I receive a multipart 
>> form, from which I have to extract the file input stream and send it 
>> via PUT to an existing servlet on an Alfresco repository.
>>
>> I managed to accomplish this with httpclient 4.1, with the following 
>> code fragment:
>>
>>                         HttpClient httpclient = new DefaultHttpClient();
>>                         HttpPut httpput = new HttpPut(uploadUrl) ;
>>                         InputStreamEntity entity = new 
>> InputStreamEntity(is, -1) ;
>>                         httpput.setEntity(entity);
>>                         HttpResponse alfResponse = 
>> httpclient.execute(httpput);
>>                         HttpEntity resEntity = alfResponse.getEntity();
>>                         System.out.println("Status Line from 
>> alfresco: " + alfResponse.getStatusLine().toString());
>>                         resEntity.getContent().close() ;
>>
>> Unfortunately I have to use httpclient 3.1, since I also have to use 
>> a third parti library (Remote Alfresco Access by Rivet logic) which 
>> needs this version. So I tried to translate the above into the 
>> following:
>>
>>                         HttpClient httpclient = new HttpClient();
>>                         PutMethod method = new PutMethod(uploadUrl);
>>                         RequestEntity entity = new 
>> InputStreamRequestEntity(is) ;
>>                         method.setRequestEntity(entity) ;
>>                         int statusCode = 
>> httpclient.executeMethod(method);
>>                         is.close() ;
>>                         System.out.println("Status code: " + 
>> statusCode) ;
>>
>> but in ths case I get a "417" status code, corresponding to the 
>> dreadful "Expectation Failed" message (I have seen it a few times 
>> during my first attempts, in which I was using 4.0).
>>
>> There are still a few tests I can try (first and foremost, sniffing 
>> the network traffic in the two cases), but in the meantime I thought 
>> I could ask if anybody has experience using PutMethod with 3.1, and 
>> if there is something clearly wrong with my code...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>



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


Re: HttpPut (4.1) vs. PutMethod (3.1)

Posted by Francesco Marchetti-Stasi <fm...@linux.it>.
I extracted the fragments to two standalone programs reading a file, and 
again, with 4.1 the upload succeeds, with 3.1 it fails. I sniffed the 
network traffic, and I found two relevant differences: with 4.1 the 
transfer encoding is chunked, and connection is set to keep-alive. So I 
set the transfer encoding and a "Connection" header in 3.1, but the 
problem persists.

Two differences persist, and I couldn't find a way to backport them to 
3.1: chunk size is 800 in 4.1 and 1000 in 3.1; and the order of HTTP 
headers is different in each case.

I have no other idea, any suggestion is welcome.

Francesco.


Il 08/03/2011 14.08, Francesco Marchetti-Stasi ha scritto:
>
> Hello,
>
> in one of the servlet of my web application I receive a multipart 
> form, from which I have to extract the file input stream and send it 
> via PUT to an existing servlet on an Alfresco repository.
>
> I managed to accomplish this with httpclient 4.1, with the following 
> code fragment:
>
>                         HttpClient httpclient = new DefaultHttpClient();
>                         HttpPut httpput = new HttpPut(uploadUrl) ;
>                         InputStreamEntity entity = new 
> InputStreamEntity(is, -1) ;
>                         httpput.setEntity(entity);
>                         HttpResponse alfResponse = 
> httpclient.execute(httpput);
>                         HttpEntity resEntity = alfResponse.getEntity();
>                         System.out.println("Status Line from alfresco: 
> " + alfResponse.getStatusLine().toString());
>                         resEntity.getContent().close() ;
>
> Unfortunately I have to use httpclient 3.1, since I also have to use a 
> third parti library (Remote Alfresco Access by Rivet logic) which 
> needs this version. So I tried to translate the above into the following:
>
>                         HttpClient httpclient = new HttpClient();
>                         PutMethod method = new PutMethod(uploadUrl);
>                         RequestEntity entity = new 
> InputStreamRequestEntity(is) ;
>                         method.setRequestEntity(entity) ;
>                         int statusCode = 
> httpclient.executeMethod(method);
>                         is.close() ;
>                         System.out.println("Status code: " + 
> statusCode) ;
>
> but in ths case I get a "417" status code, corresponding to the 
> dreadful "Expectation Failed" message (I have seen it a few times 
> during my first attempts, in which I was using 4.0).
>
> There are still a few tests I can try (first and foremost, sniffing 
> the network traffic in the two cases), but in the meantime I thought I 
> could ask if anybody has experience using PutMethod with 3.1, and if 
> there is something clearly wrong with my code...



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