Class AbstractJaxbElementProvider

  • All Implemented Interfaces:
    javax.ws.rs.ext.MessageBodyReader<javax.xml.bind.JAXBElement<?>>, javax.ws.rs.ext.MessageBodyWriter<javax.xml.bind.JAXBElement<?>>
    Direct Known Subclasses:
    XmlJaxbElementProvider

    public abstract class AbstractJaxbElementProvider
    extends AbstractJaxbProvider<javax.xml.bind.JAXBElement<?>>
    An abstract provider for JAXBElement.

    Implementing classes may extend this class to provide specific marshalling and unmarshalling behaviour.

    When unmarshalling a UnmarshalException will result in a WebApplicationException being thrown with a status of 400 (Client error), and a JAXBException will result in a WebApplicationException being thrown with a status of 500 (Internal Server error).

    When marshalling a JAXBException will result in a WebApplicationException being thrown with a status of 500 (Internal Server error).

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractJaxbElementProvider​(javax.ws.rs.ext.Providers providers)
      Inheritance constructor.
      AbstractJaxbElementProvider​(javax.ws.rs.ext.Providers providers, javax.ws.rs.core.MediaType resolverMediaType)
      Inheritance constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isReadable​(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)  
      boolean isWriteable​(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)  
      protected abstract javax.xml.bind.JAXBElement<?> readFrom​(java.lang.Class<?> type, javax.ws.rs.core.MediaType mediaType, javax.xml.bind.Unmarshaller unmarshaller, java.io.InputStream entityStream)
      Read JAXB element from an entity stream.
      javax.xml.bind.JAXBElement<?> readFrom​(java.lang.Class<javax.xml.bind.JAXBElement<?>> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> httpHeaders, java.io.InputStream inputStream)  
      void writeTo​(javax.xml.bind.JAXBElement<?> t, java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> httpHeaders, java.io.OutputStream entityStream)  
      protected abstract void writeTo​(javax.xml.bind.JAXBElement<?> element, javax.ws.rs.core.MediaType mediaType, java.nio.charset.Charset charset, javax.xml.bind.Marshaller marshaller, java.io.OutputStream entityStream)
      Write JAXB element to an entity stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractJaxbElementProvider

        public AbstractJaxbElementProvider​(javax.ws.rs.ext.Providers providers)
        Inheritance constructor.
        Parameters:
        providers - JAX-RS providers.
      • AbstractJaxbElementProvider

        public AbstractJaxbElementProvider​(javax.ws.rs.ext.Providers providers,
                                           javax.ws.rs.core.MediaType resolverMediaType)
        Inheritance constructor.
        Parameters:
        providers - JAX-RS providers.
        resolverMediaType - JAXB component context resolver media type to be used.
    • Method Detail

      • isReadable

        public boolean isReadable​(java.lang.Class<?> type,
                                  java.lang.reflect.Type genericType,
                                  java.lang.annotation.Annotation[] annotations,
                                  javax.ws.rs.core.MediaType mediaType)
      • isWriteable

        public boolean isWriteable​(java.lang.Class<?> type,
                                   java.lang.reflect.Type genericType,
                                   java.lang.annotation.Annotation[] annotations,
                                   javax.ws.rs.core.MediaType mediaType)
      • readFrom

        public final javax.xml.bind.JAXBElement<?> readFrom​(java.lang.Class<javax.xml.bind.JAXBElement<?>> type,
                                                            java.lang.reflect.Type genericType,
                                                            java.lang.annotation.Annotation[] annotations,
                                                            javax.ws.rs.core.MediaType mediaType,
                                                            javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> httpHeaders,
                                                            java.io.InputStream inputStream)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readFrom

        protected abstract javax.xml.bind.JAXBElement<?> readFrom​(java.lang.Class<?> type,
                                                                  javax.ws.rs.core.MediaType mediaType,
                                                                  javax.xml.bind.Unmarshaller unmarshaller,
                                                                  java.io.InputStream entityStream)
                                                           throws javax.xml.bind.JAXBException
        Read JAXB element from an entity stream.
        Parameters:
        type - the type that is to be read from the entity stream.
        mediaType - the media type of the HTTP entity.
        unmarshaller - JAXB unmarshaller to be used.
        entityStream - the InputStream of the HTTP entity. The caller is responsible for ensuring that the input stream ends when the entity has been consumed. The implementation should not close the input stream.
        Returns:
        JAXB element representing the entity.
        Throws:
        javax.xml.bind.JAXBException - in case entity unmarshalling fails.
      • writeTo

        public final void writeTo​(javax.xml.bind.JAXBElement<?> t,
                                  java.lang.Class<?> type,
                                  java.lang.reflect.Type genericType,
                                  java.lang.annotation.Annotation[] annotations,
                                  javax.ws.rs.core.MediaType mediaType,
                                  javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> httpHeaders,
                                  java.io.OutputStream entityStream)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTo

        protected abstract void writeTo​(javax.xml.bind.JAXBElement<?> element,
                                        javax.ws.rs.core.MediaType mediaType,
                                        java.nio.charset.Charset charset,
                                        javax.xml.bind.Marshaller marshaller,
                                        java.io.OutputStream entityStream)
                                 throws javax.xml.bind.JAXBException
        Write JAXB element to an entity stream.
        Parameters:
        element - JAXB element to be written to an entity stream.
        mediaType - the media type of the HTTP entity.
        charset - character set to be used.
        marshaller - JAXB unmarshaller to be used.
        entityStream - the InputStream of the HTTP entity. The caller is responsible for ensuring that the input stream ends when the entity has been consumed. The implementation should not close the input stream.
        Throws:
        javax.xml.bind.JAXBException - in case entity marshalling fails.