3
我想检查一个JAX-RS webservice请求,它包含正文中的有效XML。但是,此代码:是否有可能在JAX-RS/JAXB webservice中捕获SAXParseException?
@PUT
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.TEXT_XML)
@Path("/{objectID}")
public MyObject updateMyObject(@PathParam("objectID") String existingObjectID, JAXBElement<MyObject> object)
{
MyObject udpatedObject = null;
try
{
udpatedObject = object.getValue();
}
catch (Throwable ex)
{
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
// carry one with processing
}
返回500内部服务器错误,而不是预期的400错误。有没有办法捕捉异常?
的异常堆栈跟踪的起点是:
Local Exception Stack:
Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred unmarshalling the document
Internal Exception: org.xml.sax.SAXParseException: Premature end of file.
at org.eclipse.persistence.exceptions.XMLMarshalException.unmarshalException(XMLMarshalException.java:92)
感谢布莱斯! – sdoca 2010-08-03 21:49:49