[one-users] OCCI: multipart POST request with java-client
Strutz, Marco
marco.strutz at fokus.fraunhofer.de
Mon Aug 23 04:28:47 PDT 2010
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();
(...)
More information about the Users
mailing list