@Override
  public void encode(Object object, Type bodyType, RequestTemplate template) {
    if (!(bodyType instanceof Class)) {
      throw new UnsupportedOperationException(
          "SOAP only supports encoding raw types. Found " + bodyType);
    }
    try {
      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      Marshaller marshaller = jaxbContextFactory.createMarshaller((Class<?>) bodyType);
      marshaller.marshal(object, document);
      SOAPMessage soapMessage = MessageFactory.newInstance(soapProtocol).createMessage();
      soapMessage.setProperty(
          SOAPMessage.WRITE_XML_DECLARATION, Boolean.toString(writeXmlDeclaration));
      soapMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charsetEncoding.displayName());
      soapMessage.getSOAPBody().addDocument(document);

      soapMessage = modifySOAPMessage(soapMessage);

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      if (formattedOutput) {
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        t.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(bos));
      } else {
        soapMessage.writeTo(bos);
      }
      template.body(new String(bos.toByteArray()));
    } catch (SOAPException
        | JAXBException
        | ParserConfigurationException
        | IOException
        | TransformerFactoryConfigurationError
        | TransformerException e) {
      throw new EncodeException(e.toString(), e);
    }
  }
Encodes requests using SOAPMessage and JAXB for the body part. <br>

<p>Basic example with with Feign.Builder:

<pre>

public interface MyApi {

   &#64;RequestLine("POST /getObject")
   &#64;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()
    .encoder(new SOAPEncoder(jaxbFactory))
    .target(MyApi.class, "http://api");

...

try {
   api.getObject(new MyJaxbObjectRequest());
} catch (SOAPFaultException faultException) {
   log.info(faultException.getFault().getFaultString());
}
</pre>

<p>The JAXBContextFactory should be reused across requests as it caches the created JAXB
contexts.
soap/src/main/java/feign/soap/SOAPEncoder.java