Package feign.soap

Class SOAPDecoder

  • All Implemented Interfaces:
    Decoder

    public class SOAPDecoder
    extends Object
    implements Decoder
    Decodes SOAP responses using SOAPMessage and JAXB for the body part.

    The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts.

    A SOAP Fault can be returned with a 200 HTTP code. Hence, faults could be handled with no error on the HTTP layer. In this case, you'll certainly have to catch SOAPFaultException to get fault from your API client service. In the other case (Faults are returned with 4xx or 5xx HTTP error code), you may use SOAPErrorDecoder in your API configuration.

    
     public interface MyApi {
    
        @RequestLine("POST /getObject")
        @Headers({
          "SOAPAction: getObject",
          "Content-Type: text/xml"
        })
        MyJaxbObjectResponse getObject(MyJaxbObjectRequest request);
    
     }
    
     ...
    
     JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder()
         .withMarshallerJAXBEncoding("UTF-8")
         .withMarshallerSchemaLocation("http://apihost http://apihost/schema.xsd")
         .build();
    
     api = Feign.builder()
         .decoder(new SOAPDecoder(jaxbFactory))
         .target(MyApi.class, "http://api");
    
     ...
    
     try {
        api.getObject(new MyJaxbObjectRequest());
     } catch (SOAPFaultException faultException) {
        log.info(faultException.getFault().getFaultString());
     }
     
    See Also:
    SOAPErrorDecoder, SOAPFaultException