hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Marchetti-Stasi <...@linux.it>
Subject HttpPut (4.1) vs. PutMethod (3.1)
Date Tue, 08 Mar 2011 13:08:03 GMT

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


Mime
View raw message