OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.51k stars 1.93k forks source link

Enhance SoapDecoder by using Content Type from Response as Mime Type #1732

Open StefanFellinger opened 2 years ago

StefanFellinger commented 2 years ago

By sending a soap request to an external service, i've found that the response of that soap call contains the Content-Type "multipart/related; type="application/xop+xml"; boundary=...".

The result is that the soap Message unmarshalling fails with some error "Unexpected content...". I've fixed that by creating a copy of SoapDecoder and propagate the Content-Type of the response to the MessageFactory. After that the Soap Envelope was unmarshalled as expected.

The relevant part that i've changed is:

final MimeHeaders mimeHeaders = new MimeHeaders();
final String contentType = response.headers().get("Content-Type").stream().collect(Collectors.joining(";"));
mimeHeaders.setHeader("Content-Type", contentType);
SOAPMessage message = MessageFactory.newInstance(soapProtocol)
                                    .createMessage(mimeHeaders, response.body().asInputStream());

Would be nice if it's possible to always use the Content-Type from the Response, but i don't know if there are any other pitfalls when doing that in general.

Kind regards,

Stefan

kdavisk6 commented 2 years ago

We welcome contributions from all users. Check the CONTRIBUTING guide in our repository for information on how to submit a PR.

For something like this, consider a configuration property for the SoapDecoder that allows for Content-Type propagation, but implement is as disabled by default. This will enable the feature for those that want it and keep it backward compatible.

zaenk commented 2 years ago

In addition to MimeHeaders propagation javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller must also be set to properly support SOAP MTOM & XOP. For an example, see this SO answer: https://stackoverflow.com/a/24417032