Ask Your Question
0

RESTful POST method using JAX-RS Jersey

asked 2011-05-02 22:02:23 -0500

steve-chu gravatar image

I tested GET method of Glance RESTful interface. It works fine. I am wondering if you could provide sample code to PUT image to glance via its RESTful interface. When PUT is being called, how to set Meta data properties. Thanks!

edit retag flag offensive close merge delete

5 answers

Sort by ยป oldest newest most voted
0

answered 2011-05-09 17:52:12 -0500

justin-fathomdb gravatar image

Hi Steve - sorry about the delay. You should be able to set custom headers with the JAX-RS client using the header() method, though I'm only going by the docs here, not having used it myself: http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/WebResource.html (http://jersey.java.net/nonav/apidocs/...)

However, for an image upload, there's a much bigger issue, which is that your client library really has to be designed not to buffer the entire posted data (i.e. the image) in memory first. I did dig through the Jersey source code to try to see whether this was the case, it looks like it could be OK, but you _may_ have to provider a custom adapter.

Personally, I would use a lower-level library for image upload & download. Apache HttpClient seems to have changed everything in v4, but here's a sample which explains how to do chunked uploading without buffering (apparently), it also references using a "FileEntity" class which I presume is exactly what you actually want... http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientChunkEncodedPost.java (http://hc.apache.org/httpcomponents-c...)

edit flag offensive delete link more
0

answered 2011-05-04 19:56:45 -0500

jaypipes gravatar image

Sorry, Steve, I don't have any experience with writing Java-based REST clients. :( I'll ask around and see if someone else would have some more information.

edit flag offensive delete link more
0

answered 2011-05-04 19:47:56 -0500

steve-chu gravatar image

I am building RESTful client using JAX-RS Jersey and having problem with POSTing images to Glance repository. The Meta data in ClientRequest headers are not processed by Glance. The Image in the ClientRequest entity was added to the Glance repository.

Does Glance support JAX-RS Jersey?

edit flag offensive delete link more
0

answered 2011-05-03 16:59:55 -0500

jaypipes gravatar image

Hi Steve,

Sorry, I do not have any Java sample code. However, the REST interface is documented in the Glance Documentation online here:

http://glance.openstack.org/glanceapi...

A call to GET /images/<id> returns the image in the request body, and metadata about the image in the HTTP headers.

Cheers, jay

edit flag offensive delete link more
0

answered 2011-05-03 00:57:44 -0500

steve-chu gravatar image

The following Java code is from RESTful client. ... ...

    Client client = Client.create();

    // get GET
    WebResource getWebResource = client.resource("http://your-host-ip:9292/images/detail");
    String s = getWebResource.get(String.class);
    System.out.println("response is " + s);
    JSONObject jsonObj = null;
    try {
        jsonObj = new JSONObject(s);
        JSONArray jsonArray = jsonObj.getJSONArray("images");
        int index = jsonArray.length();
        JSONObject imageObj = null;
        for (int i = 0; i < index; i++) {
            imageObj = jsonArray.getJSONObject(i);
            String imageName = imageObj.getString("name");
            System.out.println("name is " + imageName);
            Long imageSize = imageObj.getLong("size");
            System.out.println("image size is " + imageSize.toString());
        }

        JSONObject newImage = jsonArray.getJSONObject(0);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // test DELETE
    WebResource deleteWebResource = client.resource("http://your-host-ip:9292/images/3");
    deleteWebResource.delete();

The above GET and DELETE method seem working. The output of GET is only Meta data. Where is the real image? I could not find details description from Glance documentation. I can not get PUT or POST to work and I am getting HTTP error 400 and 404. Do you have documentation to describe the RESTful interface? If you can provide sample code (Java), that would be great!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2011-05-02 22:02:23 -0500

Seen: 858 times

Last updated: May 09 '11