用于下载文件(附件)的Java代码,我在点击Soap Web服务后得到了响应

时间:2016-08-23 09:34:13

标签: java web-services soap download

我在java中调用soap web服务,我得到一个附件作为响应我得到了附件的名称,我想要一个java代码下载并将该文件保存到我本地机器中的特定位置......谢谢

2 个答案:

答案 0 :(得分:0)

如果您可以访问本地计算机中的该服务,但您已登录到特定的远程服务器以下载该文件。

如果您对文件有任何附件响应,则可以使用以下代码轻松下载该文件

if(attachmentsResp!=null)
{
    for(int j=0; j<attachmentsResp.length; j++)
    {
        if(attachmentsResp[j].getContent()!=null)
        {
            //getting the file to particular Driver Name(C drive ,D drive)
            OutputStream out = new FileOutputStream("Driver Name:"+attachmentsResp[j].getName()+"."+attachmentsResp[j].getFileType());
        }         
    }
}

如果您想要解码到文件下载,请告诉我。

答案 1 :(得分:0)

1.  Login to the server by providing the server url and authentication credentials.
2.  Create the request object GetFileAttachmentRequestType for the getFileAttachment operation
3.  Create an array of requests of type SoapGetFileAttachmentRequestType. Batch operations may be
4.  performed by populating as many request objects as required to retrieve several files
5.  with one single operation. 
6.  For each batched request, specify the unique object from whose attachment tab
7.  files shall be retrieved. Supply class identifier and object number information
8.  for the same. 
9.  The exact specification of the attachment to be downloaded is defined as an
10. object of type SoapFileAttachmentRequestType. This object includes information
11. about rowId, a boolean to indicate whether all the files of the object are to
12. be downloaded and finally provision for fileIds to be used in special cases.  
13. In this sample the boolean element 'allFiles' is set to true. By using this 
14. option, the necessity to derive rowIds or fileIds is negated. The response
15. object will consist of all the files present in the attachment tab of the 
16. soap object specified in the request.          
17. The request objects are set and the soap Stub is used to make the getFileAttachment
18. webservice call. The status code obtained from the response object is printed to
19. verify the success of the getFileAttachment operation. 
20. If the status code is not 'SUCCESS', then populate the list of exceptions
21. returned by the webservice. 
22. If the webservice call was successful, then display information about the file(s) retrieved.