Dear all,
Some weeks ago, I was coding a servlet in an OSGi context (apache
felix/sling).
In the process, of course, I wanted to use the triplet cocoon-pipeline,
cocoon-sax, cocoon-xml, which as a result of the
design goals of Cocoon 3, can be used without further dependencies. A
wise thing !
Of course, a first rough attempt is to just embed the jars in the
bundle. This worked.
But now, I would like to take the thing an obvious step further: prepare
OSGi bundles for the three sisters.
When I checked out the trunk again, I was pleasantly surprised to notice
that ... cocoon-xml already is!
That means that I am not the only guy in the world thinking this would
be a good idea.
I prepared bundles for the other two, but ... there is a class loading
issue with cocoon-sax.
Summarising:
1. in spite of adding the xerces bundle to felix, inside the SAX2
classes a class.forName("") gives a
ClassNotFoundException.:
org.apache.cocoon.pipeline.ProcessingException: Cannot create and
prepare an XMLReader.
at
org.apache.cocoon.sax.util.XMLUtils.createXMLReader(XMLUtils.java:138)
and this is because:
Caused by: java.lang.ClassNotFoundException:
org.apache.xerces.parsers.SAXParser
at
org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:189)
2. On the other hand, inside 'my' bundle a code like:
<snip>
XMLReader reader = new SAXParser();
reader = null;
String className = System.getProperty("org.xml.sax.driver");
try {
reader =
(XMLReader)(Class.forName(className).newInstance());
}
catch (Exception e) {
System.err.println("No love...");
e.printStackTrace();
}
URL here = new
URL("http://localhost:8080/some/nice/xml/content");
URLConnection hc = here.openConnection();
InputStream in = hc.getInputStream();
ContentHandler contentHandler = new MyFavoriteContentHandler();
reader.setContentHandler(contentHandler);
InputSource input = new InputSource(in);
try {
reader.parse(input);
}
catch (Exception e) {
System.err.println("Can't parse your file");
e.printStackTrace();
}
</snip>
works.
So, clearly there is a classloader confusion.
But the question is: is this the right way to go inside OSGi? Probably
it would be better to ask the framework what parser
services it has available for us, and then use XMLParserActivator?
We could think about adding such a method to XMLUtils.
Of course I can take the embedded solution, but this is really a
third-class solution. I really think there is an interest
to transform cocoon-sax into a genuine OSGi bundle.
I do not expect problems with cocoon-pipeline, being nicely insulated
from the JAXP-loading issues.
Is there any interest in this group to dig into the matter?
Please let me know. If we can set up a discussion on this matter I am
willing to address the issues in my own time.
Cheers,
Jos