diff --git a/extensions/resteasy-reactive/rest-jaxb/deployment/src/test/java/io/quarkus/resteasy/reactive/jaxb/deployment/test/SimpleXmlTest.java b/extensions/resteasy-reactive/rest-jaxb/deployment/src/test/java/io/quarkus/resteasy/reactive/jaxb/deployment/test/SimpleXmlTest.java index 4cfe409be76ff..b9ce38f92fc64 100644 --- a/extensions/resteasy-reactive/rest-jaxb/deployment/src/test/java/io/quarkus/resteasy/reactive/jaxb/deployment/test/SimpleXmlTest.java +++ b/extensions/resteasy-reactive/rest-jaxb/deployment/src/test/java/io/quarkus/resteasy/reactive/jaxb/deployment/test/SimpleXmlTest.java @@ -75,6 +75,17 @@ public void testXml() { assertEquals(person.getLast(), secondPerson.getLast()); } + @Test + public void testInvalidXml() { + RestAssured + .with() + .body("Bob") + .contentType("application/xml") + .post("/simple/person") + .then() + .statusCode(400); + } + @Test public void testLargeXmlPost() { StringBuilder sb = new StringBuilder(); diff --git a/extensions/resteasy-reactive/rest-jaxb/runtime/src/main/java/io/quarkus/resteasy/reactive/jaxb/runtime/serialisers/ServerJaxbMessageBodyReader.java b/extensions/resteasy-reactive/rest-jaxb/runtime/src/main/java/io/quarkus/resteasy/reactive/jaxb/runtime/serialisers/ServerJaxbMessageBodyReader.java index 6a8226fba6d03..ab833016c9bc7 100644 --- a/extensions/resteasy-reactive/rest-jaxb/runtime/src/main/java/io/quarkus/resteasy/reactive/jaxb/runtime/serialisers/ServerJaxbMessageBodyReader.java +++ b/extensions/resteasy-reactive/rest-jaxb/runtime/src/main/java/io/quarkus/resteasy/reactive/jaxb/runtime/serialisers/ServerJaxbMessageBodyReader.java @@ -12,10 +12,12 @@ import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; import jakarta.ws.rs.ext.Providers; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.UnmarshalException; import jakarta.xml.bind.Unmarshaller; import org.jboss.resteasy.reactive.common.util.StreamUtil; @@ -73,6 +75,8 @@ protected Object unmarshal(InputStream entityStream, Class type) { JAXBElement item = getUnmarshall(type) .unmarshal(new StreamSource(entityStream), type); return item.getValue(); + } catch (UnmarshalException e) { + throw new WebApplicationException(e, Response.Status.BAD_REQUEST); } catch (JAXBException e) { throw new RuntimeException(e); }