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

When following instructions for multi-inherited catalogs keep getting unknown host exception from xjc #12

Closed
jahutton opened this issue Oct 24, 2014 · 11 comments

Comments

@jahutton
Copy link

Created an oasis xml catalog with the rewriteSystem element replacing a bogus url with the maven: uri. Sample stack trace is below. Using jaxb-impl/api 2.2.7 and 0.11.0 of your plugin.

org.xml.sax.SAXParseException; systemId: file:/I:/workspace/infrastructure_maven/datatypes/src/main/resources/datatype.xsd; lineNumber: 7; columnNumber: 104; java.net.UnknownHostException: ssg.fusa.com
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:349)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.importSchema(NGCCRuntimeEx.java:258)
at com.sun.xml.xsom.impl.parser.state.importDecl.action0(importDecl.java:85)
at com.sun.xml.xsom.impl.parser.state.importDecl.leaveElement(importDecl.java:183)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.endElement(NGCCRuntime.java:314)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.xjc.util.SubtreeCutter.endElement(SubtreeCutter.java:112)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.endElement(CustomizationContextChecker.java:199)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:570)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:355)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2770)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:94)
at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:497)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:269)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:347)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:128)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:168)
at com.sun.tools.xjc.ModelLoader.createXSOMSpeculative(ModelLoader.java:514)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:369)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.loadModel(XJC22Mojo.java:50)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:40)
at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:28)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:326)
at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:168)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
Caused by: java.net.UnknownHostException: ssg.fusa.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:637)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:357)
at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:94)
at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:497)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:269)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:347)
... 62 more

@jahutton
Copy link
Author

As a note, the codegen succeeds, however the errors look like they should be fatal.

@highsource
Copy link
Owner

Please provide the sample project as well as mvn -X -e clean install log.

@highsource
Copy link
Owner

What is a "multi-inherited catalog" by the way?

@jahutton
Copy link
Author

ie; B depends on A, and C depends on both B and A.

@highsource
Copy link
Owner

Ok, this should work.
Please send me the log first. -X should turn on debugging of the catalog. But I'll probably need the project anyway.
If not discloseable via valikov - at - gmx.net

@highsource
Copy link
Owner

Solved?

@jahutton
Copy link
Author

Not sure if I modified something in the catalog file that corrected the parsing. Sorry for the bother.

@highsource
Copy link
Owner

Well. 👍
Glad you solved it.
General recommendation: do mvn -X and study the log. Resolver write there what he does. You can often spot problems this way.

@jahutton
Copy link
Author

Any thoughts if this rewrite can be used on schemas within the project itself? As in have two schema A.xsd and B.xsd in src/main/resources, B imports A like:

<xs:import namespace="urn:A" schemaLocation="http://somehost.com/A.xsd"/>

Getting duplicate element errors in a large project (~30 schemas) and there may be circular dependencies and resolved uri's may not be matching. Just didn't know if your maven resolver would resolve resources within the current maven project.

@highsource
Copy link
Owner

You can rewrite to local files:

REWRITE_SYSTEM "http://schemas.opengis.net" "ogc"

But not to via maven:... into the current project. You need a pre-built artifact (an existing JAR).

Resolving maven:... in the current project isn't even cleanly implementable. Where should it be resolved then? Into src/main/resources? There may be many resource roots. Check all of them? But resources may be generated in later phases.

So, in essense, you need an artiface.

As for your case, check this project:

https://github.com/highsource/ogc-schemas

This is exactly the same case as you have. Many schemas, interconnected with circular refs etc. Some URLs are bogus. References via absolute and relative URLs.

My recommendations:

  • First of all, create a separate schemas JAR artifact which would just prepare and package the schemas, nothing more. Sometimes you also need to do some minor patches to schemas because not all of the constructs are supported by JAXB/XJC (almoust all, but not all). You can do it with a patch plugin in this schemas module. Example: https://github.com/highsource/ogc-schemas/tree/master/schemas
  • If you compile schema from several sources/authorities/schema repositories, consider creating one root directory per authority. Example: ogc for http://schemas.opengis.net and oasis for http://docs.oasis-open.org. You'll need one rewriting rule per authority, see this catalog file for example.
  • Write catalog files which rewrite http://somehost.com to your maven:com.somehost:schemas::!/somehost (assumes somehost is the target root directory). Include this catalog in your schemas artifact.
  • When compiling your schemas, compile absolute urls like http://somehost.com/A.xsd and use the catalog from your schemas artifact. This will rewrite http://somehost.com/A.xsd to maven:com.somehost:schemas::!/somehost/A.xsd which would be then resolve to the appropriate resourcesin your schemas....jar.
  • Since you start your compilation from the absolute URL, all schema URLs will finally be calculated as absolute. So logically your schemas will only get absolute system IDs. This should eliminate "duplicates".
  • It still can be that your schemas use wrong absolute URLs (i.e. they have errors). You can resolve this schema to the correct resources using rewriting in the catalog. But you will still get errors on duplicates. This is because there is a bug/an issue in JAXB/XJC: JAXB-1046. At the moment, JAXB/XJC only considers "original" system IDs when looking for duplicates, not the "resolved" ID. Thus, even if you resolve two schemas with different system IDs to the same local resource, for JAXB/XJC they're still duplicates. As long as this is not resolved, I'd just recommend patching the schemas in the schemas module.

@highsource
Copy link
Owner

I've started a Best Practices guide on the subject:

https://github.com/highsource/maven-jaxb2-plugin/wiki/Compiling-Large-Schema-Sets

phax referenced this issue in phax/maven-jaxb2-plugin Sep 1, 2022
…us.plexus-plexus-utils-3.3.0

Bump plexus-utils from 1.5.15 to 3.3.0
laurentschoelens pushed a commit to laurentschoelens/jaxb-tools that referenced this issue May 12, 2023
Add scaffolding for HashCode generators.
laurentschoelens pushed a commit to laurentschoelens/jaxb-tools that referenced this issue May 12, 2023
laurentschoelens pushed a commit to laurentschoelens/jaxb-tools that referenced this issue Aug 22, 2023
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

2 participants