Home
Analytics
JAXB does not work
kuli
Hi,<br />
Im using eclipse report designer with birt 2.5.2.<br />
I have a java event handler in which I try to parse a xml string by using jaxb. Creating the unmarshaller with JAXBContext.newInstance(...) is no problem. But when I try to unmarsahl the xml a unmarshal exception is thrown.<br />
I tested the same code in a single java application. this works perfectly.<br />
<br />
here the java code:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>String xml = "..."; //my xml string
Unmarshaller unmarshaller = JAXBContext.newInstance(MyClass.class).createUnmarshaller();
MyClass mc = (MyClass) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
System.out.println(mc.getProperty());</pre>
<br />
here the exception:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>javax.xml.bind.UnmarshalException: unexpected element (uri: ...</pre>
<br />
Why does the same code work in a single java application but not in a birt event handler? can somebody help me out?<br />
<br />
thx<br />
thomas
Find more posts tagged with
Comments
kuli
can someone help me out?
pJune
Did you get the answer? I have kind of the same problem.
CBR
Can you provide the source code? My assumption is that JAXB can't find corresponding java classes because of classloading issues.
It's always a good idea to try to set the context classloader or to provide JAXB with a list of java classes.
johnw
This is due to a classloading issue in OSGi. There were a group of folks who built a JAXB implementation that will work as a plugin for OSGi/Eclipse. I had written about it several years ago:
http://digiassn.blogspot.com/2008/09/osgi-jaxb-with-osgi.html
John
CBR
A quick and dirty workaround might be to set the context classloader for JAXB accordingly. This only works if your java class files are located within the same "plugin" as the java class that uses JAXB.
pJune
Hi, can you post an example of the context ClassLoader?
This is my source code for JAXB:
JAXBContext context = JAXBContext.newInstance("org.cdisc.ns.odm.v1_3");
Unmarshaller u = context.createUnmarshaller() ;
odm = (org.cdisc.ns.odm.v1_3.ODM) u.unmarshal(odmFile);
I have a birt report with an scripted dataset that retrieves information from a java object. This java class has the code below. When I run the java class, it works well. However, when I run my report, I get the following error:
1 counts of IllegalAnnotationExceptions
1 counts of IllegalAnnotationExceptionscom.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:448)
com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:297)
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:117)
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:188)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
javax.xml.bind.ContextFinder.find(ContextFinder.java:277)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
com.infotechsoft.ad_edc.dataset.adapter.odm.OdmAdapter.openODM(OdmAdapter.java:743)
com.infotechsoft.ad_edc.dataset.adapter.odm.OdmAdapter.<init>(OdmAdapter.java:42)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
org.mozilla.javascript.MemberBox.newInstance(MemberBox.java:194)
org.mozilla.javascript.NativeJavaClass.constructSpecific(NativeJavaClass.java:281)
org.mozilla.javascript.NativeJavaClass.construct(NativeJavaClass.java:200)
org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2327)
org.mozilla.javascript.gen.c106._c1(:5)
org.mozilla.javascript.gen.c106.call()
org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
org.mozilla.javascript.gen.c6._c0(:0)
org.mozilla.javascript.gen.c6.call()
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
org.mozilla.javascript.gen.c6.call()
org.mozilla.javascript.gen.c6.exec()
org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateRawScript(JavascriptEvalUtil.java:95)
org.eclipse.birt.core.script.JavascriptEvalUtil.evaluateScript(JavascriptEvalUtil.java:134)
org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJSAsExpr(ScriptEvalUtil.java:1001)
org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:76)
org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:90)
org.eclipse.birt.report.engine.script.internal.DataSetScriptExecutor.handleJS(DataSetScriptExecutor.java:219)
org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleOpen(ScriptDataSetScriptExecutor.java:88)
org.eclipse.birt.data.engine.impl.ScriptDataSetRuntime.open(ScriptDataSetRuntime.java:80)
org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor$CustomDataSet.open(PreparedScriptDSQuery.java:247)
org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor.executeOdiQuery(PreparedScriptDSQuery.java:223)
org.eclipse.birt.data.engine.impl.QueryExecutor.execute(QueryExecutor.java:1094)
org.eclipse.birt.data.engine.impl.ServiceForQueryResults.executeQuery(ServiceForQueryResults.java:232)
org.eclipse.birt.data.engine.impl.QueryResults.getResultIterator(QueryResults.java:172)
org.eclipse.birt.report.engine.data.dte.QueryResultSet.<init>(QueryResultSet.java:98)
org.eclipse.birt.report.engine.data.dte.DteDataEngine.doExecuteQuery(DteDataEngine.java:168)
org.eclipse.birt.report.engine.data.dte.AbstractDataEngine.execute(AbstractDataEngine.java:265)
org.eclipse.birt.report.engine.executor.ExecutionContext.executeQuery(ExecutionContext.java:1876)
org.eclipse.birt.report.engine.executor.QueryItemExecutor.executeQuery(QueryItemExecutor.java:80)
org.eclipse.birt.report.engine.executor.GridItemExecutor.execute(GridItemExecutor.java:65)
org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)
org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)
org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)
org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)
org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)
org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:99)
org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:180)
org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:920)
org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:973)
org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(BirtGetPageAllActionHandler.java:131)
org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)
org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)
org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(BirtDocumentProcessor.java:183)
sun.reflect.GeneratedMethodAccessor116.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)
org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)
sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:126)
org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
org.mortbay.jetty.Server.handle(Server.java:326)
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:939)
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Thanks in advanced
CBR
Hi,
can you try to change this line:
JAXBContext context = JAXBContext.newInstance("org.cdisc.ns.odm.v1_3");
TO
JAXBContext.newInstance( "org.cdisc.ns.odm.v1_3", this.getClass().getClassLoader() );
depending on internals it might also be necessary to change the newInstance call to include a List of class objects for the JAXBContext. The disadvantage is that you have to provide all class objects that are required for unmarshalling.
JAXBContext context = JAXBContext.newInstance(classA.class, classB.class, ...);
Let me know if this works for you. If you provide me with the source code i can have a deeper look into this.
Shivani_T
Hello All,<br />
<br />
Can you please help me with JAXB, I am new to JAXB? I am using BIRT reports and for the dynamic Datasource creation I use BIRT APIs in Ruby on rails project. But now for the performance reasons I want to use JAXB, so that the XML processing of the report design become fast. but I do not know how should I go about it.<br />
Did anyone of you have implemented same functionality or have experience in JAXB with BIRT then please help me.<br />
<br />
Thanks in advance,<br />
Shivani<br />
C<br />
<blockquote class='ipsBlockquote' data-author="'CBR'" data-cid="74307" data-time="1299230215" data-date="04 March 2011 - 02:16 AM"><p>
Hi,<br />
<br />
can you try to change this line:<br />
<br />
JAXBContext context = JAXBContext.newInstance("org.cdisc.ns.odm.v1_3");<br />
<br />
TO<br />
JAXBContext.newInstance( "org.cdisc.ns.odm.v1_3", this.getClass().getClassLoader() );<br />
<br />
depending on internals it might also be necessary to change the newInstance call to include a List of class objects for the JAXBContext. The disadvantage is that you have to provide all class objects that are required for unmarshalling. <br />
<br />
<br />
JAXBContext context = JAXBContext.newInstance(classA.class, classB.class, ...);<br />
<br />
Let me know if this works for you. If you provide me with the source code i can have a deeper look into this.<br /></p></blockquote>