I have a PersonProxy which contains one method which invokes third party webservice. AttachmentResponse is a wsdl generated class Decoder is configured to decode the response into Wsdl generated class. I have written an api which calls PersonProxy class method to get the response. While unmarshalling in decoder, in AttachmentResponse _return is coming as null. Not able to fetch binary data in _return variable.Please help on this
@FeignClient(name = "PersonProxyWebService", url = "${url}",configuration = ServiceConfiguration.class)
public interface PersonProxy {
@GetMapping(value = "", consumes = MediaType.TEXT_XML_VALUE, produces = {MediaType.APPLICATION_OCTET_STREAM_VALUE})
AttachmentResponse getResultAttachment(Long attachementId);
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "attachmentResponse", propOrder = {
"_return"
})
@XmlRootElement(name = "attachmentResponse")
public class AttachmentResponse {
@XmlElement(name = "return")
protected byte[] _return;
//getter and setter
}
public class SOAPDecoder implements Decoder {
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404)
return Util.emptyValueOf(type);
if (response.body() == null)
return null;
while (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
type = ptype.getRawType();
}
if (!(type instanceof Class)) {
throw new UnsupportedOperationException(
"SOAP only supports decoding raw types. Found " + type);
}
try (Scanner scanner = new Scanner(response.body().asInputStream())) {
Optional<String> soapEnvOpt= scanner.findAll(pattern).map(f->f.group(1)).findFirst();
if(soapEnvOpt.isPresent()) {
SOAPMessage message = MessageFactory.newInstance(soapProtocol).createMessage(null,new ByteArrayInputStream(soapEnvOpt.get().getBytes()));
if (message.getSOAPBody() != null) {
if (message.getSOAPBody().hasFault()) {
throw new SOAPFaultException(message.getSOAPBody().getFault());
}
Unmarshaller unmarshaller = jaxbContextFactory.createUnmarshaller((Class<?>) type);
if (this.useFirstChild) {
return unmarshaller.unmarshal(message.getSOAPBody().getFirstChild());
} else {
return unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());
}
}
}
} catch (SOAPException | JAXBException e) {
throw new DecodeException(response.status(), e.toString(), response.request(), e);
} finally {
if (response.body() != null) {
response.body().close();
}
}
return Util.emptyValueOf(type);
}
}
On debug mode response is coming like this but return field is coming >>>null in Wsdl generated class .
How to map contentId (cid) on client side to extract binary data?
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:attachmentResponse>
xmlns:ns2="http://mscs.com/emr">
<return>
<xop:Include
xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:180aba29-24c2-44cd-b0a5-63a3b5ff4189-5@cxf.apache.org"/>
</return>
</ns2:attachmentResponse>
</soap:Body>
</soap:Envelope>