Hi, 

I am new to the Drools , i wanted to expose rules as a webservice using
Axis2. 

what i have done is that 
1. I have created a drools Project (working fine on eclispe) export all
files in jar
2. Placed the jar file in C:\Program Files\Apache Software Foundation\Tomcat
7.0\webapps\axis2\WEB-INF\lib directory
3. Created a new Dynamic java project with axis2 facet.created a class with 


**

package in.abhi.ws;


import java.math.BigDecimal;

import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;


import com.sample.SaleItem;


public class Test {

        private static KnowledgeBase readKnowledgeBase() throws Exception {

                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
                                .newKnowledgeBuilder();
                
kbuilder.add(ResourceFactory.newClassPathResource("KanasSalesTax.drl"),
                                ResourceType.DRL);
                
                KnowledgeBuilderErrors errors = kbuilder.getErrors();
                if (errors.size() > 0) {
                        for (KnowledgeBuilderError error : errors) {
                                System.err.println(error);
                        }
                        throw new IllegalArgumentException("Could not parse 
knowledge.");
                }
                KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
                kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
                return kbase;
        }



        public BigDecimal salesTax(String taxState, String typeItem) {
                BigDecimal taxCal = null;
                try {
                        // load up the knowledge base
                        KnowledgeBase kbase = readKnowledgeBase();
                        StatefulKnowledgeSession ksession = kbase
                                        .newStatefulKnowledgeSession();

                        // Non-prescription item
                        // Expect $1.89 for the tax

                        SaleItem item1 = new SaleItem();

                        item1.setPurchaseState(taxState);
                        item1.setItemType(typeItem);
                        item1.setSalesPrice(new BigDecimal(29.95));
                        ksession.insert(item1);
                        ksession.fireAllRules();

                        taxCal = item1.getSalesTax();

                        System.out.println(item1.getPurchaseState().toString() 
+ " "
                                        + item1.getItemType().toString() + ": "
                                        + item1.getSalesTax().toString());
                } catch (Throwable t) {
                        t.printStackTrace();
                }
                return taxCal;
        }
}


**
4. Then created a bottom up java bean webservice of it using the same above
class.
5. Wsdl is generated 


i am getting the error response on eclispe console while testing by soap-ui

**********


java.lang.NullPointerException
        at
org.drools.util.CompositeClassLoader.getResourceAsStream(CompositeClassLoader.java:122)
        at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:234)
        at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:215)
        at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:748)
        at
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:87)
        at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:167)
        at
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:721)
        at
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:381)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
        at
org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358)
        at
org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49)
        at
org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:369)
        at
org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:53)
        at 
org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:71)
        at 
org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:869)
        at 
org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:826)
        at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:404)
        at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:586)
        at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:37)
        at in.abhi.ws.Test.readKnowledgeBase(Test.java:31)
        at in.abhi.ws.Test.salesTax(Test.java:55)
        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.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
        at
org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
        at
org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
        at
org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
        at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
        at 
org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
        at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
        at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
        at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
        at
org.drools.util.CompositeClassLoader.getResourceAsStream(CompositeClassLoader.java:122)
        at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:234)
        at
org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:215)
        at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:748)
        at
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:87)
        at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:167)
        at
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:721)
        at
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:381)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
        at
org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358)
        at
org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49)
        at
org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:369)
        at
org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:53)
        at 
org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:71)
        at 
org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:869)
        at 
org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:826)
        at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:404)
        at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:586)
        at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:37)
        at in.abhi.ws.Test.readKnowledgeBase(Test.java:31)
        at in.abhi.ws.Test.salesTax(Test.java:55)
        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.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
        at
org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
        at
org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
        at
org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
        at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
        at 
org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
        at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
        at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
        at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
****************

Please let me know how to make it work 

--
View this message in context: 
http://drools.46999.n3.nabble.com/Drools-as-a-Webservice-tp3950198.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to