class DOMSourceEntityProvider implements EntityProvider<DOMSource> {

    @Override
    public DOMSource readFrom(Class<DOMSource> type,
                              Type genericType,
                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> httpHeaders,
                              InputStream entityStream) throws IOException {
        try {
            DocumentBuilderFactory factory = createFeaturedDocumentBuilderFactory();
            factory.setNamespaceAware(true);
            Document d = factory.newDocumentBuilder().parse(entityStream);
            return new DOMSource(d);
        } catch (SAXParseException saxpe) {
            LOG.debug(saxpe.getMessage(), saxpe);
            return null;
        } catch (SAXException | ParserConfigurationException saxe) {
            throw new IOException(String.format("Can't read from input stream, %s", saxe));
        }
    }

}