我必须为使用者和提供者都实现Grails RESTful Web服务。
提供者必须返回pdf文档,而使用者必须处理它并将其保存到db。
作为提供者,如何使用grails rest服务返回pdf文档。
我在肥皂网络服务中使用MTOM来实现此目的,但不确定如何在Grails rest服务中实现。

请建议我如何使用一些示例代码来实现这一目标。

谢谢

请您参考如下方法:

这是我所做的,这是您可以为制作人做的

>  def boas = callservicetogenerateReport // this should return an 
> byteArray 
>         // setting the content type 
>         response.setContentType("application/pdf"); 
>         response.setHeader("Content-Disposition", "attachment;filename=sample.pdf") 
>         response.setContentLength(boas.size()); 
>         // write ByteArrayOutputStream to the ServletOutputStream 
>         response.outputStream << boas.toByteArray() 
>         response.outputStream.flush() 
>         response.outputStream.close() 

对于Consumer,这就是我在rest call 中所做的事情,该 call 实际上处理了通过邮寄提交文件的用户。
request.multiFileMap."files[]".each {file -> 
                def newFile = new Expando(name: file.originalFilename, size: file.size) 
                callServicetoAddFileToDB(file) 
  } 

希望这可以帮助


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!