OpenFeign/feign

Enhance SoapDecoder by using Content Type from Response as Mime Type

Open

#1.732 aberto em 25 de ago. de 2022

Ver no GitHub
 (2 comments) (1 reaction) (0 assignees)Java (1.911 forks)batch import
help wantedproposal

Métricas do repositório

Stars
 (9.070 stars)
Métricas de merge de PR
 (Mesclagem média 3d 8h) (59 fundiu PRs em 30d)

Description

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

Guia do colaborador