Hi,
I am currently trying to create a web service that implements a fee calculation using a rule engine. I have followed the details in Chapter 11 of the spring modules documents, but find that my Jsr94Template is null when trying to call getTemplate (causing a null pointer exception).
The code for my web service is as follows (excuse the debug code).
Here is my applicationcontext.xml.Code:@WebService(name = "FeeService", targetNamespace = "http://service.backoffice.com") public class FeeServiceImpl extends Jsr94RuleSupport implements IFeeService { @WebMethod(operationName = "getTransactionFee", action = "urn:GetTransactionFee") @WebResult(name = "getTransactionFeeResponse") public TransactionFee getTransactionFee(@WebParam(name = "txnFeeParam") TransactionFee txn) { final String TXN_FEE_URI="TransactionFeeRules"; final List<TransactionFee> inputs = new ArrayList<TransactionFee>(); inputs.add(txn); System.out.println("Started"); getTemplate().executeStateless(TXN_FEE_URI, null, new StatelessRuleSessionCallback() { public Object execute(StatelessRuleSession session) throws InvalidRuleSessionException, RemoteException { return session.executeRules(inputs); } }); System.out.println("Finished"); // txn.setBIN(464646L); return txn; } }
I deploy this on Tomcat from within Eclipse. I find that if I debug the service on startup the template bean is set correctly via DI.Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="ruleServiceProvider" class="org.springmodules.jsr94.factory.DefaultRuleServiceProviderFactoryBean"> <property name="provider"> <value>http://drools.org/</value> </property> <property name="providerClass"> <value>org.drools.jsr94.rules.RuleServiceProviderImpl</value> </property> </bean> <bean id="ruleRuntime" class="org.springmodules.jsr94.factory.RuleRuntimeFactoryBean"> <property name="serviceProvider"> <ref local="ruleServiceProvider" /> </property> </bean> <bean id="ruleAdministrator" class="org.springmodules.jsr94.factory.RuleAdministratorFactoryBean"> <property name="serviceProvider"> <ref local="ruleServiceProvider" /> </property> </bean> <bean id="ruleSource" class="org.springmodules.jsr94.rulesource.DefaultRuleSource"> <property name="ruleRuntime"> <ref local="ruleRuntime" /> </property> <property name="ruleAdministrator"> <ref local="ruleAdministrator" /> </property> <property name="source"> <value>WEB-INF/classes/TransactionFeeRules.drl</value> </property> <property name="bindUri"> <value>TransactionFeeRules</value> </property> </bean> <bean id="jsr94Template" class="org.springmodules.jsr94.core.Jsr94Template"> <property name="ruleSource"> <ref local="ruleSource" /> </property> </bean> <bean id="FeeService" class="com.aciworldwide.backoffice.cms.service.FeeServiceImpl"> <property name="template"> <ref local="jsr94Template" /> </property> </bean> </beans>
I've then used Eclipse to generate the stub code for the service and created a test client as below.
When I debug this through to the web service code running on Tomcat and look at the template variable I find that it is null.Code:public class FeeTester { /** * @param args */ public static void main(String[] args) throws Exception{ FeeServiceImplLocator loc = new FeeServiceImplLocator(); FeeService port = (FeeService)loc.getPort(FeeService.class); TransactionFee req = new TransactionFee(); System.out.println("\nTesting ATM Transaction"); req.setCardNumber("1234098712340987"); req.setIssuerCountry("840"); req.setTxnType("001"); req.setMerchantCategoryCode("6011"); req.setSourceCurrencyCode(new Integer(840)); TransactionFee resp = port.getTransactionFee(req); System.out.println("Done"); System.out.println(resp.getFeeAmount()); System.out.println(resp.getFeeCurrencyCode()); System.out.println(resp.getBIN()); } }
From a simplistic point of view it looks as if the client request is causing a new instance of the web service to be "created" which hasn't had its bean set via DI.
I can't believe this is a bug as I'm sure there must be plenty of people using Spring Modules to do this (given the number of example articles on the net). The JSR94 sample distributed with spring modules seems to suggest that I am using the correct code.
Therefore there must either be something stupid that I've done and can't see it or my runtime environment is wrong. I have tried a number of different ways of coding based on the examples from different web sites nut I still haven't cracked it.
Any help would be appreciated.
Cheers,
Dave.



