简体   繁体   English

Restlet ServerResource用于二进制数据

[英]Restlet ServerResource for binary data

I can send binary data from a Restlet Client like so 我可以像这样从Restlet客户端发送二进制数据

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? 但是,如何从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. 如果您的客户端和服务器都是java + restlet,我建议尽可能将其提取到接口中。 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. 这是PUT方法的文档: 这里。 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). 虽然,这似乎表明您不一定想要完整的mime类型,所以您可能必须四处寻找或自己注册它(尽管看起来这已经被注册了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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