[英]Java SOAP web service returning DataHandler
我正在嘗試使用返回Java DataHandler的基於SOAP的WS。 我正在使用grails和apache httpclient.PostMethod。 如果我使用soap工具,那么我將以附件的形式獲取文件(請參見img-順便說一句,soapclient.com有一個很棒的工具)。
在我的Grails控制器中:
class connectToSoap {
def getFile = {
def payload = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org
<userLogicalId>${params.userLogicalId}</userLogicalId>
<clientLogicalId>${params.clientLogicalId}</clientLogicalId>
</mns1:getFile></SOAP-ENV:Body>
</SOAP-ENV:Envelope> // Summarized payload
"""
def method = new PostMethod(url)
method.setRequestHeader("Content-disposition", "attachment;filename=antocha.zip")
method.addRequestHeader("Content-Type","application/octet-stream")
method.setRequestEntity(new StringRequestEntity(payload))
def client = new HttpClient()
def statusCode = client.executeMethod(method)
InputStream inputStream = method.getResponseBodyAsStream()
OutputStream out = new FileOutputStream(new File("c:\\var\\nfile.zip"))
byte[] bytes = new byte[1024]
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read)
}
inputStream.close();
out.flush();
out.close();
method.releaseConnection()
}
當我運行此命令時,我收到inputStream.read異常(groovy.lang.MissingPropertyException:無此類屬性)。 我猜對附件文件的處理應該不同嗎?
任何人都可以使用httpclient.PostMethod給我一個示例代碼來進行返回DataHandler的SOAP調用嗎? 謝謝,我非常感謝您能提供的任何幫助。
我修改了requestHeader,它起作用了。 我得到了由SOAP服務提供文件。
method.addRequestHeader(“ Content-Type”,“ text / xml”)method.addRequestHeader(“ Accept”,“ text / xml,application / xml; q = 0.9”)method.setRequestEntity(new StringRequestEntity(payload))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.