SOAPサービスを使用してpdfファイルをダウンロードしようとしています。 wsdlのインポートにいくつかの問題があります。したがって、スタブには適切なメソッドがなく、Apache Axisサービス呼び出しメソッドを使用してファイルをダウンロードしようとしています。 SOAPEnvelope応答からbyte []を取得する方法
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:getFileStreamResponse xmlns:ns2="http://spring.io/guides/gs-producing-web-service">
<ns2:FileByteStream>L1VzZXJzL3BrdW1hci9Eb2N1bWVudHMvTmFyZW5kcmFTaW5naC5wZGY=</ns2:FileByteStream>
</ns2:getFileStreamResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
これは私が使用しようとしているJavaコードです。
String SOAP_REQUEST = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
"\t\t\t\t xmlns:gs=\"http://spring.io/guides/gs-producing-web-service\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <gs:getFileStreamRequest>\n" +
" <gs:id>12313</gs:id>\n" +
" <gs:token>Ratakkdajd</gs:token>\n" +
" <gs:path>/Users/pkumar/Documents/NarendraSingh.pdf</gs:path>\n" +
" </gs:getFileStreamRequest>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
String HOST_ADDRESS = "http://localhost:8080/ws";
SOAPEnvelope resp = null;
try {
byte[] reqBytes = SOAP_REQUEST.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(reqBytes);
StreamSource ss = new StreamSource(bis);
MessageFactoryImpl messageFactory = new MessageFactoryImpl();
SOAPMessage msg = messageFactory.createMessage();
SOAPPart soapPart = msg.getSOAPPart();
soapPart.setContent(ss);
Service service = new Service();
org.apache.axis.client.Call call = (org.apache.axis.client.Call)service.createCall();
call.setTargetEndpointAddress(HOST_ADDRESS);
call.setProperty(call.CHECK_MUST_UNDERSTAND, false);
resp = call.invoke(((org.apache.axis.SOAPPart)soapPart).getAsSOAPEnvelope());
byte[] output = resp.getBodyElements().get(0).toString().getBytes();
return output;
} catch (Exception ex) {
throw new Exception(ex.getMessage());
}
私はSOAPEnvelope resp
からbyte[] FileByteStream
を取得する方法を見つけることができません。このようなSOAP APIを使用した経験があり、ファイルを作成しましたか?
WSDLインポートは、私は簡単に日のためにそれについて行くの後、このコード
CountriesPortServiceLocator locator = new CountriesPortServiceLocator();
CountriesPort service = locator.getCountriesPortSoap11(new URL("http://localhost:8080/ws"));
GetFileStreamRequest request = new GetFileStreamRequest(123,
"321323",
"remote_file_path.pdf");
GetFileStreamResponse response = service.getFileStream(request);
byte[] fileStream = response.getFileByteStream();
new FileOutputStream("output.pdf").write(fileStream);