Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid throwing a RuntimeException when parsing an invalid XML body using JAXB #39375

Closed
davidreis97 opened this issue Mar 12, 2024 · 3 comments · Fixed by #39503
Closed

Avoid throwing a RuntimeException when parsing an invalid XML body using JAXB #39375

davidreis97 opened this issue Mar 12, 2024 · 3 comments · Fixed by #39503
Labels
area/jaxb kind/enhancement New feature or request
Milestone

Comments

@davidreis97
Copy link

Description

Throwing a RuntimeException when an invalid XML body gets deserialized by JAXB makes exception handling difficult using the ExceptionMapper mechanism.

Implementation ideas

Create a new exception, dedicated to JAXB deserialization errors, that wraps the UnmarshalException. Then it would be possible to handle that exception cleanly in a dedicated ExceptionMapper.

@davidreis97 davidreis97 added the kind/enhancement New feature or request label Mar 12, 2024
Copy link

quarkus-bot bot commented Mar 12, 2024

/cc @gsmet (jaxb)

@davidreis97 davidreis97 changed the title Avoid throwing a RuntimeException when XML parsing using JAXB throws a jakarta.xml.bind.UnmarshalException Avoid throwing a RuntimeException when parsing an invalid XML body using JAXB Mar 12, 2024
@ketola
Copy link
Contributor

ketola commented Mar 16, 2024

I compared the implementations of ServerJaxbMessageBodyReader to the json equivalent ServerJacksonMessageBodyReader and there, if the deserialization fails, a WebApplicationException is thrown.
Would that work for Jaxb also? I'd assume the same result: Bad Request would be a good default here also.

But the same way as in the jackson, the exceptions related to the configuration of the deserialization should be separated and thrown as runtime exceptions resulting in Internal Server Error.

Links:
ServerJacksonMessageBodyReader

ServerJaxbMessageBodyReader

I've been looking for an issue to contribute to Quarkus and I would like to work on this one if possible.

@ketola
Copy link
Contributor

ketola commented Mar 19, 2024

Based on my tests in the Draft PR I noticed that the resteasy-reactive-jaxb and resteasy-jaxb behave differently. The reactive implementation returns 500 when an invalid xml is sent and the other one returns 400. My suggestion is that resteasy-reactive-jaxb would be modified to work like resteasy-reactive-jackson works when invalid json is sent -> WebApplicationException resulting in http 400.
I could go on and try to fix it if this sounds like a plan? I would also need to add an integration test module as I have done in the pr to bring up the issue and verify the fix.

@quarkus-bot quarkus-bot bot added this to the 3.11 - main milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jaxb kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants