0 Replies Latest reply on Jun 20, 2013 2:00 AM by rharibabu

    Handling BadRequestException in a RESTEasy Endpoint

    rharibabu

      Hi,

       

      I have written a JBoss RESTEasy Endpoint, which requires an XML input to be sent to it, using HTTP POST. In normal scenarios, the unmarshalling of this XML into POJO works perfectly.

       

      But the problem is

      -     when a service request comes without setting the "Content-Type" as "text/xml"

      -     when the input XML is empty

       

      In these scenarios, I encounter a big warning message in the JBoss logs which starts like the below mentioned snippet and goes on for another 50 - 150 lines.

       

      WARN  [org.jboss.resteasy.core.SynchronousDispatcher] (http-/127.0.0.1:8080-7) Failed executing POST /useradmin/update/: 
      org.jboss.resteasy.spi.BadRequestException: 
      Could not find message body reader for type: javax.xml.bind.JAXBElement<com.entity.Users> of content type: application/x-www-form-urlencoded
      

       

      WARN  [org.jboss.resteasy.core.SynchronousDispatcher] (http-/127.0.0.1:8080-1) Failed executing POST /useradmin/create/: 
      org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: javax.xml.bind.UnmarshalException
       - with linked exception: [org.xml.sax.SAXParseException: Premature end of file.]
      

       

      Even though these are warnings and does not affect the functionality of the service, these are called innumerous times from a scheduled job innumerous through out the day, so the logs become huge and starts clogging the JBoss, ultimately requiring to restart it frequently. I dont have control of the job which calls this service, so I wanted to catch these exceptions within the endpoint, provide a meaningful message and reduce the size of the logs generated. But these exceptions occur even before the control comes within the method, so they are not getting caught in the exception blocks. Can someone suggest ways to handle these RESTEasy exceptions ?