我的客户将向我提供 WSDL URL,它将返回 JPEG 图像 和一些文本。
我还没有获得 WSDL,所以我想知道如何在 SOAP 消息中获取图像?
<?xml version="1.0"?>
<soap:Envelope></soap:Envelope>
<soap:Body>
**??**
</soap:Body>
请注意 SOAP 正文中的问号。 我将使用哪种标签/格式获取图像?
获取图像后,我应该使用什么Java数据类型来将其设置在POJO中?
一点解释或任何相关的教程都会非常有帮助..
最佳答案
服务响应可能包含 Base64 格式的图片或信封外的附件。 Base64 解码示例:
public static BufferedImage decodeToImage(String imageString) {
BufferedImage image = null;
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
return image;
}
JAVA已经有处理的API SOAP with attachments .
SOAPMessage response = connection.call(requestMessage, serviceURL);
Iterator attachmentsIterator = response.getAttachments();
while (attachmentsIterator.hasNext()) {
AttachmentPart attachment = (AttachmentPart) attachmentsIterator.next();
//do something with attachment
}
关于java - 如何从 SOAP Web 服务获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18911351/