This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Services and the fly likes Unable to expose a class as webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Unable to expose a class as webservice" Watch "Unable to expose a class as webservice" New topic
Author

Unable to expose a class as webservice

sumatheja dasararaju
Greenhorn

Joined: May 24, 2010
Posts: 9
Hi,
I'm new to web services concept. I have a class where i'm using JBOSS drools api to create a STATEFULKNOWLEDGESESSION. When i try to expose this class as webservices i get an error "NO END POINTS SPECIFIED".
However if i remove all the methods haveing STATEFULKNOWLEDGESESSION variables as arguments, web service is up and I'm able get the wsdl. Can anyone explain me whats wrong with using statefulknowledgesession inside a webserice.


Thanks in advance


sumatheja
sumatheja dasararaju
Greenhorn

Joined: May 24, 2010
Posts: 9
Hi all,
I'm pasting the code of my class below. Please let me know where I've gone wrong.



package test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

import oracle.jdbc.pool.OracleDataSource;

import org.apache.log4j.Logger;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.io.ResourceFactory;
//import org.drools.logger.KnowledgeRuntimeLogger;
//import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;


@WebService
public class ComplianceEngine
{
static int i=0;
static int firstArg = 0;
static ComplianceRun CompRun = new ComplianceRun(0);
String l_constr = "";
static final Logger c_log = Logger.getLogger(ComplianceEngine.class);

@WebMethod
public static String greet( @WebParam(name = "name")
String name )
{
return "Hello" + name;
}

@WebMethod
public String ComplianceRunService(@WebParam(name="RunID")int RunID,@WebParam(name="ClientID")String ClientID){

String ErrorCode = "S";
String ErrorMsg = "Success";

try{
CompRun.setRunID(RunID);
}catch(Exception e){
c_log.fatal("Argument must be an integer");
ErrorCode = "E";
ErrorMsg = "Invalid Run ID";
System.exit(1);
}

try{ /* Drool Connection Try Block */

/* For Drools Guvnor Connection */
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "MyAgent" );
kagent.applyChangeSet( ResourceFactory.newUrlResource("http://127.0.0.1:8080/drools-guvnor/changeset.xml" ));
KnowledgeBase kbase = kagent.getKnowledgeBase();
StatefulKnowledgeSession workingMemory = kbase.newStatefulKnowledgeSession();
OracleDataSource ods = new OracleDataSource();

try{ /* Routing Service Try Block */
System.out.println("");
RoutingService obj1 = new RoutingService();
c_log.info("Run ID => "+RunID);
c_log.info("Client ID => "+ClientID);
l_constr = obj1.GetconnectionStr(ClientID, c_log);
if(l_constr=="Invalid Client Code"){
ErrorCode = "E";
ErrorMsg = "Client ID "+ClientID+" is Invalid";
}else{

try{ /* Data Base Connection Try Block */
c_log.debug("Connection String => "+l_constr);
ods.setURL(l_constr);
Connection con = ods.getConnection();
CompRun.setCon(con);
workingMemory.insert(CompRun);
workingMemory.insert(c_log);
System.out.println("Start Firing Rules\n");
workingMemory.startProcess("AgreementLevelFlow");
workingMemory.fireAllRules();
c_log.info("Program Completed\n");
System.out.println("Program Completed\n");
}catch(Exception e){ /* DataBase Connection Catch */
ErrorCode = "E";
ErrorMsg = "Data Connection Failed -> "+e;
}

}

}catch(Exception e){ /* Routing Service Catch */
c_log.info("Exception -> "+e);
ErrorCode = "E";
ErrorMsg = "Routing Service Failed -> "+e;
}

/* End of Code by Raghu Prasad */


}catch (Throwable t) { /* Drools Connection Catch */
t.printStackTrace();
ErrorCode = "E";
ErrorMsg = "Drools Guvnor Connection Exception";
System.out.println("Drools Guvnor Connection Exception\n");
}

return ErrorCode+"-"+ErrorMsg;

}

/**
* Method to load numbers from the DB.
* @param workingMemory the Working memory of the drools engine.
* @param conn the DB Url connection.
*/
public void loadNUMSfromDB (StatefulKnowledgeSession workingMemory,Connection conn)
{
try {
Statement stmt = conn.createStatement();
ResultSet rs =
stmt.executeQuery("select name, organisation, userid, purpose, location, sysname, systemname, product from nums" );
while (rs.next())
workingMemory.insert(new NU(rs.getString("name"),
rs.getString("userid"),
rs.getString("purpose"),
rs.getString("location"),
rs.getString("sysname"),
rs.getString("systemname"),
rs.getString("product")));
}
catch (SQLException e) {
e.printStackTrace();
}
}

}

and the exception i'm getting is:

org.jboss.deployers.spi.DeploymentException: Error during deploy: vfszip:/home/werewolf7/ofcnprsnl/office/jboss-5.1.0.GA/server/default/deploy/TestWs1.war/
at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:177)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)
at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)
at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
at org.jboss.Main.boot(Main.java:221)
at org.jboss.Main$1.run(Main.java:556)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NoClassDefFoundError: org/drools/runtime/StatefulKnowledgeSession
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2444)
at java.lang.Class.privateGetPublicMethods(Class.java:2564)
at java.lang.Class.getMethods(Class.java:1427)
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilder.processWebMethods(JAXWSMetaDataBuilder.java:914)
at org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder.buildWebServiceMetaData(JAXWSWebServiceMetaDataBuilder.java:148)
at org.jboss.ws.metadata.builder.jaxws.JAXWSServerMetaDataBuilder.setupProviderOrWebService(JAXWSServerMetaDataBuilder.java:50)
at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilderJSE.buildMetaData(JAXWSMetaDataBuilderJSE.java:61)
at org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect.start(UnifiedMetaDataDeploymentAspect.java:64)
at org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl.deploy(DeploymentAspectManagerImpl.java:129)
at org.jboss.wsf.container.jboss50.deployer.ArchiveDeployerHook.deploy(ArchiveDeployerHook.java:76)
at org.jboss.wsf.container.jboss50.deployer.AbstractWebServiceDeployer.internalDeploy(AbstractWebServiceDeployer.java:60)
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.drools.runtime.StatefulKnowledgeSession from BaseClassLoader@4136083b{VFSClassLoaderPolicy@42567aef{name=vfszip:/home/werewolf7/ofcnprsnl/office/jboss-5.1.0.GA/server/default/deploy/TestWs1.war/ domain=ClassLoaderDomain@1fd889aa{name=vfszip:/home/werewolf7/ofcnprsnl/office/jboss-5.1.0.GA/server/default/deploy/TestWs1.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=ClassLoaderDomain@45389b3f{DefaultDomain}} roots=[MemoryContextHandler@1000407791[path= context=vfsmemory://5c4o05t-ioje51-ggjcsjzq-1-ggjcsyb1-2a real=vfsmemory://5c4o05t-ioje51-ggjcsjzq-1-ggjcsyb1-2a], ZipEntryHandler@1204270974[path=TestWs1.war/WEB-INF/classes context=file:/home/werewolf7/ofcnprsnl/office/jboss-5.1.0.GA/server/default/deploy/ real=file:/home/werewolf7/ofcnprsnl/office/jboss-5.1.0.GA/server/default/deploy/TestWs1.war/WEB-INF/classes]] delegates=null exported=[, mattelli.re] <IMPORT-ALL>NON_EMPTY}}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:448)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
... 43 more

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
First of all, the problem with your deployment is that you are missing a Drools class, org.drools.runtime.StatefulKnowledgeSession.
This has no direct relation with a web service endpoint.
I would recommend the following approach:
Separate your web service into two distinct layers - a service interaction layer and a processing layer.
The service interaction layer consists of the endpoint implementation class and any code that makes preparations for invoking the processing layer.
In the service interaction layer there should be nothing that is connected with Drools in your case.

The processing layer contains "business logic" which retrieves and/or processes the data received.
All dependencies on Drools should be concentrated to this layer.

With the above approach you will have a more clear separation of concerns and more easily testable code.
For instance, you can test the processing layer in isolation from a unit test, without starting a web service.
You can also deploy your web service with a mocked or stubbed processing layer, again for test purposes.
Finally, don't forget that missing Drools JAR!
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
sumatheja dasararaju
Greenhorn

Joined: May 24, 2010
Posts: 9
Hi Ivan,
A million thanks for replying. Regarding the drools package I've added the jar to the projects classpath and infact the class is working fine as a standalone application. Is there somewhere else i need to add this jar?


cheers
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Where have you put the JAR files?
If your project is a web application project, then libraries should be in WEB-INF/lib to ensure that they are enclosed in the resulting WAR.
In the Eclipse IDE, the libraries at this location are automatically added to the classpath, so no need to add them to the project's classpath explicitly.
Best wishes!
sumatheja dasararaju
Greenhorn

Joined: May 24, 2010
Posts: 9
Thanks Ivan. That solved my problem. And thanks for the approach you''ve mentioned for web services.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to expose a class as webservice