Hello,

> I guess if a schema is open enough to accept either A or B representations, 
> then there's no bug.

That is not the case here.

> I can see that Unmarshaller can also accept ValidationEventHandler 
> ("validationHandler" provider property). Not sure if it can help - may be you 
> can restrict it there somehow.

Well, we are using the schema validation setup this way already:

<bean name"myJaxbProvider" class="...">
  <property name="catalogLocation" value="..."/>
  <property name="schemaLocations" value="...">
    <list>
      <value>classpath:/xsd/foo.xsd</value>
      ...
    </list>
  </property>
</bean>

So we have to setup the validation twice or remove this kind of validation, we 
have been talking about lately, and use the validationHandler instead?

> May my using JAXBElement<A> instead of A is more restrictive, can you try it ?

Tested this with no difference in the result.


Best,

-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]] 
Sent: Thursday, September 20, 2012 2:27 PM
To: [email protected]
Cc: Voß, Marko
Subject: Re: UnmarshalException instead of SchemaValidationException

Hi
On 20/09/12 13:02, Voß, Marko wrote:
> Hello,
>
> Say, we have a JAX-RS method like this:
>
> @PUT
> @Path("/foo")
> @Produces(MediaType.TEXT_XML)
> @Consumes(MediaType.TEXT_XML)
> public static A create(A a);
>
> In a negative test, I send some XML to this service, which is wrong XML for 
> type A. Let's say the XML is of type B. The XML passes the schema validation, 
> because of it is valid for type B but this method expects type A and so we 
> get a UnmarshalException instead of the SchemaValidationException complaining 
> about the wrong element found.
>
> Is it a bug, that the schema validation is not using the schema for type A? 
> It looks like it is using the schema, which is responsible for the root 
> element of the passed XML if found.
>

I guess if a schema is open enough to accept either A or B representations, 
then there's no bug.

I can see that Unmarshaller can also accept ValidationEventHandler 
("validationHandler" provider property). Not sure if it can help - may be you 
can restrict it there somehow.

May my using JAXBElement<A> instead of A is more restrictive, can you try it ?

Cheers, Sergey

> best,
>
>
> -------------------------------------------------------
>
> Fachinformationszentrum Karlsruhe, Gesellschaft für 
> wissenschaftlich-technische Information mbH.
> Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 
> 101892.
> Geschäftsführerin: Sabine Brünger-Weilandt.
> Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.
>
>


-------------------------------------------------------

Fachinformationszentrum Karlsruhe, Gesellschaft für wissenschaftlich-technische 
Information mbH. 
Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 
101892. 
Geschäftsführerin: Sabine Brünger-Weilandt. 
Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.


Reply via email to