-->

Spring boot multipart SOAP web service client not

2019-08-27 15:29发布

问题:

I am developing a spring boot SOAP Webservice client which calls a SOAP service and that SOAP service return a response body with attachment. Attachment will be MTOM attachment.

With my code I can able to read SOAP web service response body but not been able to get the attachment content.

I am using Spring Boot 1.5.2 and my configurations looks like below.

@Bean(name="myMarshaller")
    public Jaxb2Marshaller myMarshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setPackagesToScan(new String[] {"com.mypack.header",
                "com.soapservice.schema",               
                "com.soapservice.exception"});
        marshaller.setMtomEnabled(true);
        return marshaller;
    }

@Bean(name = "myAppJaxbContext")
    public JAXBContext myAppJaxbContext() throws XmlMappingException
    { 
        return myMarshaller().getJaxbContext();

    }

@Bean(name = "messageFactory")
    public SaajSoapMessageFactory messageFactory() 
    {
        return new SaajSoapMessageFactory();
    }

@Bean(name = "myAppWSTemplate")
    public WebServiceTemplate myAppWSTemplate() throws SOAPException
    {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setMessageFactory(messageFactory());
        webServiceTemplate.setCheckConnectionForFault(false);
        webServiceTemplate.setCheckConnectionForError(false);
        webServiceTemplate.setUnmarshaller(myMarshaller());
        webServiceTemplate.setMarshaller(myMarshaller());

        return webServiceTemplate;
    }

SOAP Service Response

<mySoapResponse xmlns:e="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:dime="http://schemas.xmlsoap.org/ws/2002/04/reference/" xmlns:fn40="http://www.filenet.com/soapservice/schema"  xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema">
         <FiledetailResponse retrievalName="myapp.pdf" totalSize="177712">
            <Content>
               <Binary>
                  <xop:Include href="cid:v1-1234abc@mtom.p128ae.myapp.com"/>
               </Binary>
            </Content>
         </FiledetailResponse>
      </mySoapResponse>

With above response body i will get an attachment as MIME type. But when try to unmarshal this response body content.getBinary() will be always come as empty. But when I print the SOAP response i can see attachment binary.

Am I missing something in my configuration. Is there any example for Spring Boot Webservice client for multipart SOAP.