users@glassfish.java.net

Re: How to validate request xml for POST/PUT method

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 02 Mar 2010 09:52:09 +0100

Hi Sumved,

Register one or more implementation of ContextResolver<Unmarshaller>
[1] for the JAXB classes you need to validate.

   @Provider
   public class MyResolver implements ContextResolver<Unmarshaller> {
      private final JAXBContext jc;
      private final Schema s; // [2]
      public MyResolver() {
        // create the JAXBContext
        jc = ...;
        // set the schema
        s = ...;
      }

      public Unmarshaller getContext(java.lang.Class<?> type) {
        if (/type is to be validated and part of the JAXBContext/) {
          Unmarshaller u = jc.createUnmarshaller();
          u.setSchema(s);
          return u;
        } else {
          return null;
        }
      }
   }

The following email thread may also be of interest:

http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users+JAXB+validation#query
:list%3Anet.java.dev.jersey.users%20JAXB%20validation+page:1+mid:ohytzrd6rak3yuvr+state:results

Paul.

[1] https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/ext/ContextResolver.html

[2] http://java.sun.com/javase/6/docs/api/javax/xml/validation/Schema.html

On Feb 25, 2010, at 10:09 AM, glassfish_at_javadesktop.org wrote:

> Hi everyone,
>
> I am new to JAX-RS. And, I want to validate request xml of POST/PUT
> http methods against an XSD file.
>
> Do you have an example for this?
>
> Thanking you.
>
> Regards,
> Sumved Shami
> [Message sent by forum member 'sumved' (sumved.shami_at_gmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=388587
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>