Have you looked at the Jersey json-from-jaxb sample? I believe it uses
a JAXBContext to provide both XML and JSON options, see the bottom of
the file here:
http://java.net/projects/jersey/sources/svn/content/trunk/jersey/samples/json-from-jaxb/README.html?rev=5653
It might point out something that can fix your problem.
Regards,
Glen
On 02/15/2012 03:26 PM, Farrukh Najmi wrote:
>
> Hi Guys,
>
> I am still stuck on the problem posted earlier in this thread under a
> different subject.
>
> In order for me to get this resolved I am thinking I need a clearer
> understanding of how jersey creates its JAXBContext that it uses to
> marshal and unmarshal JAXB objects.
> In particular I am curious how I can give the jersey runtime a
> JAXBContext that I have alredayt created elsewhere.
>
> I would be grateful if someone could provide some guidance. Thanks.
>
> On 02/10/2012 02:59 PM, Farrukh Najmi wrote:
>> Hi Guys,
>>
>> Upon further investigation here are some findings on my problem....
>>
>> * First the class in question net.opengis.gml.v_3_1_1.PolygonType
>> is definitely in a jar in my classpath for the web app
>> * The "JAXBException: <Class> is not known to this context" problem
>> seems to be experienced due to ClassLoader issues in many cases:
>> o https://issues.apache.org/jira/browse/GERONIMO-3793
>> o http://mail-archives.apache.org/mod_mbox/cxf-users/200809.mbox/%3C1220547389.13894.37.camel@ubuntu%3E
>> o http://healthvaultjavalib.codeplex.com/workitem/10842
>> * I do not experience this problem when I use the SOAP endpoint to
>> the same webapp but only when I use the jersey REST endpoint
>> * In my own code I am not doing any ClassLoader magic that I know off
>> * I am using spring-framework in case it is relevant
>>
>> Any idea what else I can try to get to the bottom of this? Is this
>> issue more appropriate for the users_at_jaxb list?
>>
>>
>> On 02/09/2012 12:53 PM, Farrukh Najmi wrote:
>>>
>>> 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"
>>> <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"
>>> <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"
>>> <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/"
>>> <http://schemas.xmlsoap.org/soap/envelope/>
>>> xmlns:ns9="http://www.w3.org/2001/SMIL20/"
>>> <http://www.w3.org/2001/SMIL20/>
>>> xmlns:ns10="http://www.w3.org/2001/SMIL20/Language"
>>> <http://www.w3.org/2001/SMIL20/Language>
>>> xmlns:ns8="http://www.opengis.net/gml" <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
>
--
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza