Bader Javaid
Bader Javaid

Reputation: 41

How to Get Image from a SOAP Web Service

My Client will give me WSDL url which will return a JPEG Image and some text.

i haven't got the WSDL yet so i was wondering that How i will be getting image in SOAP Message??

<?xml version="1.0"?> 
<soap:Envelope></soap:Envelope>
<soap:Body>
**??**
</soap:Body>

Note the Question marks in SOAP Body. in which Tag / Format i will be getting the Image?

and after getting the image what datatype of Java i should use to set it in a POJO?

A bit Explanation or any Relevant Tutorail will be really helpfull..

Upvotes: 1

Views: 10890

Answers (3)

Evgeney Kuznetsov
Evgeney Kuznetsov

Reputation: 620

The service response may contain a picture as base64 or an attachment outside the envelope. Example decoding 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 already has an API for processing 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 
    }

Upvotes: 1

Karthikeyan Sukkoor
Karthikeyan Sukkoor

Reputation: 998

I hope this link will help you.. http://www.ibm.com/developerworks/xml/library/x-tippass/

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ps:retrieve 
       soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:ps="http://psol.com/2004/ws/retrieve">
<address xsi:type="xsd:base64Binary">d3d3Lm1hcmNoYWwuY29t</address>
</ps:retrieve>
</soapenv:Body>
</soapenv:Envelope>

Upvotes: 1

herry
herry

Reputation: 1738

I use base64binary for send document, jpg etc.

<soap:element name="jpg" type="xs:base64Binary" minOccurs="0" maxOccurs="1"/>

Upvotes: 0

Related Questions