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

Creating KKAppEng and then...in Wicket

Started by Ted, October 12, 2009, 01:41:32 pm

Previous topic - Next topic

Ted

I've started on a project we're we have to integrate an entirely new Wicket application with KonaKart. Although the KonaKart Struts/JSP frontend application gives us a lot of information as to how to interact with the client engine KKAppEng, there are a few constructions I'm not entire confident about.

We have taken the following resources from the KonaKart distribution and added them inside our Wicket Maven application:

  • in WEB-INF/lib: konakart.jar, konakart_app.jar, konakart_custom.jar, konakart_utils.jar, konakart_village-2.0.jar

  • in src/main/resources: konakart.properties and konakart_app.properties

  • the rest is bascially good ol' MySQL 5 filled with the konakart_demo.sql and the correct JDBC driver




The first problem: How to create KKAppEng? (Does KKEngPlugin know more?)

Basically I have inside my Wicket application a HomePage which extends TemplatePage - this I tried to mimick from the Struts/JSP frontend classes CatalogMainPageAction and it's parent BaseAction. But when I have only the BaseAction code in place, e.g.:

            String storeId = getStoreIdFromRequest(request);

            StoreInfo si = new StoreInfo();
            si.setStoreId(storeId);
            kkAppEng = new KKAppEng(si);


I get this NullPointerException in com.konakart.al.KKAppEng.getEngConfCopy:

Caused by: com.konakart.al.KKAppException: java.lang.NullPointerException
at com.konakart.al.KKAppEng.init(Unknown Source)
at com.konakart.al.KKAppEng.<init>(Unknown Source)
at somepackage.wicket.ui.TemplatePage.getAppEng(TemplatePage.java:195)
at somepackage.wicket.ui.HomePage.<init>(HomePage.java:40)
... 33 more
Caused by: java.lang.NullPointerException
at com.konakart.al.KKAppEng.getEngConfCopy(Unknown Source)
at com.konakart.al.KKAppEng.getAServerEngineInstance(Unknown Source)


So my solution was the invoke the other constructor first:

EngineConfig engConf = new EngineConfig();
try {
engConf.setPropertiesFileName("konakart.properties");
engConf.setAppPropertiesFileName("konakart_app.properties");
engConf.setMode(engineMode);
engConf.setStoreId(storeId);
engConf.setCustomersShared(customersShared);
engConf.setProductsShared(productsShared);

// override store id with one from request if any
String requestStoreId = getStoreIdFromRequest(request);
if (requestStoreId != null) {
engConf.setStoreId(requestStoreId);
}

// this sets e.g. property file internally...
appEng = new KKAppEng(engConf);
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate EngConf.", e);
}

// ..and now we have to use the KKAppEng(StoreInfo storeInfo) for
// when a user creates a new session.
StoreInfo si = new StoreInfo();
si.setStoreId(engConf.getStoreId()); // we have default store or request store
appEng = new KKAppEng(si);


Now everything works fine - but ofcourse this setup seems weird: having to call 2 constructors to properly initialize everything. In Struts a mysterious com.konakart.plugins.KKEngPlugin seems to would have called the KKAppEng(com.konakart.appif.EngineConfigIf engConf) constructor first when the container loaded. Now we have to do that ourselves so it seems. Is this true? It looks like there's no source of KKEngPlugin so there's noway to see what that class does in order to do it manually.

Also, I'm not sure whether or not properties from konakart.properties override any set properties via the setters e.g. engConf.setMode(engineMode) this way.

Next: Why can 't I retrieve any categories?

Now that I don't get any exceptions anymore I started out to get the categories for a block on the homepage, but I'm not getting any results from the CategoryMgr. It also seems that I had to log in myself as one of the example users - but I didn't see such code in the STruts/JSP application source so somehow something is playing tricks with me :D

CategoriesPanel is supposed to list the categories, buit it doesn't. (I've passed the KKApEng created earlier to the constructor for this component and is being used as a protected variable "appEng").

appEng.getCustomerMgr().logout();
String sessionId1 = appEng.getEng().login("root@localhost", "password");
String sessionId2 = appEng.getCustomerMgr().login("root@localhost", "password");
log.debug("sessionId1: " + sessionId1);
log.debug("sessionId2: " + sessionId2);
log.debug("appEng.getSessionId(): " + appEng.getSessionId());
log.debug("appEng.getCustomerMgr().getCurrentCustomer(): " + appEng.getCustomerMgr().getCurrentCustomer());
log.debug("appEng.getCategoryMgr().isMgrReady(): " + appEng.getCategoryMgr().isMgrReady());
log.debug("appEng.getCategoryMgr().getCats(): " + appEng.getCategoryMgr().getCats());
log.debug("appEng.getCategoryMgr().getCurrentCat().getName(): " + appEng.getCategoryMgr().getCurrentCat().getName());

results in

[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - sessionId1: 194a5dd2e2a708b20d63a8bfc93a40ed
[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - sessionId2: b99b0cf470e757410220e29d768cf3ac
[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - appEng.getSessionId(): b99b0cf470e757410220e29d768cf3ac
[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - appEng.getCustomerMgr().getCurrentCustomer(): Customer:
accountCreated = null
accountLastModified = null
birthdate = Mon Jan 01 00:00:00 CET 2001
emailAddr = root@localhost
faxNumber =
firstName = John
gender = m
globalProdNotifier = 0
id = 1
lastName = doe
lastLogon = null
newsletter = 0
numberOfLogons = 0
password = null
globalProdNotifier = 0
telephoneNumber = 12345
type = 0
groupId = -1
custom1 = null
custom2 = null
custom3 = null
custom4 = null
custom5 = null

[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - appEng.getCategoryMgr().isMgrReady(): false
[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - appEng.getCategoryMgr().getCats(): null
[2009-10-12 14:21:07,125] DEBUG somepackage.wicket.ui.tiles.CategoriesPanel - appEng.getCategoryMgr().getCurrentCat().getName():


There are no categories returned. I've checked the database they're all there. Further more I'm trying to rewrite some of the Struts methods (using HttpServletRequest) to Wicket methods (using Wicket's own Request object). My being new to integrations with KonaKart - and even more so since I don't use the existing Struts/JSP frontend - I realize there are a few subtleties I think I'm not aware of.

A few questions:

Can information such as categories be retrieved from the KonaKart client API anonymously or do I always need to be logged in as someone?

What's the difference between

  • KKAppEng's getEng().login(username, password)

  • KKAppEng's getCustomerMgr().login(username, password)



Why does getCategoryMgr().isMgrReady() say false? Is this relevant for my problem (= not getting anything) and if so, how can I ascertain the cause?

There are a few Struts methods, such as manageCookieLogout(request, response, kkAppEng), which manipulate the HttpServletRequest and HttpServletResponse. For Wicket I've rewritten them to use it's own wrappers for that (org.apache.wicket.Request and org.apache.wicket.Response) because that's simply good practice - but I'm wondering if the client engine implicitly is expecting session attributes which I don't set anymore (because of some rewriting).

If someone (with or without specific Wicket knowledge) can give me any pointers, they would be greatly appreciated!!


trevor

I don't know much about Wicket outside of cricket that is, but I can have a shot ....

KKAppEng has two constructors because one of them is called only once by the framework (in our case struts) to set up global aspects common to all future instances of the kkAppEng (e.g. The thread that updates global caches). The other one is called every time an instance is created for a customer.

QuoteWhat's the difference between
KKAppEng's getEng().login(username, password)
KKAppEng's getCustomerMgr().login(username, password)


The first one is a login directly on the server engine. The second one uses the client engine which also does a login on the server engine but then stores the session id for future calls. It also saves a copy of the current customer object, merges the temporary basket with that of the logged in  user and refreshes the data of the logged in customer so that the JSPs display it correctly. You could write your application just using the server engine (which is stateless) and then manage state whichever way you see fit. The client engine attempts to simplify things by removing a lot of the code from the struts action classes and saving state for the current customer.

QuoteWhy does getCategoryMgr().isMgrReady() say false?

This means that the refreshCaches() method hasn't been called on the CategoryMgr. This is because the constructor of kkAppEng which sets up the refresh thread hasn't been called. This is the reason why you don't get categories back.

Ted

Thanks for your insight!

Since I can't ascertain the correct way to set up global aspects common to all future instances of the KKAppEng since it's inside com.konakart.plugins.KKEngPlugin - is it possible to view the code of com.konakart.plugins.KKEngPlugin somewhere? Then I can make sure that our Wicket framework basically uses the same approach at startup of the application.

julie

Please contact support AT konakart.com for these types of questions.


Ranjith

I am having the same issue, can you suggest me how to proceed with it.

julie

I would code directly to the KKEng and not use KKAppEng at all if you aren't using the Struts / JSP storefront we supply as a part of the product.