On Fri, 2009-09-18 at 07:48 -0700, Mario Becker-Reinhold wrote:
> Hi Folks,
>
> I'm trying to upgrade some code from HttpClient 3.1 to version 4.
>
> The old code that does a simple PUT in 3.1 is:
>
> HttpClient httpClient = new HttpClient();
> PutMethod put = new PutMethod(this.getArchiveURL_Put()+ "/"
> +fObject.getName());
> RequestEntity entity = new InputStreamRequestEntity(new
> FileInputStream(fObject)); put.setRequestEntity(entity);
>
> httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
> put.setRequestEntity(entity);
>
> Now, I don't know, how I can put the entity in version 4? There are no more
> classes for RequestEntity and InputStreamRequestEntity. I didn't find any
> code examples for Put, only for Get/Post, with this examples I tried to do
> the following:
>
> HttpClient httpClient = new DefaultHttpClient();
> HttpPut put = new HttpPut(this.getArchiveURL_Put()+ "/" +fObject.getName());
> FileBody filebody = new FileBody(fObject);
> MultipartEntity entity = new MultipartEntity();
> entity.addPart("file", filebody);
> put.setRequestEntity(entity);
>
>
> I have removed the jar files of version 3.1 and putted the 2 jar files of
> version 4 (also to the build-path of eclipse), but now, with the code above,
> I get the following error message in eclipse:
> "The type org.apache.james.mime4j.message.SingleBody cannot be resolved. It
> is indirectly referenced from required .class files"
>
> Can anyone give me a hint or can tell me, if I am with the code above on the
> right track?
>
Apparently you do not have mime4j jar on the classpath. The best way to
ensure you have all dependencies is by using Maven to manage your
project or by downloading the latest binary package with dependencies:
http://hc.apache.org/downloads.cgi
Here's an example of multipart POST:
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpmime/src/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java
PUT is virtually identical to POST from the API standpoint.
Oleg
> Thanks in advance,
> best regards and have a nice weekend!
>
> Mario
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]