Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect namespace prefix assignments results in invalid documents #197

Open
charlesmoore99 opened this issue May 24, 2018 · 1 comment

Comments

@charlesmoore99
Copy link
Contributor

I'm not entirely certain that this is the correct place to post this issue. If it isn't, please direct me to the proper venue.

There are two methods that accept data of type ANY in an SOS 2.0 Insert Observation document.

Via the JaxB API they are accessed by:

  • InsertObservationType.getExtension()
  • InsertObservationType.getObservation().get(0).getOMObservation().getResult()

The namespace prefixes of these elements are being corrupted when they are marshalled.

Example (with an excessive number of namespaces):
Consider the below SOS2 InsertObservation document...

<sos:InsertObservation xmlns:addressing="http://www.w3.org/2005/08/addressing" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:icism="urn:us:gov:ic:ism:v2" xmlns:om="http://www.opengis.net/om/2.0" xmlns:om1="http://www.opengis.net/om/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:samp="http://www.opengis.net/sampling/2.0" xmlns:samp1="http://www.opengis.net/sampling/1.0" xmlns:smil="http://www.w3.org/2001/SMIL20/" xmlns:smilLang="http://www.w3.org/2001/SMIL20/Language" xmlns:sml="http://www.opengis.net/sensorML/1.0.1" xmlns:sos="http://www.opengis.net/sos/2.0" xmlns:ssf="http://www.opengis.net/samplingSpatial/2.0" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:swe101="http://www.opengis.net/swe/1.0.1" xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:wsn="http://docs.oasis-open.org/wsn/t-1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="SOS" version="2.0.0">
<swes:extension xlink:href="obs_id_1412689556053">
<sml:Security…..

… when unmarshalled and remarshalled you’ll get a document fragment that looks something that looks like this...

<ns11:InsertObservation version="2.0.0" service="SOS" xmlns:ns2="http://www.opengis.net/gml/3.2" xmlns:ns1="http://www.opengis.net/swes/2.0" xmlns:ns4="http://www.opengis.net/om/2.0" xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns6="http://www.isotc211.org/2005/gmx" xmlns:ns5="http://www.isotc211.org/2005/gco" xmlns:ns8="http://www.isotc211.org/2005/gts" xmlns:ns7="http://www.isotc211.org/2005/gmd" xmlns:ns13="http://docs.oasis-open.org/wsn/t-1" xmlns:ns9="http://www.opengis.net/sampling/2.0" xmlns:ns12="http://www.w3.org/2005/08/addressing" xmlns:ns11="http://www.opengis.net/sos/2.0" xmlns:ns10="http://www.opengis.net/samplingSpatial/2.0" xmlns:ns16="http://www.opengis.net/ows/1.1" xmlns:ns15="http://www.opengis.net/fes/2.0" xmlns:ns14="http://www.opengis.net/swe/2.0">

<ns1:extension xlink:href="obs_id_1412689556053" xmlns:swe="http://www.opengis.net/swe/2.0" xmlns:addressing="http://www.w3.org/2005/08/addressing" xmlns:samp1="http://www.opengis.net/sampling/1.0" xmlns:samp="http://www.opengis.net/sampling/2.0" xmlns:swes="http://www.opengis.net/swes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:ssf="http://www.opengis.net/samplingSpatial/2.0" xmlns:smil="http://www.w3.org/2001/SMIL20/" xmlns:swe101="http://www.opengis.net/swe/1.0.1" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:om1="http://www.opengis.net/om/1.0" xmlns:sml="http://www.opengis.net/sensorML/1.0.1" xmlns:wsn="http://docs.oasis-open.org/wsn/t-1" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:sos="http://www.opengis.net/sos/2.0" xmlns:smilLang="http://www.w3.org/2001/SMIL20/Language" xmlns:om="http://www.opengis.net/om/2.0" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:icism="urn:us:gov:ic:ism:v2" xmlns:xlink="http://www.w3.org/1999/xlink">
<sml:Security…...

The original namespace prefixes on the InsertObservation element have been renumbered. The namespace URIs are the same, but the prefixes are all different. However, the original namespace prefixes still appear on the swes:extension element.

The namespace prefix of the swes:extension element was originally ‘swes’ but is now ‘ns1’. Also The original ‘swes’ namespace prefix still appears in list of namespaces of the extension element. There are now two prefixes for the same namespace URI.

Here’s where it gets nasty:

Consider this SOS2 InsertObservation document. This one already has namespaces numbered ns1 through ns19.

<ns12:InsertObservation xmlns:ns14="http://docs.oasis-open.org/wsn/t-1" xmlns:ns5= "http://www.isotc211.org/2005/gco" xmlns:ns6= "http://www.isotc211.org/2005/gmd" xmlns:ns7= "http://www.isotc211.org/2005/gts" xmlns:ns15="http://www.opengis.net/fes/2.0" xmlns:ns18="http://www.opengis.net/gml" xmlns:ns3= "http://www.opengis.net/gml/3.2" xmlns:ns22="http://www.opengis.net/om/1.0" xmlns:ns4= "http://www.opengis.net/om/2.0" xmlns:ns16="http://www.opengis.net/ows/1.1" xmlns:ns23="http://www.opengis.net/sampling/1.0" xmlns:ns10="http://www.opengis.net/sampling/2.0" xmlns:ns11="http://www.opengis.net/samplingSpatial/2.0" xmlns:ns17="http://www.opengis.net/sensorML/1.0.1" xmlns:ns12="http://www.opengis.net/sos/2.0" xmlns:ns8= "http://www.opengis.net/swe/2.0" xmlns:ns20="http://www.opengis.net/swe/1.0.1" xmlns:ns2= "http://www.opengis.net/swes/2.0" xmlns:ns21="http://www.w3.org/2001/SMIL20/" xmlns:ns24="http://www.w3.org/2001/SMIL20/Language" xmlns:ns1= "http://www.w3.org/1999/xlink" xmlns:ns13="http://www.w3.org/2005/08/addressing" xmlns:ns19="urn:us:gov:ic:ism:v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="SOS" version="2.0.0" >
<ns2:extension ns1:href="obs_id_1412689556053">
<ns17:Security ...

When this document is unmarshalled and remarshalled the namespaces are shuffled like they were in the first case. Except this time when the swes extension element is assigned a new namespace, that prefix has already been used...

<ns4:InsertObservation version="2.0.0" service="SOS" xmlns:ns2="http://www.opengis.net/swe/2.0" xmlns:ns1="http://www.opengis.net/swes/2.0" xmlns:ns4="http://www.opengis.net/sos/2.0" xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns6="http://www.w3.org/2005/08/addressing" xmlns:ns5="http://www.opengis.net/gml/3.2" xmlns:ns8="http://www.isotc211.org/2005/gco" xmlns:ns7="http://www.opengis.net/om/2.0" xmlns:ns13="http://www.opengis.net/samplingSpatial/2.0" xmlns:ns9="http://www.isotc211.org/2005/gmx" xmlns:ns12="http://www.opengis.net/sampling/2.0" xmlns:ns11="http://www.isotc211.org/2005/gts" xmlns:ns10="http://www.isotc211.org/2005/gmd" xmlns:ns16="http://www.opengis.net/ows/1.1" xmlns:ns15="http://www.opengis.net/fes/2.0" xmlns:ns14="http://docs.oasis-open.org/wsn/t-1">.

<ns1:extension xlink:href="obs_id_1412689556053" xmlns:ns14="http://docs.oasis-open.org/wsn/t-1" xmlns:ns5= "http://www.isotc211.org/2005/gco" xmlns:ns6= "http://www.isotc211.org/2005/gmd" xmlns:ns7= "http://www.isotc211.org/2005/gts" xmlns:ns15="http://www.opengis.net/fes/2.0" xmlns:ns18="http://www.opengis.net/gml" xmlns:ns3= "http://www.opengis.net/gml/3.2" xmlns:ns22="http://www.opengis.net/om/1.0" xmlns:ns4= "http://www.opengis.net/om/2.0" xmlns:ns16="http://www.opengis.net/ows/1.1" xmlns:ns23="http://www.opengis.net/sampling/1.0" xmlns:ns10="http://www.opengis.net/sampling/2.0" xmlns:ns11="http://www.opengis.net/samplingSpatial/2.0" xmlns:ns17="http://www.opengis.net/sensorML/1.0.1" xmlns:ns12="http://www.opengis.net/sos/2.0" xmlns:ns8= "http://www.opengis.net/swe/2.0" xmlns:ns20="http://www.opengis.net/swe/1.0.1" xmlns:ns2= "http://www.opengis.net/swes/2.0" xmlns:ns21="http://www.w3.org/2001/SMIL20/" xmlns:ns24="http://www.w3.org/2001/SMIL20/Language" xmlns:ns1= "http://www.w3.org/1999/xlink" xmlns:ns13="http://www.w3.org/2005/08/addressing" xmlns:ns19="urn:us:gov:ic:ism:v2" >
<ns12:Security…..

The {http://www.opengis.net/swes/2.0}extension element originally had a namespace prefix of ‘ns2’. After being unmarshalled and remarshalled it was assigned the namespace prefix of ‘ns1’. Where we get into trouble is that the {http://www.opengis.net/swes/2.0}extension element carries with it the namespace definitions of the original InsertObservation document. In the original document the namespace prefix ‘ns1’ is assigned to {http://www.w3.org/1999/xlink}. This results in two namespace URIs assigned to the same namespace prefix. This corrupts the document and causes it to fail validation.

@charlesmoore99
Copy link
Contributor Author

charlesmoore99 commented May 31, 2018

Possible work around.

Add the following dependencies to whatever project you're using the bindings on...

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-core -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.googlecode.jaxb-namespaceprefixmapper-interfaces/JAXBNamespacePrefixMapper -->
<dependency>
    <groupId>com.googlecode.jaxb-namespaceprefixmapper-interfaces</groupId>
    <artifactId>JAXBNamespacePrefixMapper</artifactId>
    <version>2.2.4</version>
</dependency>

Then implement a com.sun.xml.bind.marshaller.NamespacePrefixMapper that covers whatever namespace URIs are causing trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant