我正在尝试使用一个基于SOAP的WS,它返回一个java DataHandler。我使用的是grails和apache httpclient.PostMethod。如果我使用soap工具,我会将文件作为附件(参见img - BTW,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调用的示例代码?谢谢,我真的很感谢你能给我的帮助。
发布于 2012-02-11 03:00:55
我修改了requestHeader,它起作用了。我得到了由SOAP服务提供的文件。
Method.addRequestHeader(“内容类型”,“文本/xml”) method.addRequestHeader("Accept",“文本/xml,应用程序/xml;q=0.9”)method.setRequestEntity(新的StringRequestEntity(有效负载))
https://stackoverflow.com/questions/9204130
复制相似问题