• Welcome to KonaKart Community Forum. Please login or sign up.
 

KonaKart integration with another webapp in Tomcat

Started by jeffzzang, February 16, 2009, 11:32:06 pm

Previous topic - Next topic

jeffzzang

We are trying to integrate KonaKart with an existing web app written in JSF. I was successfully able to deploy KonaKart as a war, and dropped it into my Tomcat webapps directory. Both client and admin versions run properly.

I want to use the Java API to make calls to the KKEng object so users on our existing website can use the functionality in KonaKart. My first attempt at this included the following:

In one of my JSF actions, I call:


Class engineClass = Class.forName("com.konakart.app.KKEng");
       
KKEngIf eng = (KKEngIf) engineClass.newInstance();
String sessID = eng.login("someemail@email.com","passpass");

ProductSearchIf pSearch = new ProductSearch();
pSearch.setSearchText("Cisco");
ProductsIf prods = eng.searchForProducts(sessionId,null,pSearch,-1);
ProductIf[] prod = prods.getProductArray();
for (int p = 0; p < prod.length; p++){
    System.out.println("Product: " + prod[p].getName());
}


However when I run this, I get the following error:


PropertyFileFinder.findProperties() Could not find konakart.properties on the classpath
com.konakart.app.KKException: Could not find konakart.properties on the classpath


I also noticed that when the above code is executed, it looks like it loads a new instance of KKEng into memory. The reason I know this is because the KonaKart intro text (license information, default variable values, etc.) gets printed to the logs twice - once at Tomcat startup and a second time when the above code is executed.

I'm assuming one way around this is to load the static instance of the KKEng class from the instance of KonaKart that is already running. How do I get the static instance? I've looked into classloaders in Tomcat, but couldn't really find anything useful.

Another route I've tried is to set crossContext="true" in both webapps. I was able to access KonaKart's ServletContext, but I don't know where to go from there.

Does anyone else have experience integrating an existing site with KonaKart? Any help would be greatly appreciated.

trevor

Normally this is achieved in one of two ways:

  • You place KonaKart is a separate webapp and communicate via SOAP

  • You place the KonaKart jars in the same webapp and communicate using the Java APIs



It looks like you have done both, which is why you see KK being instantiated twice in the log. What I suggest is for you to use the Java APIs assuming that you don't get any jar conflicts when you mix the KK jars with the jars of your current application. This method performs better and should work once you put konakart.properties in the classpath (i.e. you move it to the classes directory).

If for some reason you do get jar conflicts that you can't resolve, then you should instantiate the KK SOAP engine from your JSF webapp and point it to the KK instance running in its own webapp.

jeffzzang

Thanks for your response. If I use the java APIs, will I have to merge any configuration files such as web.xml? Also, can I leave struts-related files such as strut-config.xml out of the merged webapp?

trevor

If you are only using the server eCommerce engine (KKEngIf) then you don't need any of the UI related bits (all struts files, JSPs , KKAppEng etc.).

jeffzzang

Thanks for your response. One other question about integrating KonaKart with an existing database of customers. My existing database has a table of website accounts which contains the normal customer information (name, address, etc.). If I want to integrate KonaKart with this existing table of accounts, do I have to import all the data from the existing database into the KonaKart CUSTOMERS table? If not, then when a customer places an order, what should I put in the ORDERS.CUSTOMERS_ID field? Any guidance would be greatly appreciated.

kate

Hi,

The ideal approach will depend on many circumstances so it's difficult to answer generically here.

KonaKart will not be able to use the customer data in your own data structures directly.

The easiest solution would probably be to load the customer data into KonaKart.   How you do this rather depends on your circumstances again.   You might choose to synchronise the data using triggers on the nominated master source, you might choose to load it every time a person logs in.... etc...

If you want some more in-depth consultancy on these kinds of topics you can always take out a support contract and contact the consultants at KonaKart who will be ony too pleased to help...   

--Kate

jeffzzang

Question about how to use the KonaKart java API:

From reading other forum postings, I've gathered that if we're including the KK jar files in our own web app and using the java api, we should only concern ourselves with calling methods in KKEngIf. However,  many of the methods in KKEngIf requires a session ID to be passed into it.

The Java API examples included in the download package use the credentials root@locahost.com // password when initializing the engine. Is this the username and password that should be used when a user is browsing products and has not yet logged in?

Also, when the user DOES log in, should I be passing the new session ID that is returned by KKEngIf.login() to the KKEngIf methods that require session IDs?

Last, I noticed that passing a random string to KKEngIf.getCustomer(String sessionId) returns a customer with user ID equal to 1 (which is root@localhost.com in the DB) - why does the implementation behavior deviate from what's written in the API documentation? I thought it was supposed Null.

julie


QuoteThe Java API examples included in the download package use the credentials root@locahost.com // password when initializing the engine. Is this the username and password that should be used when a user is browsing products and has not yet logged in?


No. You never need to pass a session id if the user hasn't logged in. In some API calls it is an optional parameter because if present we can figure out where the customer is from and maybe add tax to the prices. If not we show the default prices.

QuoteAlso, when the user DOES log in, should I be passing the new session ID that is returned by KKEngIf.login() to the KKEngIf methods that require session IDs?


Yes.

QuoteLast, I noticed that passing a random string to KKEngIf.getCustomer(String sessionId) returns a customer with user ID equal to 1 (which is root@localhost.com in the DB) - why does the implementation behavior deviate from what's written in the API documentation? I thought it was supposed Null.


Are you sure ?  I get an exception and so should you.

jeffzzang

Thanks. It didn't know you can pass in NULL for the session Id.

I also figured out why the .getCustomer() method wasn't throwing an exception. I was passing it session IDs from previous sessions that I thought would have been invalidated when I restarted Tomcat. It looks like session IDs are stored in the SESSIONS table which I'm assuming is where the .getCustomer() method queries.

Thanks for your help!

julie

Expired sessions can be removed from the Admin App or from an Admin Eng API call.