Hi there,
I really want to use Castor but I'm running into some performance
issues. I previously attempted to mitigate this by keeping a marshaler
instance around and invoking the marshal method many times. This does
not appear to work as things end up hanging (I think on the second
invocation). Consequently I searched and found the best practices
advice...
I've attempted to follow the best practices guide re. performance but
then run into a null pointer exception. Here's the stack trace:
java.lang.NullPointerException
at
org
.exolab
.castor
.xml
.util
.XMLClassDescriptorResolverImpl
.setMappingLoader(XMLClassDescriptorResolverImpl.java:143)
at
com
.classactionpl
.mule.transformer.GMLObjectToGML.<init>(GMLObjectToGML.java:44)
at
com
.classactionpl
.mule
.transformer
.GMLObjectToGMLTest
.testTransformMuleMessageString(GMLObjectToGMLTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun
.reflect
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org
.eclipse
.jdt
.internal
.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:
130)
at
org
.eclipse
.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org
.eclipse
.jdt
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
460)
at
org
.eclipse
.jdt
.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
673)
at
org
.eclipse
.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
386)
at
org
.eclipse
.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
196)
Here's my constructor code:
Mapping mapping = new Mapping();
try {
URL url =
this.getClass().getResource("/JourneyMappings.xml");
mapping.loadMapping(url);
classDescriptorResolver = ClassDescriptorResolverFactory
.createClassDescriptorResolver(BindingType.XML);
MappingUnmarshaller mappingUnmarshaller = new
MappingUnmarshaller();
MappingLoader mappingLoader =
mappingUnmarshaller.getMappingLoader(
mapping, BindingType.XML);
classDescriptorResolver.setMappingLoader(mappingLoader);
out = new StringWriter();
} catch (IOException e) {
logger.fatal(e);
} catch (MappingException e) {
logger.fatal(e);
}
...and then subsequently, for each marshaling invocation:
assert out != null;
StringBuffer buffer = out.getBuffer();
out.getBuffer().delete(0, buffer.length());
Marshaller marshaller = new Marshaller();
marshaller.setNamespaceMapping("",
"http://www.opengis.net/gml/3.2");
marshaller.setNamespaceMapping("gml", "http://www.opengis.net/gml/
3.2");
marshaller.setValidation(false);
assert classDescriptorResolver != null;
marshaller
.setResolver((XMLClassDescriptorResolver)
classDescriptorResolver);
try {
marshaller.setWriter(out);
marshaller.marshal(src);
} catch (MarshalException e) {
throw new TransformerException(this, e);
} catch (ValidationException e) {
throw new TransformerException(this, e);
} catch (IOException e) {
throw new TransformerException(this, e);
}
return out.toString();
Any indication on what is wrong with the approach?
Cheers,
-C