Friday, March 21, 2008

Using Ofbiz and Wicket - Part I

This article is the first article and probably more to follow on how to use Wicket with Ofbiz.

Both Wicket and Ofbiz are from ASF (Apache Software Foundation) but unfortunately not many ppl seem to have used them together.

Primary reason for me to use them together was complexity and amount of configuration required to use existing Ofbiz frontend frameworks such as screen widget and learning additional technologies such as freemarker, beanshell etc. That lead me to look for a framework which would replace that and provide more - hence Apache Wicket.

Apache Wicket falls into already crowded MVC UI Frameworks consisting of struts, seam amongst others. You can get an entire list from Wicket website :). Yes, it has AJAX support builtin in the framework and yes it has rich set of components both AJAX and otherwise as Wicket extensions and at WicketStuff.org with integration with popular Javascript AJAX libraries DOJO, YUI and JQuery and few others.

Now that we have some background, lets see what you need to get started and use Wicket "inside" Apache Ofbiz.

  • Ofbiz comes with embedded Tomcat at the time of writing Ofbiz 4.0 came with Tomcat 5.5.23 and fortunately Wicket can be deployed in any standard web container
  • Download wicket binaries from Apache Wicket site, copy them over to your Ofbiz application lib directory where you have your application and other 3rd party jars. I chose to put it under hot-deploy/myapp/webapp/myapp/WEB-INF/lib
  • Add WicketFilter entry to your web.xml file (Note: Both WicketFilter and Ofbiz ContextFilter will be listening on /* requests - so initially there will be chaining of those filters, but for this first article I will ignore that) - Make sure to put WicketFilter entry before ContextFilter so WicketFilter gets called first
  • Write your first Hello World in Wicket by creating your WebApplication and WebPage classes - access the URL (http://localhost:8080/yourappcontext) and see it in action, where yourappcontext is whatever you configured it to be in your ofbiz-component.xml file
In the following articles I will try to cover things like using Ofbiz Entity Engine, Service Engine from wicket and may be how to translate Ofbiz ecommerce application using entirely Wicket. On the way will try to quickly cover some cool UI components both SEO friendly and otherwise.

How to resolve channel 1: open failed: administratively prohibited: open failed

There are a few reasons why you could get

channel 1: open failed: administratively prohibited: open failed

But essentially it means the port you are trying to tunnel into on the remote machine cannot be opened

To debug the issue
  • If you have access to the remote machine check /var/log/secure to get more information on error
  • You could try ssh tunnel in verbose mode with -v option
  • Try with a different port number on the remote host just to test - some ports are reserved
To resolve the issue - Depending on what the error was from debugging you might have to
  • If the error in the secure log was cannot resolve host name - it means you need to restart your network service or interfaces - it could be due to dns server issues
  • restart sshd on the remote server - make sure port forwarding is enabled in your ssh config - there are plenty of resources on the net that will explain this

Thursday, March 20, 2008

How to package Wicket jars quickly

Wicket is buildable only using maven. Using maven install is not bad if you have to just build Wicket once, but when you have to build it multiple times, its takes its toll :) - on my 2.4GHz, 4Gb RAM dell laptop it takes atleast 8-12 mins - thats painful.

If you are not Maven guru and would like to get this done quickly - here is what I tried and it worked. I could not find any documentation that shows exactly these steps so...

Depending on the wicket jar that you want to build - cd to that subdirectory under wicket and use

mvn -Dmaven.test.skip=true compile jar:jar install:install

or any combination of the options above which are self explanatory, but I will explain them anyway, just in case-
compile - compile phase of maven which will compile all
jar:jar - is the jar goal of package phase if you specify the package instead of jar:jar it will also try to generate javadocs which will take forever
install:install - deploy phase goal

Hope that helped - would save atleast 30-45 mins if you didnt know maven

Thursday, March 13, 2008

Main entities and their relationships

Following are the main entities to get the basic e-commerce store up and running and their relationships

  • Website -> Store -> Catalog -> Categories
  • Store -> Payment, Email, Facilities
  • Categories -> Product

You will find most of the convenience methods to extract information out for these entities (for e-commerce) are in *Worker files. e.g. CategoryWorker has all category convenience methods, CatalogWorker for catalog and so on.

Tuesday, March 11, 2008

Not so obvious about Ofbiz Categories and Catalog

Assumption:You should already be familiar with Ofbiz Category/Catalog data model. If you are not, please refer to the database tables and understand the relationship before proceeding further.

PRODUCT_CATEGORY should contain all the categories that you ever need.
PROD_CATALOG_CATEGORY contains a subset of the categories from the above table. Why the subset you ask? ... because PROD_CATALOG_CATEGORY table contains categories which are directly linked to a given catalog. Under normal circumstances, you would need a handful of categories (which are of type identified by the type in PROD_CATALOG_CATEGORY_TYPE). e.g. Browse Root, Quick Add, Search and Promotions and may be Whats new and Most popular. Most categories in the PRODUCT_CATEGORY table should be direct or indirect child of Browse Root category and should be of type CATALOG_CATEGORY. Only a handful of other categories (e.g. Quick Add, Search, Promotions and any other custom ones that you define) are standalone categories.

  • Quick Add category is used to group all the products which can be added together in one shot
  • All child (immediate or otherwise) categories of Browse Root categories are used for Navigation on ecommerce site (e.g. left nav on the Ofbiz ecommerce demo).
  • Promotion category is used to show promotional products
  • Search categories are used for product searches.

Refer to Ofbiz ecommerce demo and demo data under ecommerce data/demo*.xml that you installed to see the relationship and how its used/displayed

Monday, March 10, 2008

How to Hot Deploy your application in Ofbiz

Ofbiz uses embedded tomcat container as a web/application server. Ofbiz comes with hot-deploy directory exactly for that purpose - to be able to hot-deploy your application. This comes in handy especially during development, since Ofbiz startup takes a while, restarting several times during the development can be painful.

hot-deploy in Ofbiz doesnt work out of the box, there are a couple of minor config changes that you need to do before you can use it.

  1. Copy you Ofbiz application (web application) under hot-deploy directory. Make sure all the directory structure of your ofbiz application is correct.
  2. Create (or copy from other ofbiz applications) component-load.xml file and add your applications load-component element tag
  3. In your ofbiz_home/framework/base/config/ofbiz-containers.xml file change the property setting app-contact-reloadable to true e.g. <property name="apps-context-reloadable" value="false"/>
  4. Restart ofbiz for this change to take effect.
  5. To test if its working, modify one of the java files of your application and recompile it. You will see messages on your console and/or log file indicating the web app context being reloaded.
    Important: I use build.xml in my application to copy my application jar file under my applications ofbiz_home/hot-deploy/myapp/webapp/myapp/WEB-INF/lib directory. I have not tried choosing a different deploy location so not sure if it will work.

Friday, March 7, 2008

Setting up product database and seed data for Ofbiz

This post follows the main document on Ofbiz docs site and contains information that are not included in that document or information that is "in between lines".
Ofbiz Setup Guide

  1. Make sure the default delegator in framework/entity/config/entityengine.xml is pointing to the correct database
  2. For production db setup from the ofbiz home run ant run-install-seed , this will install only the seed data which is the bare minimum data required for Ofbiz to come up in the most basic meaningful way and then you can enter your custom data
  3. Create your business specific data by looking at Demo*.xml files in ecommerce, accounting and other applications that comes with Ofbiz. In order to run and customize e-commerce store, you will need at least Accounting/data/DemoOrgnization e-commerce/data/DemoProduct.xml.
  4. Pay close attention to the "id" fields in the data file, these are the primary keys for your data. In order to avoid conflicts with existing data choose alpha numeric keys which begin with a string which identifies your company or business.
  5. Once these data files are created, they can be imported through the WebTools/Import functionality. If the files are successfully imported, you will see message towards teh bottom indicating how many entities were successfully imported. Note: import process is atomic and is part of 1 transaction - so if you have lot of data and if for any reason import fails, none of the data from that import will be saved. So you can import the data in its entirity.