首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回DataHandler的Java SOAP web服务

返回DataHandler的Java SOAP web服务
EN

Stack Overflow用户
提问于 2012-02-09 09:11:40
回答 1查看 887关注 0票数 0

我正在尝试使用一个基于SOAP的WS,它返回一个java DataHandler。我使用的是grails和apache httpclient.PostMethod。如果我使用soap工具,我会将文件作为附件(参见img - BTW,soapclient.com有一个很棒的工具)。

在我的Grails控制器中:

代码语言:javascript
复制
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调用的示例代码?谢谢,我真的很感谢你能给我的帮助。

EN

回答 1

Stack Overflow用户

发布于 2012-02-11 03:00:55

我修改了requestHeader,它起作用了。我得到了由SOAP服务提供的文件。

Method.addRequestHeader(“内容类型”,“文本/xml”) method.addRequestHeader("Accept",“文本/xml,应用程序/xml;q=0.9”)method.setRequestEntity(新的StringRequestEntity(有效负载))

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9204130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档