feign icon indicating copy to clipboard operation
feign copied to clipboard

Feign Soap Exceptions

Open alabotski opened this issue 4 years ago • 4 comments

JAXB by default silently ignores errors.
Can you add this code to throw an exception if something goes wrong. To SoapEncoder & SoapDecoder


 unmarshaller.setEventHandler(
    new ValidationEventHandler() {
        @Override
        public boolean handleEvent(ValidationEvent event ) {
            throw new RuntimeException(event.getMessage(),
                                       event.getLinkedException());
        }
});

alabotski avatar Aug 10 '21 10:08 alabotski

By javax.xml.bind.ValidationEventHandler#handleEvent contract you can simply return false and JAXB will throw an exception:

unmarshaller.setEventHandler(event -> false);

However I wouldn't add this sort of handling by default, as all of the written code already relies on the default JAXB behavior and instead provide means to customize feign.jaxb.JAXBContextFactory.Builder.

virtual-machinist avatar Nov 03 '21 10:11 virtual-machinist

I agree with @virtual-machinist, this is something you'll have to provide to the SOAP encoder/decoder components. Those components should accept an external JAXBContext. If not, please open an enhancement issue/pr to do so.

kdavisk6 avatar Mar 24 '22 14:03 kdavisk6

@kdavisk6 I'm afraid it's not that simple and we have to modify feign.jaxb.JAXBContextFactory even if we allow external JAXBContext for SOAP encoders and decoders.

AFAIK you can only set the ValidationEventHandler when Marshaller and Unmarshaller instances are created, i.e. at some point in feign.jaxb.JAXBContextFactory#createUnmarshaller or feign.jaxb.JAXBContextFactory#createMarshaller.

In other words something like

public Builder withUnmarshallerValidationEventHandler(ValidationEventHandler handler) {
 ...
}

public Builder withMarshallerValidationEventHandler(ValidationEventHandler handler) {
 ...
}

is needed + modifications to the create factory methods.

If this is a reasonable proposal, I can make a branch + PR. :smiley:

virtual-machinist avatar Jun 12 '23 13:06 virtual-machinist

@kdavisk6 I've created a PR (#2084) that hopefully addresses this issue.

virtual-machinist avatar Jun 14 '23 14:06 virtual-machinist