[rules-users] Drools and Jersey

mike mikemps at gmail.com
Wed Mar 14 13:25:59 EDT 2012


Wolfgang,

I am able to find the place where the NPE happens. It is
in com.sun.jersey.spi.service.ServiceFinder on the method

    private static Enumeration<URL> getResources(ClassLoader loader, String
name) throws IOException {
        if (loader == null) {
            return getResources(name);
        } else {
            final Enumeration<URL> resources = loader.getResources(name);
            if (resources.hasMoreElements()) {
                return resources;
            } else {
                return getResources(name);
            }
        }
    }

In there, the call to loader.getResources(name) returns null
causing resources.hasMoreElements() to throw the NPE. That is a bug in
Jersey. But the same code works just fine without MVEL. So MVEL is doing
something that is causing Jersey not to find some classes.

Mauricio,

The test is simple, try running this drl

import com.sun.jersey.api.client.Client;

dialect  "mvel"

rule "create Rest Client"
    then new Client();
end

OTOH this works just fine

import com.sun.jersey.api.client.Client;

rule "create Rest Client"
    then new Client();
end

Thank you very much for your help
Cheers
Mike


2012/3/14 Mauricio Salatino <salaboy at gmail.com>

> If you create an isolated test you can also create a new Jira issue, so
> it's easier for every one to reproduce, test and fix the problem.
> Cheers
>
>
> 2012/3/14 mike <mikemps at gmail.com>
>
>> Wolfgang,
>>
>> I am using
>>
>> <dependency>
>>  <groupId>org.drools</groupId>
>>  <artifactId>drools-core</artifactId>
>> <version>5.3.1.Final</version>
>>  <type>jar</type>
>> </dependency>
>>
>> Mauricio:
>>
>> It is something related to loading classes inside Jersey that brakes if I
>> am using mvel. I use mvel always, because java syntax hurts me.
>>
>> Drools Team:
>>
>> I think the easier way would be to try this scenario yourself. This is a
>> pom for Jersey.
>>
>> <dependency>
>> <groupId>com.sun.jersey</groupId>
>>  <artifactId>jersey-client</artifactId>
>> <version>1.12</version>
>>  </dependency>
>>
>> Thank you very much
>> Cheers
>> Mike
>>
>> 2012/3/14 Mauricio Salatino <salaboy at gmail.com>
>>
>>> Sure.. we are interested in finding out what is happening. So, you find
>>> that when you are using mvel something inside Jersey fails?
>>> Did you find what exactly is happening inside Jersey? Probably it's
>>> something related with the class loaders, but I never seen an error like
>>> that when you specify the mvel dialect.
>>> By the way, what exactly are you trying to do with mvel? did you try
>>> using the mvel syntax without explicitly specifying the dialect?
>>>
>>> Cheers
>>>
>>>
>>>
>>> 2012/3/14 mike <mikemps at gmail.com>
>>>
>>>> Wait ... I haven't solved the problem ... I mean, as of now I cannot
>>>> use mvel if I want to use Jersey ... and I don't think it's Jersey's fault
>>>> because it works in any condition except when using mvel. I thought that
>>>> the Drools team follows this list and might be interested in that bug.
>>>>
>>>> Thank you very much
>>>> Mike
>>>>
>>>> 2012/3/14 Mauricio Salatino <salaboy at gmail.com>
>>>>
>>>>> Cool that you find that :)
>>>>> Cheers
>>>>>
>>>>>
>>>>> 2012/3/14 mike <mikemps at gmail.com>
>>>>>
>>>>>> Hi Mauricio,
>>>>>>
>>>>>> I spent like 2 days debugging, before realizing that mvel was the
>>>>>> culprit. The error is a Null Exception when resolving some service inside
>>>>>> Jersey. I have to check my browser history at home for more details but the
>>>>>> exception was happening inside Jersey.
>>>>>>
>>>>>> Please notice I reduced the code to the minimum. I had 'real' code
>>>>>> doing more reasonable things with new Client. Client c = new Client() fails
>>>>>> too.
>>>>>>
>>>>>> Thank you very much
>>>>>>  Mike
>>>>>>
>>>>>>
>>>>>> 2012/3/14 Mauricio Salatino <salaboy at gmail.com>
>>>>>>
>>>>>>> Hi Mike, I've never tried that before (a rule without the when
>>>>>>> part..) is good to know that it works :)
>>>>>>> Humm that's sounds weird.. why the dialect is affecting your Client
>>>>>>> creation.
>>>>>>> It could be that there is something wrong with the expression
>>>>>>> evaluation.
>>>>>>> It looks like MVEL cannot compile the new Client(); expression -> at
>>>>>>> java.lang.String.<init>(Unknown Source)
>>>>>>> Did you try with something like:
>>>>>>> then \n
>>>>>>> Client c = new Client();
>>>>>>>
>>>>>>> I'm just guessing here, because it looks strange
>>>>>>>
>>>>>>>
>>>>>>> 2012/3/14 mike <mikemps at gmail.com>
>>>>>>>
>>>>>>>> Hi Mauricio,
>>>>>>>>
>>>>>>>> Thank you for the speedy reply. Ia m making rest call to web
>>>>>>>> services using jersey. I simplified the rule to the max. The 'when' is not
>>>>>>>> really needed. I get the exception on the call to "new Client()". Please
>>>>>>>> keep in mind it works without dialect "mvel".
>>>>>>>>
>>>>>>>> Thank you very much
>>>>>>>> Mike
>>>>>>>>
>>>>>>>> Here's the stack trace .............
>>>>>>>> java.lang.StringIndexOutOfBoundsException: String index out of
>>>>>>>> range: -1
>>>>>>>> at java.lang.String.<init>(Unknown Source)
>>>>>>>>  at
>>>>>>>> org.mvel2.CompileException.showCodeNearError(CompileException.java:149)
>>>>>>>> at
>>>>>>>> org.mvel2.CompileException.generateErrorMessage(CompileException.java:219)
>>>>>>>>  at org.mvel2.CompileException.toString(CompileException.java:62)
>>>>>>>> at java.lang.Throwable.<init>(Throwable.java:242)
>>>>>>>>  at java.lang.Exception.<init>(Unknown Source)
>>>>>>>> at java.lang.RuntimeException.<init>(Unknown Source)
>>>>>>>>  at
>>>>>>>> org.drools.runtime.rule.ConsequenceException.<init>(ConsequenceException.java:31)
>>>>>>>> at
>>>>>>>> org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
>>>>>>>>  at
>>>>>>>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
>>>>>>>> at
>>>>>>>> org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
>>>>>>>>  at
>>>>>>>> org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
>>>>>>>> at
>>>>>>>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:709)
>>>>>>>>  at
>>>>>>>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:673)
>>>>>>>> at
>>>>>>>> org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
>>>>>>>>  at
>>>>>>>> com.ultimatesoftware.engine.tests.Wip.drools_new_client(Wip.java:32)
>>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>>>>>  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>>>>>>  at java.lang.reflect.Method.invoke(Unknown Source)
>>>>>>>> at
>>>>>>>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>>>>>>>  at
>>>>>>>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>>>>>>> at
>>>>>>>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>>>>>>>  at
>>>>>>>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>>>>>>> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>>>>>>>>  at
>>>>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
>>>>>>>> at
>>>>>>>> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
>>>>>>>>  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>>>>>>>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>>>>>>>>  at
>>>>>>>> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>>>>>>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>>>>>>>>  at
>>>>>>>> org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>>>>>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
>>>>>>>>  at
>>>>>>>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>>>>>>>> at
>>>>>>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>>>>>>>  at
>>>>>>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>>>>>>>> at
>>>>>>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>>>>>>>>  at
>>>>>>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>>>>>>>> at
>>>>>>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> 2012/3/14 Mauricio Salatino <salaboy at gmail.com>
>>>>>>>>
>>>>>>>>> what are you trying to do?
>>>>>>>>> what's the error?
>>>>>>>>>
>>>>>>>>> the rule should look like
>>>>>>>>>
>>>>>>>>> rule "create Rest Client"
>>>>>>>>>     when
>>>>>>>>>     then new Client();
>>>>>>>>> end
>>>>>>>>>
>>>>>>>>> 2012/3/14 mike <mikemps at gmail.com>
>>>>>>>>>
>>>>>>>>>>  Hi there,
>>>>>>>>>>
>>>>>>>>>> I am trying to make rest calls from Drools. For that I am using
>>>>>>>>>> Jersey http://jersey.java.net/. I cannot no get it to work if I
>>>>>>>>>> use mvel, otherwise it works fine.
>>>>>>>>>>
>>>>>>>>>> Here is a sample rule:
>>>>>>>>>> ----------------------------------------------------------
>>>>>>>>>> import com.sun.jersey.api.client.Client;
>>>>>>>>>>
>>>>>>>>>> dialect  "mvel"
>>>>>>>>>>
>>>>>>>>>> rule "create Rest Client"
>>>>>>>>>>     then new Client();
>>>>>>>>>> end
>>>>>>>>>> ----------------------------------------------------------
>>>>>>>>>>
>>>>>>>>>> I would love to be able to use mvel since it curves java syntax
>>>>>>>>>> :)
>>>>>>>>>>
>>>>>>>>>> Thank you
>>>>>>>>>> Mike
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> rules-users mailing list
>>>>>>>>>> rules-users at lists.jboss.org
>>>>>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>  - MyJourney @ http://salaboy.wordpress.com
>>>>>>>>>  - Co-Founder @ http://www.jugargentina.org
>>>>>>>>>  - Co-Founder @ http://www.jbug.com.ar
>>>>>>>>>
>>>>>>>>>  - Salatino "Salaboy" Mauricio -
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> rules-users mailing list
>>>>>>>>> rules-users at lists.jboss.org
>>>>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> rules-users mailing list
>>>>>>>> rules-users at lists.jboss.org
>>>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>  - MyJourney @ http://salaboy.wordpress.com
>>>>>>>  - Co-Founder @ http://www.jugargentina.org
>>>>>>>  - Co-Founder @ http://www.jbug.com.ar
>>>>>>>
>>>>>>>  - Salatino "Salaboy" Mauricio -
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> rules-users mailing list
>>>>>>> rules-users at lists.jboss.org
>>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> rules-users mailing list
>>>>>> rules-users at lists.jboss.org
>>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>  - MyJourney @ http://salaboy.wordpress.com
>>>>>  - Co-Founder @ http://www.jugargentina.org
>>>>>  - Co-Founder @ http://www.jbug.com.ar
>>>>>
>>>>>  - Salatino "Salaboy" Mauricio -
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> rules-users mailing list
>>>>> rules-users at lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> rules-users mailing list
>>>> rules-users at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>>
>>>>
>>>
>>>
>>> --
>>>  - MyJourney @ http://salaboy.wordpress.com
>>>  - Co-Founder @ http://www.jugargentina.org
>>>  - Co-Founder @ http://www.jbug.com.ar
>>>
>>>  - Salatino "Salaboy" Mauricio -
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
>  - MyJourney @ http://salaboy.wordpress.com
>  - Co-Founder @ http://www.jugargentina.org
>  - Co-Founder @ http://www.jbug.com.ar
>
>  - Salatino "Salaboy" Mauricio -
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120314/b2d70d85/attachment.html 


More information about the rules-users mailing list