简体   繁体   中英

Restlet ServerResource for binary data

I can send binary data from a Restlet Client like so

Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_OCTET_STREAM);
request.setEntity(representation);

However, how can I receive this data from within a restlet ServerResouce?

My starting point would be a method with a signature like this?

@Put
    public MyCustomResponse AddNewDocument(Form data)
    {
     ...
    }

But then how do I get the binary stream?

Try this:

    @Put(MediaType.APPLICATION_OCTET_STREAM)
    public MyCustomResponse AddNewDocument(Form data)
    {
     //...
    }

If both your client and server are java+restlet I would suggest extracting it out to an interface if possible. This way, you could annotate the interface as above and both the client and server would use the same media type. Here is an example .

And here is the documentation for the PUT method: here. Although, it does seem to indicate that you don't necessarily want the full mime type, so you may have to dig around to find it or register it yourself (though it would seem this is already registered).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM