Java 如何从SOAPEnvelope响应中获取字节[]
我正在尝试使用SOAP服务下载pdf文件。wsdl导入存在一些问题,因此存根没有正确的方法,我正在尝试使用apacheaxis服务调用方法下载该文件。Java 如何从SOAPEnvelope响应中获取字节[],java,soap,axis,Java,Soap,Axis,我正在尝试使用SOAP服务下载pdf文件。wsdl导入存在一些问题,因此存根没有正确的方法,我正在尝试使用apacheaxis服务调用方法下载该文件。 经过几天的讨论,客户的一个好人帮我解决了这个问题 SOAPEnvelope类支持类似于DOM的方法,我们可以使用这些方法导航到结果标记(fileByteStream),文本节点中的字符串表示实际上是由Byte64编码的,因此我们需要将其解码回原始字节[]。 经过几天的讨论,客户的一个好人帮我解决了这个问题 SOAPEnvelope类支持类似于
经过几天的讨论,客户的一个好人帮我解决了这个问题
SOAPEnvelope
类支持类似于DOM
的方法,我们可以使用这些方法导航到结果标记(fileByteStream
),文本节点中的字符串表示实际上是由Byte64编码的,因此我们需要将其解码回原始字节[]。
经过几天的讨论,客户的一个好人帮我解决了这个问题
SOAPEnvelope
类支持类似于DOM
的方法,我们可以使用这些方法导航到结果标记(fileByteStream
),文本节点中的字符串表示实际上是由Byte64编码的,因此我们需要将其解码回原始字节[]。
<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>
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());
}
//Invoke the WebService.
SOAPEnvelope resp = call.invoke(((org.apache.axis.SOAPPart) soapPart).getAsSOAPEnvelope());
//Extract and decode the fileStream from the response
byte[] output = Base64.decode(resp.getBody().getElementsByTagName("FileByteStream").item(0).getLastChild().getNodeValue());