users@jaxb.java.net

Re: JAXB Swallowing Exceptions

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 23 May 2012 10:56:05 +0200

All right, but also mentioned in the discussion you are referencing is the
site for JAX-WS issues: https://jax-ws.dev.java.net/issues/
It seems to me that your problem is a JAX-WS issue, since you can do
what you want using a proper Unmarshaller setup.

Some leniency in parsing is there by design; see the JAXB 2.0 specification.

-W

On 23/05/2012, Tim Canavan <tim.canavan_at_googlemail.com> wrote:
> JAXB 2.0 swallows Number format exceptions because it regards them as
> recoverable.
>
> We tried using our Factory using @UsesJAXBContext to try and override the
> createUnmarshaller and
> set the EventHandler of the Unmarshaller to the DefaultValidationHandler
> but found that this was not possible
>
> as JAXBContextImpl the default is also used in the bridge code.
>
> We are bootstrapping jaxws using
>
> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
>
> There is no way to configure the level of severity of the validation you
> would like.
>
> JAXB reports an error only in the case of FATAL errors. This is clearly
> wrong as it allows
> invalid data to enter the system.
>
>
> // from UnmarshallerContext// calls Unmarshaller getEventHandler.
> ValidationEventHandler eventHandler = parent.getEventHandler();
>
> boolean recover = eventHandler.handleEvent(event); // JAXB
> handles event only if is fatal // it considers ERRORS as
> recoverable !!!
>
> // if the handler says "abort", we will not return the object
> // from the unmarshaller.getResult() if(!recover)
> aborted = true;
>
> if( !canRecover || !recover )
> throw new SAXParseException2( event.getMessage(), locator,
> new UnmarshalException(
> event.getMessage(),
> event.getLinkedException() ) );
>
>
> The same problem is discussed here.
>
> http://old.nabble.com/Setting-marshaller-properties-with-JAX-WS-td29340141.html
>