users@jersey.java.net

[Jersey] javax.xml.bind.JAXBException: XXXType is not known to this context

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Thu, 09 Feb 2012 12:53:07 -0500

I am getting the following exception in my jersey endpoint built using
jersey 1.10:

javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
  - with linked exception:
[javax.xml.bind.JAXBException: net.opengis.gml.v_3_1_1.PolygonType is
not known to this context]
         at
com.sun.jersey.core.provider.jaxb.AbstractJAXBElementProvider.writeTo(AbstractJAXBElementProvider.java:141)
         at
com.sun.jersey.core.provider.jaxb.AbstractJAXBElementProvider.writeTo(AbstractJAXBElementProvider.java:79)
         at
com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
         at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
         at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
         at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
         at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
         at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
         at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)


This happens when the endpoint returns an XML response using a
JAXBElement. The element look like this (simplified):

<RegistryObject xsi:type="ExtrinsicObjectType"
xmlns:ns2="http://www.w3.org/1999/xlink"
xmlns="urn:oasis:names:tc:ebxml-regrep:xsd:rim:4.0"
xmlns:ns4="urn:oasis:names:tc:ebxml-regrep:xsd:rs:4.0"
xmlns:ns3="http://www.w3.org/2005/08/addressing"
xmlns:ns5="urn:oasis:names:tc:ebxml-regrep:xsd:spi:4.0"
xmlns:ns6="urn:oasis:names:tc:ebxml-regrep:xsd:query:4.0"
xmlns:ns7="urn:oasis:names:tc:ebxml-regrep:xsd:lcm:4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Slot name="urn:iso:TC211:19115:slot:geographicBoundingBox"
type="urn:ogc:def:dataType:ISO-19107:GM_Envelope">
<SlotValue xsi:type="AnyValueType">
<ns8:Polygon srsName="urn:ogc:def:crs:EPSG::4326"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns9="http://www.w3.org/2001/SMIL20/"
xmlns:ns10="http://www.w3.org/2001/SMIL20/Language"
xmlns:ns8="http://www.opengis.net/gml">
<ns8:exterior>
<ns8:LinearRing>
<ns8:pos>-120.0 25.0</ns8:pos>
<ns8:pos>-70.0 25.0</ns8:pos>
<ns8:pos>-70.0 40.0</ns8:pos>
<ns8:pos>-120.0 40.0</ns8:pos>
<ns8:pos>-120.0 25.0</ns8:pos>
</ns8:LinearRing>
</ns8:exterior>
</ns8:Polygon>
</SlotValue>
</Slot>
</RegistryObject>

The XML Schema for above is defined here
<http://docs.oasis-open.org/regrep/regrep-core/v4.0/cos01/xsd/rim.xsd>.

The <SlotValue xsi:type="AnyValueType"> element allows xs:anyType.

I have a ContextResolver as part of the jersey endpoint that has a
JAXBContext that includes JAXB bindings for the ns8:Polygon element and
the classpath contai9ns the jar containing the
net.opengis.gml.v_3_1_1.PolygonType class.

During debug it seems that my ContextResolver is never called because
com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider#getMarshaller
(line 140 in jersey 1.10)
skips the resolver because fixedMediaType is true.

I would be very grateful for any suggestions on how to debug this more
and get past this problem.

Thanks.

-- 
Regards,
Farrukh Najmi
Web:http://www.wellfleetsoftware.com