Package feign.soap
Class SOAPEncoder
- java.lang.Object
-
- feign.soap.SOAPEncoder
-
- All Implemented Interfaces:
feign.codec.Encoder
public class SOAPEncoder extends Object implements feign.codec.Encoder
Encodes requests using SOAPMessage and JAXB for the body part.
Basic example with Feign.Builder:
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() .encoder(new SOAPEncoder(jaxbFactory)) .target(MyApi.class, "http://api"); ... try { api.getObject(new MyJaxbObjectRequest()); } catch (SOAPFaultException faultException) { log.info(faultException.getFault().getFaultString()); }The JAXBContextFactory should be reused across requests as it caches the created JAXB contexts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSOAPEncoder.BuilderCreates instances ofSOAPEncoder.
-
Constructor Summary
Constructors Constructor Description SOAPEncoder(feign.jaxb.JAXBContextFactory jaxbContextFactory)SOAPEncoder(SOAPEncoder.Builder builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidencode(Object object, Type bodyType, feign.RequestTemplate template)protected jakarta.xml.soap.SOAPMessagemodifySOAPMessage(jakarta.xml.soap.SOAPMessage soapMessage)Override this in order to modify the SOAP message object before it's finally encoded.
-
-
-
Constructor Detail
-
SOAPEncoder
public SOAPEncoder(SOAPEncoder.Builder builder)
-
SOAPEncoder
public SOAPEncoder(feign.jaxb.JAXBContextFactory jaxbContextFactory)
-
-
Method Detail
-
encode
public void encode(Object object, Type bodyType, feign.RequestTemplate template)
- Specified by:
encodein interfacefeign.codec.Encoder
-
modifySOAPMessage
protected jakarta.xml.soap.SOAPMessage modifySOAPMessage(jakarta.xml.soap.SOAPMessage soapMessage) throws jakarta.xml.soap.SOAPExceptionOverride this in order to modify the SOAP message object before it's finally encoded.
This might be useful to add SOAP Headers, which are not supported by this SOAPEncoder directly.
This is an example of how to add a security header:protected SOAPMessage modifySOAPMessage(SOAPMessage soapMessage) throws SOAPException { SOAPFactory soapFactory = SOAPFactory.newInstance(); String uri = "http://schemas.xmlsoap.org/ws/2002/12/secext"; String prefix = "wss"; SOAPElement security = soapFactory.createElement("Security", prefix, uri); SOAPElement usernameToken = soapFactory.createElement("UsernameToken", prefix, uri); usernameToken.addChildElement("Username", prefix, uri).setValue("test"); usernameToken.addChildElement("Password", prefix, uri).setValue("test"); security.addChildElement(usernameToken); soapMessage.getSOAPHeader().addChildElement(security); return soapMessage; }- Throws:
jakarta.xml.soap.SOAPException
-
-