2012-02-09 19 views
0

私は、Java DataHandlerを返すSOAPベースのWSを消費しようとしています。私はgrailsとapache httpclient.PostMethodを使っています。私が石鹸ツールを使用する場合、ファイルを添付ファイルとして取得しています(img-BTW、soapclient.comには素晴らしいツールがあります)。DataHandlerを返すJava SOAP Webサービス

私のGrailsコントローラで

enter image description here

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呼び出しを行うサンプルコードを誰にでも教えてもらえますか?ありがとう、私は本当にあなたが与えることができる任意のヘルプに感謝します。

答えて

0

私はrequestHeaderを修正しました。 SOAPサービスが提供するファイルを取得しました。

method.addRequestHeader( "Content-Typeの"、 "text/xmlで") method.addRequestHeader(、 "同意する" "text/xmlで、アプリケーション/ xmlの; Q = 0.9") method.setRequestEntity(新しいStringRequestEntity (ペイロード))

関連する問題