You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@sis.apache.org by Emmanuel Blondel <em...@gmail.com> on 2014/07/22 15:13:49 UTC

Moving from geotk to Apache-sis - problems with metadata xml marshalling

Hello,

i'm moving now from geotoolkit to Apache SIS, progressively, by using 
Geotk 4.0-M1 which uses some apache SIS modules (0.3-jdk7), and in the 
meantime, moving from jdk6 to jdk7.

What i have is a class that extends the DefaultMetadata.
I have a marshaller unit test that works fine. And the main application 
of my program works fine to marshall the metadata when i use it directly 
from Eclipse.

To use the my tool outside Eclipse, i've built a shaded Jar with Maven 
to embedd all dependencies.
But when i try to to run it the main application from command line, i 
get an error dealing with JAXB context.

I was previously using similar code with geotk, and it was working properly.

The first error i get deals with the missing annotation 
@XmlRootElement(name = "MD_Metadata") for my subclass

/Exception in thread "main" java.lang.Exception: Fail to publish 
data/metadata pair//
//        at 
org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:91)//
//        at 
org.fao.fi.gems.application.MetadataGenerator.main(MetadataGenerator.java:178)//
//Caused by: java.lang.Exception: Failed to publish metadata//
//        at 
org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:104)//
//        at 
org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:68)//
//        ... 1 more//
//Caused by: javax.xml.bind.MarshalException//
// - with linked exception://
//[com.sun.istack.internal.SAXException2: unable to marshal type 
"org.fao.fi.gems.GemsMetadata" as an//
//element because it is missing an @XmlRootElement annotation]//
//        at 
com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)//
//        at 
com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown 
Source)//
//        at 
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)//
//        at 
org.apache.sis.xml.PooledMarshaller.marshal(PooledMarshaller.java:138)//
//        at org.apache.sis.xml.XML.marshal(XML.java:374)//
//        at 
org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:84)//
//        ... 2 more//
//Caused by: com.sun.istack.internal.SAXException2: unable to marshal 
type "org.fao.fi.gems.GemsMetada//
//ta" as an element because it is missing an @XmlRootElement annotation//
//        at 
com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown 
Source)//
//        at 
com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown 
Source)//
//        at 
com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown 
Source)//
//        ... 8 more/

After adding the missing annotation, everything still works (tests, main 
app in Eclipse)
If i try to run the app with the shaded jar, i get the following error:

/Exception in thread "main" java.lang.Exception: Fail to publish 
data/metadata pair//
//        at 
org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:91)//
//        at 
org.fao.fi.gems.application.MetadataGenerator.main(MetadataGenerator.java:178)//
//Caused by: java.lang.Exception: Failed to publish metadata//
//        at 
org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:104)//
//        at 
org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:68)//
//        ... 1 more//
//Caused by: javax.xml.bind.MarshalException//
// - with linked exception://
//[com.sun.istack.internal.SAXException2: unable to marshal type 
"org.fao.fi.gems.GemsMetadata" as an//
//element because it is not known to this context.]//
//        at 
com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)//
//        at 
com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown 
Source)//
//        at 
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)//
//        at 
org.apache.sis.xml.PooledMarshaller.marshal(PooledMarshaller.java:138)//
//        at org.apache.sis.xml.XML.marshal(XML.java:374)//
//        at 
org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:84)//
//        ... 2 more//
//Caused by: com.sun.istack.internal.SAXException2: unable to marshal 
type "org.fao.fi.gems.GemsMetada//
//ta" as an element because it is not known to this context.//
//        at 
com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown 
Source)//
//        at 
com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown 
Source)//
//        at 
com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown 
Source)//
//        ... 8 more//
/
Do you have any idea what is wrong? (and also why would i need to add 
/xmlRootElement/? )
What are the differences between the geotk JAXB xml marshaller and the 
Apache SIS one?

I would be very grateful if you could advice how to solve this...

Many thanks in advance
Kind regards

-- 
*Emmanuel Blondel*
GIS Consultant
Engineer in Agronomy & Environment

Geographic Information Systems
in Agronomy - Environment - Fisheries
Email: emmanuel.blondel1@gmail.com - Emmanuel.Blondel@fao.org
View my LinkedIn profileView my LinkedIn profile 
<http://fr.linkedin.com/in/emmanuelblondel1>

Re: Moving from geotk to Apache-sis - problems with metadata xml marshalling

Posted by Emmanuel Blondel <em...@gmail.com>.
Thanks Martin,

I've tried your suggestion, but it does not work. I get back the error 
saying that i miss the XmlRootElement..
With or without annotations, my junit test works well. I'm wondering if 
it's a problem with the shaded JAR? some missing dependency? Any idea?

Emmanuel

Le 23/07/2014 00:34, Martin Desruisseaux a écrit :
> Hello Emmanuel
>
> Le 22/07/14 15:54, Adam Estrada a écrit :
>>> What i have is a class that extends the DefaultMetadata. (...snip...)
>>> The first error i get deals with the missing annotation @XmlRootElement(name = "MD_Metadata") for my subclass
>>>
>>> (...snip...)
>>> Caused by: javax.xml.bind.MarshalException
>>> com.sun.istack.internal.SAXException2: unable to marshal type "org.fao.fi.gems.GemsMetadata" as an element because it is missing an @XmlRootElement annotation
>>> (...snip...)
>>>
>>> After adding the missing annotation, everything still works (tests, main app in Eclipse)
>>> If i try to run the app with the shaded jar, i get the following error:
>>>
>>> (...snip...)
>>> Caused by: javax.xml.bind.MarshalException
>>> com.sun.istack.internal.SAXException2: unable to marshal type "org.fao.fi.gems.GemsMetadata" as an
>>> element because it is not known to this context.
> I would suggest to not put @XmlRootElement annotation in GemsMetadata,
> and instead put a @XmlTransient annotation. I'm not sure however why it
> worked before - I would have expected both the old Geotk and the new
> Apache SIS objects to behave the same way in this regards. Maybe the
> change in behaviour is related to the change in JDK version used, since
> they come with different JAXB versions.
>
> Regards,
>
>      Martin
>

Re: Moving from geotk to Apache-sis - problems with metadata xml marshalling

Posted by Martin Desruisseaux <de...@apache.org>.
Hello Emmanuel

Le 22/07/14 15:54, Adam Estrada a écrit :
>> What i have is a class that extends the DefaultMetadata. (...snip...)
>> The first error i get deals with the missing annotation @XmlRootElement(name = "MD_Metadata") for my subclass
>>
>> (...snip...)
>> Caused by: javax.xml.bind.MarshalException
>> com.sun.istack.internal.SAXException2: unable to marshal type "org.fao.fi.gems.GemsMetadata" as an element because it is missing an @XmlRootElement annotation
>> (...snip...)
>>
>> After adding the missing annotation, everything still works (tests, main app in Eclipse)
>> If i try to run the app with the shaded jar, i get the following error:
>>
>> (...snip...)
>> Caused by: javax.xml.bind.MarshalException
>> com.sun.istack.internal.SAXException2: unable to marshal type "org.fao.fi.gems.GemsMetadata" as an
>> element because it is not known to this context.

I would suggest to not put @XmlRootElement annotation in GemsMetadata,
and instead put a @XmlTransient annotation. I'm not sure however why it
worked before - I would have expected both the old Geotk and the new
Apache SIS objects to behave the same way in this regards. Maybe the
change in behaviour is related to the change in JDK version used, since
they come with different JAXB versions.

Regards,

    Martin


Re: Moving from geotk to Apache-sis - problems with metadata xml marshalling

Posted by Adam Estrada <es...@gmail.com>.
Hi Emmanuel,

It's great that you are porting your code to SIS! Thanks for the
feedback. I think that Martin and his team are best suited to answer
such a question...

Cheers,
Adam


On Tue, Jul 22, 2014 at 9:13 AM, Emmanuel Blondel
<em...@gmail.com> wrote:
> Hello,
>
> i'm moving now from geotoolkit to Apache SIS, progressively, by using Geotk
> 4.0-M1 which uses some apache SIS modules (0.3-jdk7), and in the meantime,
> moving from jdk6 to jdk7.
>
> What i have is a class that extends the DefaultMetadata.
> I have a marshaller unit test that works fine. And the main application of
> my program works fine to marshall the metadata when i use it directly from
> Eclipse.
>
> To use the my tool outside Eclipse, i've built a shaded Jar with Maven to
> embedd all dependencies.
> But when i try to to run it the main application from command line, i get an
> error dealing with JAXB context.
>
> I was previously using similar code with geotk, and it was working properly.
>
> The first error i get deals with the missing annotation @XmlRootElement(name
> = "MD_Metadata") for my subclass
>
> Exception in thread "main" java.lang.Exception: Fail to publish
> data/metadata pair
>         at org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:91)
>         at
> org.fao.fi.gems.application.MetadataGenerator.main(MetadataGenerator.java:178)
> Caused by: java.lang.Exception: Failed to publish metadata
>         at
> org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:104)
>         at org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:68)
>         ... 1 more
> Caused by: javax.xml.bind.MarshalException
>  - with linked exception:
> [com.sun.istack.internal.SAXException2: unable to marshal type
> "org.fao.fi.gems.GemsMetadata" as an
> element because it is missing an @XmlRootElement annotation]
>         at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown
> Source)
>         at
> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
>         at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown
> Source)
>         at
> org.apache.sis.xml.PooledMarshaller.marshal(PooledMarshaller.java:138)
>         at org.apache.sis.xml.XML.marshal(XML.java:374)
>         at
> org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:84)
>         ... 2 more
> Caused by: com.sun.istack.internal.SAXException2: unable to marshal type
> "org.fao.fi.gems.GemsMetada
> ta" as an element because it is missing an @XmlRootElement annotation
>         at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown
> Source)
>         at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown
> Source)
>         at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown
> Source)
>         ... 8 more
>
> After adding the missing annotation, everything still works (tests, main app
> in Eclipse)
> If i try to run the app with the shaded jar, i get the following error:
>
> Exception in thread "main" java.lang.Exception: Fail to publish
> data/metadata pair
>         at org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:91)
>         at
> org.fao.fi.gems.application.MetadataGenerator.main(MetadataGenerator.java:178)
> Caused by: java.lang.Exception: Failed to publish metadata
>         at
> org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:104)
>         at org.fao.fi.gems.publisher.Publisher.publish(Publisher.java:68)
>         ... 1 more
> Caused by: javax.xml.bind.MarshalException
>  - with linked exception:
> [com.sun.istack.internal.SAXException2: unable to marshal type
> "org.fao.fi.gems.GemsMetadata" as an
> element because it is not known to this context.]
>         at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown
> Source)
>         at
> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
>         at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown
> Source)
>         at
> org.apache.sis.xml.PooledMarshaller.marshal(PooledMarshaller.java:138)
>         at org.apache.sis.xml.XML.marshal(XML.java:374)
>         at
> org.fao.fi.gems.publisher.MetadataPublisher.publishMetadata(MetadataPublisher.java:84)
>         ... 2 more
> Caused by: com.sun.istack.internal.SAXException2: unable to marshal type
> "org.fao.fi.gems.GemsMetada
> ta" as an element because it is not known to this context.
>         at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown
> Source)
>         at
> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown
> Source)
>         at
> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown
> Source)
>         ... 8 more
>
> Do you have any idea what is wrong? (and also why would i need to add
> xmlRootElement? )
> What are the differences between the geotk JAXB xml marshaller and the
> Apache SIS one?
>
> I would be very grateful if you could advice how to solve this...
>
> Many thanks in advance
> Kind regards
>
> --
> Emmanuel Blondel
> GIS Consultant
> Engineer in Agronomy & Environment
>
> Geographic Information Systems
> in Agronomy - Environment - Fisheries
> Email: emmanuel.blondel1@gmail.com - Emmanuel.Blondel@fao.org
> View my LinkedIn profile