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

Strutz, Marco marco.strutz at fokus.fraunhofer.de
Wed Aug 11 06:19:59 PDT 2010


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();

(...)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20100811/2afd6a4b/attachment-0002.htm>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20100811/2afd6a4b/attachment-0002.html>


More information about the Users mailing list