我正在嘗試使用返回java DataHandler的基於SOAP的WS。我使用grails和apache httpclient.PostMethod。如果我使用soap工具,我會以附件的形式獲取文件(請參閱img - BTW,soapclient.com有一個很棒的工具)。返回DataHandler的Java SOAP web服務
在我的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進行SOAP調用,返回一個DataHandler?謝謝,我真的很感謝你能給予的幫助。