Skip to content

Commit

Permalink
Merge pull request #39503 from ketola/39375-jaxb-exception
Browse files Browse the repository at this point in the history
Improve JAXB Exception handling
  • Loading branch information
gsmet authored Apr 22, 2024
2 parents a9f0f54 + 744ccfb commit 54db277
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 54db277

Please sign in to comment.