0 Replies Latest reply on Sep 28, 2011 6:42 AM by epi

    AS7 : How to enable a custom MessageBodyReader, @Provider did nothing

    epi Newbie

      Hi,

       

      I have a wierd problem. I'm using @Provider to annote my Mapper Exception and it's work fine, but when I'm using it to annote the class below it won't work at all.

       

      @Consumes("application/x-java-serialized-object")

      @Provider

      public class JAXBSpecificMarshaller implements MessageBodyReader

      {

       

        @PersistenceContext(unitName = "primary", type = PersistenceContextType.EXTENDED)

        private EntityManager em;

       

        @Override

        public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType)

        {

          return type.isAnnotationPresent(XmlRootElement.class);

        }

       

        @Override

        public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException

        {

          try

          {

            //    DataAdapter dataAdapter = new DataAdapter(em);

            //unmarshaller.setAdapter(dataAdapter);

            System.out.println(type.getName());

            JAXBContext ctx = JAXBContext.newInstance(type);

            Unmarshaller unmarshaller = ctx.createUnmarshaller();

            return unmarshaller.unmarshal(entityStream);

          }

          catch ( JAXBException ex )

          {

            throw new RuntimeException(ex);

          }

        }

       

       

      }

       

      My main reason is to be able to use specific adapter to retrieve an object by passing its id in the input xml. I followed this http://stackoverflow.com/questions/7278406/serialize-a-jaxb-object-via-its-id/7285517#7285517 . But to initialize the adapter with my enitymanger I was told to use MessageBodyReader to do so.

       

      Thank you for your help.