Jump to content
We've recently updated our Privacy Statement, available here ×

No query executer factory registered for the xpath2 language


kashkoa

Recommended Posts

I have been round the internet searching for answers to the problem I am having with this

Background:

I need to write code to produce a report from an XML datasource using a .jrxml template provided by someone else.

The .rxml template uses the query language xpath2. I still get the problem if i manually cange xpath2 to xpath.

The API docs say

For each query language, a query executer factory must be created and registered as a JR property and

QUERY_EXECUTER_FACTORY_PREFIX

static final java.lang.String QUERY_EXECUTER_FACTORY_PREFIX[/code]

Prefix for query executer factory properties.

To obtain query executer factories, a property having the query language appended to this prefix is used to get the query executor factory name.

But the docs do not give an example of the format to use. This leaves me looking for a needle in a haystack.

I got this from an online post which might have helped but turned out useless in a frustrating way

  1. No indication where in the documentation this occurs

  2. No indication of the values to put in for each string in "<......>"

Again I need the crystal ball that is in the pawnshop right now

Even PHP was better documented way back in 1999

I have spent three days looking for examples of what to put in the java code I tried putting the lines below after creating the report with

JasperReport report = JasperCompileManager.compileReport(template);[/code]

(template is the name of the .jrxml file. We decided not to support .jasper files)

overall I am disappointed because this is something no one trying to deal with JR should have to face.

JasperReport jasperReport = <...>jasperReport.setProperty( JRQueryExecuterFactory.QUERY_EXECUTER_FACTORY_PREFIX + "<query language>", "<value>")[/code]

 

Link to comment
Share on other sites

  • Replies 13
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

It seems the problem is  in this line

        JasperReport report = JasperCompileManager.compileReport(template);

If the template is a .jrxml file it tells me there is no query executer factory registered for xpath or for xpath2

And if the template is a .jasper file I get a sax parse exception.

This sounds to me as if there is a bug in the code for handling xml and xpath.  There seems no way to register a  factory.

I guess  I will have againt o advise me client that JR is not a good path to take.

And once again they are unlikely to listen.

 


 

 

 

Link to comment
Share on other sites

Right. It looks like a bug caused by bad programming practice.

 

The exception is printed to the console in Eclipse, and presumably logged somewhere. but not propagated upwards. This means the unit tests, if they exist, will not fail because no problem or fail code is propagated to the test.

 

I have tried various ways to get round this, including setting properties files. The package does not meet standards I would have set for myself

 

Link to comment
Share on other sites

Hi,

 

Please take a moment and read about JR Extension support in the JasperReports Ultimate Guide which is available for free here:

http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf

and is also shipped with the source code package in latest JR releases.

 

Query executers can be added very easy simply by adding a JAR to classpath. The fact that your reports have a query language called xpath2 seems to indicate they were created with iReport, which is an optional query executer for Web Services that is registered to this xpath2 custom defined query language.

If you indeed used iReport, than the only thing you should have done is to take the JAR containing this custom query executer from iReport and add it to the classpath of your application, without making any further configurations. The JAR is called jasperreports-extensions.jar.

 

The documentation you cited is for those who want to implement custom query executers on their own. But if you are just using the one that comes from iReport, or any other custom query executer provider, you just need to take the JAR from them and that's all.

If the xpath2 query executer is not from iReport, then those who provided it to you should have given you a JAR containing that custom query executer and you should have added it to your application classpath.

You had all these exceptions because your reports made use of a pluggable custom query executer that you did not add to your application classpath. It's as easy as that.

 

Your decision to compile JRXML reports at runtime comes with the drawback of your reports running a bit slower, just because they are compiled at runtime, without any particular reason. But if you want them to run slower, it is up to you.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Thanks for the  quick reply.

Here is the  stack trace as printed  to the console. I have highlighted the lines I think are most significant.

This is probably a configuration problem. 

 

 


16-Mar-2012 11:41:36 net.sf.jasperreports.engine.component.ComponentsEnvironment findComponentBundles
WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
16-Mar-2012 11:41:36 org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
    at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:216)
    at org.apache.commons.digester.Rule.end(Rule.java:230)
    at org.apache.commons.digester.Digester.endElement(Digester.java:1130)
    at net.sf.jasperreports.engine.xml.JRXmlDigester.endElement(JRXmlDigester.java:186)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:243)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:230)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:143)
    at com.curema.test.xml.creation.TestCreatePDFwithdatasource.simple(TestCreatePDFwithdatasource.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
    at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
    at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    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)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the 'xpath2' language.
    at net.sf.jasperreports.engine.util.JRQueryExecuterUtils.getQueryExecuterFactory(JRQueryExecuterUtils.java:64)
    at net.sf.jasperreports.engine.design.JRDesignDataset.queryLanguageChanged(JRDesignDataset.java:1122)
    at net.sf.jasperreports.engine.design.JRDesignDataset.setQuery(JRDesignDataset.java:600)
    at net.sf.jasperreports.engine.design.JasperDesign.setQuery(JasperDesign.java:789)
    ... 46 more
net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the 'xpath2' language.
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:230)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:218)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:143)
    at com.curema.test.xml.creation.TestCreatePDFwithdatasource.simple(TestCreatePDFwithdatasource.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
    at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
    at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    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)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the 'xpath2' language.
    at org.apache.commons.digester.Digester.createSAXException(Digester.java:2919)
    at org.apache.commons.digester.Digester.createSAXException(Digester.java:2945)
    at org.apache.commons.digester.Digester.endElement(Digester.java:1133)
    at net.sf.jasperreports.engine.xml.JRXmlDigester.endElement(JRXmlDigester.java:186)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:243)
    ... 26 more
 

 

 

Link to comment
Share on other sites

What we can see here is a unit test that you have in your code, called com.curema.test.xml.creation.TestCreatePDFwithdatasource, in which you call the JasperCompilerManager to compile a report.

JR Library raises an unchecked exception in the form of a JRRuntimeException, when no query executer is registered with the specified query language in the report. The condition is serios and prevents JR from continuing because it is similar to missing a JAR in the classpath or something.

In JR, we raise an exception. JR is open source. Can you point us to the place in the JR source code where we spit exceptions on the stack trace?

Since when raising unchecked exception is considered bad practice and what exactly are these standards you have set for yourself that we do not meet? We'd like to learn.

If you run your unit tests from Eclipse, where else would you want exceptions to be logged if not in the Eclipse console view? In your project that contains these unit tests, do you use any of the available logging libraries? If you do, why don't you configure them so their output be sent where you expect it to be sent?

Thanks,
Teodor

 

Link to comment
Share on other sites

I worked on a project where testers ( yes, testers, not developers, it was a chaotic project) were passing  code that  throw unchecked exceptions  simply because the unit test bars went green.   So I set a rule for myself to  write code that would not cause a test to look as if it has passed. 

I set myself rules on unit testing  and code clarity. These are based on hard experience.  While it is not my job to deal with poor management, I suffered the results several times on more than one  contract.

I have seen a lot of bad code, and the code here is not the worst I have seen (6/10), but that is a couple of stories not to tell here,   and as a result  I try to develop for testability and maintainability first and performance later.  This slows me down a  bit but clients normally  find they save on testing time. (Occasionally I have been told to produce code fast and not worry about quality). 

Before this gets acrimonious I have had more aggravation from working with JR  and IRthan any open source project I remember using.  Normally I fix problems like this in a day, two at most. 

I will look at the documentation you mentioned and hope this makes liife easier.  Luckily my client is relaxed about pdf creation

The prolem is exactly what you say.  No query executer is registered.

Link to comment
Share on other sites

I do not ignore any exceptions at the unit test level. In fact I deliberately did what people say you should not and caught any exception. Since the exception was handled at a lower level than the test and no exception was passed upwards the unit test could not register it. I saw this on a project last year and no one was able to get the test to register the exception. It is possible there is a tweak to the junit configuration that will do this but I at least have not found one.

 

Link to comment
Share on other sites

Apologies Teodor. I looked at the unit test and found why the test was not failing and corrected it. It now fails as expected. I also put the extensions jar in the class path but still get the failure. I am 99% certain I am missing some minor point that will be obvious once pointed out. I think I got too wrapped up in trying to fix the main problem to think straight about anything else.

 

Link to comment
Share on other sites

What you missed is something I missed too and only became apparent when testing the thing myself.

 

The extensions JAR present in iReport is not packaged as a true JR extension because it does not contain a jasperreports_extension.properties file in its root package.

So although it brings to the classpath the required classes, it does not register them with JR.

 

The solution was to register the xpath2 language with a line in the jasperreports.properties file that sits in the root package of your application classpath. If you don't have one, you should create it and add this line to it:

net.sf.jasperreports.query.executer.factory.xpath2=com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory

 

This was also explained on the tracker.

Sorry for not testing the extension JAR before indicating it, but I'm not an expert in iReport.

 

You also mentioned some documentation spelling errors that made you waste time. If you could point them to us, we would be happy to fix them.

After all, that's all open source is about.

 

Thanks,
Teodor

 

Link to comment
Share on other sites

  • 3 weeks later...

I was stuck on this issue for a week or so.
Where should I have originally looked for documentation on the matter?
Is all iReport docs relevant for JasperStudio?
Thanks

 

Edit: Sorry, forgot this is not the JasperStudio forum, feel free to ignore.



Post Edited by roded at 04/03/2012 16:21
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...