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

Improve JAXB Exception handling #39503

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ public void testXml() {
assertEquals(person.getLast(), secondPerson.getLast());
}

@Test
public void testInvalidXml() {
RestAssured
.with()
.body("<person><first>Bob</first></invalid>")
.contentType("application/xml")
.post("/simple/person")
.then()
.statusCode(400);
}

@Test
public void testLargeXmlPost() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,6 +75,8 @@ protected Object unmarshal(InputStream entityStream, Class<Object> type) {
JAXBElement<Object> 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);
}
Expand Down