MCPcopy Index your code
hub / github.com/OpenFeign/feign / SOAPDecoder

Class SOAPDecoder

soap-jakarta/src/main/java/feign/soap/SOAPDecoder.java:78–178  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

76 * @see SOAPFaultException
77 */
78public class SOAPDecoder implements Decoder {
79
80 private final JAXBContextFactory jaxbContextFactory;
81 private final String soapProtocol;
82 private final boolean useFirstChild;
83
84 public SOAPDecoder(JAXBContextFactory jaxbContextFactory) {
85 this.jaxbContextFactory = jaxbContextFactory;
86 this.soapProtocol = SOAPConstants.DEFAULT_SOAP_PROTOCOL;
87 this.useFirstChild = false;
88 }
89
90 private SOAPDecoder(Builder builder) {
91 this.soapProtocol = builder.soapProtocol;
92 this.jaxbContextFactory = builder.jaxbContextFactory;
93 this.useFirstChild = builder.useFirstChild;
94 }
95
96 @Override
97 public Object decode(Response response, Type type) throws IOException {
98 if (response.status() == 404) return Util.emptyValueOf(type);
99 if (response.body() == null) return null;
100 while (type instanceof ParameterizedType) {
101 ParameterizedType ptype = (ParameterizedType) type;
102 type = ptype.getRawType();
103 }
104 if (!(type instanceof Class)) {
105 throw new UnsupportedOperationException(
106 "SOAP only supports decoding raw types. Found " + type);
107 }
108
109 try {
110 SOAPMessage message =
111 MessageFactory.newInstance(soapProtocol)
112 .createMessage(null, response.body().asInputStream());
113 if (message.getSOAPBody() != null) {
114 if (message.getSOAPBody().hasFault()) {
115 throw new SOAPFaultException(message.getSOAPBody().getFault());
116 }
117
118 Unmarshaller unmarshaller = jaxbContextFactory.createUnmarshaller((Class<?>) type);
119
120 if (this.useFirstChild) {
121 return unmarshaller.unmarshal(message.getSOAPBody().getFirstChild());
122 } else {
123 return unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());
124 }
125 }
126 } catch (SOAPException | JAXBException e) {
127 throw new DecodeException(response.status(), e.toString(), response.request(), e);
128 } finally {
129 if (response.body() != null) {
130 response.body().close();
131 }
132 }
133 return Util.emptyValueOf(type);
134 }
135

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected