public class SOAPEncoder extends Object implements Encoder
Basic example with 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.
| Modifier and Type | Class and Description |
|---|---|
static class |
SOAPEncoder.Builder
Creates instances of
SOAPEncoder. |
Encoder.DefaultMAP_STRING_WILDCARD| Constructor and Description |
|---|
SOAPEncoder(JAXBContextFactory jaxbContextFactory) |
SOAPEncoder(SOAPEncoder.Builder builder) |
| Modifier and Type | Method and Description |
|---|---|
void |
encode(Object object,
Type bodyType,
RequestTemplate template) |
protected SOAPMessage |
modifySOAPMessage(SOAPMessage soapMessage)
Override this in order to modify the SOAP message object before it's finally encoded.
|
public SOAPEncoder(SOAPEncoder.Builder builder)
public SOAPEncoder(JAXBContextFactory jaxbContextFactory)
public void encode(Object object, Type bodyType, RequestTemplate template)
protected SOAPMessage modifySOAPMessage(SOAPMessage soapMessage) throws SOAPException
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;
}
SOAPExceptionCopyright © 2012–2022 OpenFeign. All rights reserved.