[one-users] OCCI: multipart POST request with java-client

Javier Fontan jfontan at gmail.com
Tue Aug 24 07:33:20 PDT 2010


Hello,

Looking at the log files from your previous email looks like Java
library is sending both parameters (occixml and file) as files in the
post and the web server writes both parameters as temporary files. I
am not sure what is the difference in your java implementation (or
better, the java library) but we have tested the API using curl
command line (in fact we also use curl library to upload files) and
works fine. I'll open a bug to make the server aware of that behavior
and read occixml parameter from a file if that is the case.

Bye

On Mon, Aug 23, 2010 at 1:28 PM, Strutz, Marco
<marco.strutz at fokus.fraunhofer.de> wrote:
> After further investigation I could not trace back the error with the
> OCCI interface.
>
> Has anybody successfully uploaded a multipart-POST file to the OCCI
> interface with an http-client (except the ruby-client)? That would
> really help me.
>
>
> Thanks
> Marco
>
> -----Original Message-----
> From: users-bounces at lists.opennebula.org
> [mailto:users-bounces at lists.opennebula.org] On Behalf Of Strutz, Marco
> Sent: Wednesday, August 11, 2010 3:20 PM
> To: users at lists.opennebula.org
> Subject: [one-users] OCCI: multipart POST request with java-client
>
> Hi everyone.
>
>
>
> I want to use the opennebula occi interface (.../storage) to upload
> images to the repository (/srv/cloud/images).
>
> But instead of using the ruby-occi-client (occi-storage create xmlfile)
> I want to do test it with a  java client.
>
>
>
> The multipart-upload seems to work but as response I get the following
> error message (short version, long version please find attached
> [occiUploadErrorMessage.html]):
>
>
>
> "RuntimeError at /storage
>
> Hash is not a valid input stream. It must walk like either a String, an
> IO, or a Source.
>
>    * file: source.rb
>
>    * location: create_from
>
>    * line: 21"
>
>
>
>
>
> Seems to be a parsing problem with the xml configuration of the request?
>
> But if I use the same xml-configuration with "occi-storage create
> xmlfile" then all works fine.
>
>
>
> Any suggestions? Would be really appreciate it.
>
>
>
>
>
>
>
> Thanks
>
> Marco
>
>
>
>
>
>
>
> -----------------------
>
>
>
> the config:
>
> - OpenNebula v1.4
>
> - as java html client I'm using "apache.commons.httpclient" (v3.1).
>
> - occiserver endpoint: http://occi.opennebula.cloud:4567/storage
>
>
>
>
>
> the java html multipart occi client
>
> (...)
>
> //prepare xml configuration
>
> file = new File("/tmp/ttyLinux");
>
> xmlConfiguration = "<DISK>      <NAME>testfile_ttyLinux</NAME>
> <URL>file:////tmp/ttyLinux.img</URL></DISK>";
>
> image = new FilePart("file", file);
>
> configurationPart = new StringPart("occixml", xmlConfiguration);
>
>
>
> //create multiparts
>
> Part[] parts =     { image, configurationPart };
>
> filePost = new PostMethod("http://occi.opennebula.cloud:4567/storage";
>
> filePost.setRequestEntity(new MultipartRequestEntity(multiParts,
> filePost.getParams()));
>
>
>
> //load client
>
> client = new HttpClient();
>
> client.getHttpConnectionManager().getParams().setConnectionTimeout(5000)
> ;
>
>
>
> //set credentials
>
> client.getParams().setAuthenticationPreemptive(true); //enable
> Preemptive Authentication
>
> Credentials defaultcreds = new UsernamePasswordCredentials(authUserName,
> authPassword);
>
> AuthScope authScope = new AuthScope(uri.getHost(), uri.getPort(),
> AuthScope.ANY_REALM);
>
> client.getState().setCredentials(authScope, defaultcreds);
>
>
>
> //do post request
>
> client.executeMethod(filePost);
>
> response = filePost.getResponseBodyAsString();
>
> (...)
>
> _______________________________________________
> Users mailing list
> Users at lists.opennebula.org
> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>



-- 
Javier Fontan, Grid & Virtualization Technology Engineer/Researcher
DSA Research Group: http://dsa-research.org
Globus GridWay Metascheduler: http://www.GridWay.org
OpenNebula Virtual Infrastructure Engine: http://www.OpenNebula.org



More information about the Users mailing list