[rules-users] Weird NullPointerException when deploying Drools rules on FUSE OSGI 4 ESB

Marcel Casado marcel at ucar.edu
Sun Aug 23 15:33:11 EDT 2009


Hi,

I'm trying to deploy a simple decision service using Drools on a OSGI
environment (FUSE ESB 4.). The rule right now is really simple is like a
look up service. The rules run fine on my tests on the IDE but when
deploying it on Fuse ESB throws an exception.  To be clear I'm not using the
Drool's servicemix component (Drools Service Engine), I'm building my OSGI
bundle that imports it's Drools dependencies from some other "servicemix"
bundles deployed on the OSGI kernel. I know that  drools builder finds my
rule file but then throws this exception :

	... 32 more
Caused by: java.lang.NullPointerException
	at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:47)
	at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)
	at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)
	at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
	at
edu.ucar.rap.flighthazard.decisionservice.service.impl.SessionManagerImpl.instantiateRuleBase(SessionManagerImpl.java:173)
	at
edu.ucar.rap.flighthazard.decisionservice.service.impl.SessionManagerImpl.initialize(SessionManagerImpl.java:96)

What I'm doing is really basic and it works on my IDE but seems I'm missing
something when deploying on the OSGI. I tried also to use the Drools 5.0.1
API with KnowledgeBase but the same thing. I saw other posts with
classloader problems on OSGI but this seems something different. 


The java code :

	private RuleBase instantiateRuleBase() throws DroolsParserException,
			IOException {
		Reader reader;
		PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
		
		PackageBuilder builder = new PackageBuilder(conf);
		Package pkg;
		RuleBase ruleBase;

		/* Process DRLS */
		Iterator<String> iter = drls.iterator();
		while (iter.hasNext()) {
			
			URL url = URLUtils.getURL(iter.next());
			reader = new InputStreamReader(url.openStream());
	
			builder.addPackageFromDrl(reader);
		}

		// get the compiled package (which is serializable)
		pkg = builder.getPackage();

		// add the package to a rulebase (deploy the rule package).
		ruleBase = RuleBaseFactory.newRuleBase();
		try {
			ruleBase.addPackage(pkg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return ruleBase;
	}


The rule .drl  :


package edu.ucar.rap.flighthazard.decision.rules


import org.drools.base.extractors.*;

import
edu.ucar.rap.flighthazard.decisionservice.dto.FlightHazardsDecisionRequest;
import edu.ucar.rap.flighthazard.decisionservice.dto.FlightHazardThresholds;
import
edu.ucar.rap.flighthazard.core.dto.weatherHazard.WeatherHazardDefinition;
import
edu.ucar.rap.flighthazard.core.dto.weatherHazard.CoverageHazardDefinition;
import edu.ucar.rap.flighthazard.core.dto.weatherHazard.Threshold;
import edu.ucar.rap.flighthazard.core.dto.aircraft.AircraftCharacteristic;
import edu.ucar.rap.flighthazard.core.dto.aircraft.FlightCharacteristic;

import java.util.List;


rule "FindFlightCoverageHazardsThresholds"
salience 50

no-loop 
	when
		$request : FlightHazardsDecisionRequest();
		$hazardDefinition : WeatherHazardDefinition(eval(type.value() ==
"COVERAGE")) from $request.getHazardsOfInterest();
	
		$fhthresholds : FlightHazardThresholds (aircraft.type.code ==
$request.aircraft.type.code,
		hazardOfInterest.data_ref == $hazardDefinition.data_ref,
hazardOfInterest.field_ref == $hazardDefinition.field_ref);
	then
		System.out.println( "Request is: " + $request.toString());
	    System.out.println( "fhthresholds is: " +
$fhthresholds.getHazardOfInterest().getData_ref());
		
		
$hazardDefinition.setThresholds($fhthresholds.getHazardOfInterest().getThresholds());	
		
end



# This rule sets special CEILING, VISIBILITY and FLTCAT thresholds if the
Flight Rule provided in the request is VFR - Visual flight rules
# in this case ceiling and visibility does not matters as hazards.
rule "FlightRule"
salience 10

no-loop 
	when
		$request : FlightHazardsDecisionRequest(
eval(flightCharacteristic.getRule().value() == "VFR" ))
		$hazardDefinition : WeatherHazardDefinition(data_ref ==
"urn:fdc:ncar.ucar.edu:Dataset:CEIL" ||
		data_ref == "urn:fdc:ncar.ucar.edu:Dataset:Visibility" || data_ref ==
"urn:fdc:ncar.ucar.edu:Dataset:FLTCAT" ) from
$request.getHazardsOfInterest()
	   # eval(System.out.println(hazardDefinition.data_ref); true)
		$fhthresholds : FlightHazardThresholds (aircraft.type.code ==
$request.aircraft.type.code,
		 eval(hazardOfInterest.getData_ref()  ==
$hazardDefinition.getData_ref().concat(":VFR")), hazardOfInterest.field_ref
== $hazardDefinition.field_ref)
	then
	//	System.out.println( "Request is: " + request.toString());
	//    System.out.println( "fhthresholds is: " +
fhthresholds.getHazardOfInterest().getData_ref());
		
	   
$hazardDefinition.setThresholds($fhthresholds.getHazardOfInterest().getThresholds());
		
end

Any suggestions will be appreciated.

Thanks,

-Marcel
	
-- 
View this message in context: http://www.nabble.com/Weird-NullPointerException-when-deploying-Drools-rules-on-FUSE-OSGI-4-ESB-tp25106635p25106635.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list