Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Problem using JSR94 getTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using JSR94 getTemplate

    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).

    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;
    	}
    
    }
    Here is my applicationcontext.xml.

    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 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.

    I've then used Eclipse to generate the stub code for the service and created a test client as below.

    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());
    	}
    }
    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.

    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.

  • #2
    I've got exactly the same problem (trying to do the same in a webapp). The only way to have this piece of code working is to specify a classpath for the "source" property like that :

    <property name="source">
    <value>myrules.drl</value>

    Each time I try to change the path to something a little bit more complicated, like

    <property name="source">
    <value>/[anypath]/myrules.drl</value>

    or

    <property name="source">
    <value>classpath:somewhere/myrules.drl</value>

    I've got the same NPE...

    Does anyone here can explain why it fails when source file isn't in the root folder ?

    Comment


    • #3
      Originally posted by delirii View Post
      I've got exactly the same problem (trying to do the same in a webapp). The only way to have this piece of code working is to specify a classpath for the "source" property like that :

      <property name="source">
      <value>myrules.drl</value>

      Each time I try to change the path to something a little bit more complicated, like

      <property name="source">
      <value>/[anypath]/myrules.drl</value>

      or

      <property name="source">
      <value>classpath:somewhere/myrules.drl</value>

      I've got the same NPE...

      Does anyone here can explain why it fails when source file isn't in the root folder ?

      you need to make sure that folder somewhere is on your classpath and the file myrules.drl is inside it.

      Cheers,
      Anej

      Comment


      • #4
        As far as I can remember (because it's a two years old problem), the folder "somewhere" was in the classpath.

        Comment

        Working...
        X