2013-04-24 83 views
1

我必須爲消費者和提供者實現Grails RESTful Web服務。 提供程序必須返回PDF文檔,消費者必須處理它並將其保存到數據庫。 作爲提供者如何使用grails rest服務返回pdf文檔。 我在肥皂web服務中使用MTOM來實現這一點,但不知道如何在Grails休息服務中實現。Grails-帶pdf附件的RESTful Web服務?

請告訴我如何用一些示例代碼實現此目的。

感謝

回答

2

這是我做的,這是你能爲生產者

> 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() 

對於消費這做的是什麼,我在休息調用,它實際上處理用戶提交的文件做了通過郵政。

request.multiFileMap."files[]".each {file -> 
       def newFile = new Expando(name: file.originalFilename, size: file.size) 
       callServicetoAddFileToDB(file) 
    } 

希望這有助於

+0

關於消費者 - 作爲一個消費者我已經發送請求數據,並需要從供應商..獲得PDF @製片人:你覺得我已經將它寫入反應,而不是我可以在BYYARRAY中獲得PDF作爲迴應,不是嗎? – 2013-04-24 17:32:49

+0

來自消費者,你是否向提供商發佈文件? – 2013-04-24 17:36:15

+1

問題 - 用戶如何選擇要發送的文件? – allthenutsandbolts 2013-04-24 17:36:23