Deprecated
This page is maybe deprecated...
Standalone entity engine
Overview
This page documents the steps I took to get a standalone running entity-engine + catalina. I included catalina so that I could create an example application for accessing the entity engine.
The intention for this exercise was to see if it would be possible to create a standaone entity-engine as the first step towards providing a more modular ofbiz and perhaps even using OSGi for managing the dependencies.
Steps
svn co trunk
modify framework/build.xml:
<project name="OFBiz Framework Build" default="build" basedir="."> <import file="../macros.xml"/> <filelist id="framework-builds" dir="." files="start/build.xml,base/build.xml,sql/build.xml, entity/build.xml,geronimo/build.xml, catalina/build.xml, "/>
(optional) delete unused folders in framework, i.e. all folders and files EXCEPT:
build.xml
component-load.xml
base
catalina
entity
geronimo
sql
start
modify framework/component-load.xml:
<component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd"> <load-component component-location="geronimo"/> <load-component component-location="sql"/> <load-component component-location="entity"/> <load-component component-location="catalina"/> <!-- removed all other components --> </component-loader>
modify framework/base/config/component-load.xml:
<component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd"> <load-components parent-directory="framework"/> <!-- <load-components parent-directory="themes"/>--> <!-- <load-components parent-directory="applications"/>--> <!-- <load-components parent-directory="specialpurpose"/>--> <!- hot-deploy component will be created to access the entity engine --> <load-components parent-directory="hot-deploy"/> </component-loader>
create a component to access the entity engine:
ant create-component - e.g. name = cstest
add an entity definition to cstest:
<entity entity-name="CsTest" package-name="cs"> <field name="id" type="id"/> <field name="myfield" type="description"/> <prim-key field="id"/> </entity>
modify cstest web.xml - remove dependencies on webapp component:
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>Open For Business - CsTest Component</display-name> <description>CsTest Component of the Open For Business Project</description> <context-param> <param-name>webSiteId</param-name> <param-value>cstestSite</param-value> <description>A unique ID used to look up the WebSite entity</description> </context-param> <context-param> <param-name>localDispatcherName</param-name><param-value>cstest</param-value> <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description> </context-param> <context-param> <param-name>entityDelegatorName</param-name><param-value>default</param-value> <description>The Name of the Entity Delegator to use, defined in entityengine.xml</description> </context-param> <context-param> <param-name>mainDecoratorLocation</param-name> <param-value>component://cstest/widget/CommonScreens.xml</param-value> <description>The location of the main-decorator screen to use for this webapp; referred to as a context variable in screen def XML files.</description> </context-param> <context-param> <param-name>widgetVerbose</param-name> <param-value>false</param-value> <description>Enable widget boundary comments. See org.ofbiz.widget.ModelWidget.widgetBoundaryCommentsEnabled().</description> </context-param> <context-param> <param-name>compressHTML</param-name> <param-value>false</param-value> <description>Remove unnecessary whitespace from HTML output.</description> </context-param> <!-- <filter>--> <!-- <filter-name>ContextFilter</filter-name>--> <!-- <display-name>ContextFilter</display-name>--> <!-- <filter-class>org.ofbiz.webapp.control.ContextFilter</filter-class>--> <!-- <init-param><param-name>disableContextSecurity</param-name><param-value>N</param-value></init-param>--> <!-- <init-param>--> <!-- <param-name>allowedPaths</param-name>--> <!-- <param-value>/control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/includes/maincss.css</param-value>--> <!-- </init-param>--> <!-- <init-param><param-name>errorCode</param-name><param-value>403</param-value></init-param>--> <!-- <init-param><param-name>redirectPath</param-name><param-value>/control/main</param-value></init-param>--> <!-- </filter>--> <!-- <filter-mapping><filter-name>ContextFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>--> <!-- <listener><listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class></listener>--> <!-- <listener><listener-class>org.ofbiz.webapp.control.LoginEventListener</listener-class></listener>--> <!-- NOTE: not all app servers support mounting implementations of the HttpSessionActivationListener interface --> <!-- <listener><listener-class>org.ofbiz.webapp.control.ControlActivationEventListener</listener-class></listener> --> <!-- <servlet>--> <!-- <servlet-name>ControlServlet</servlet-name>--> <!-- <display-name>ControlServlet</display-name>--> <!-- <description>Main Control Servlet</description>--> <!-- <servlet-class>org.ofbiz.webapp.control.ControlServlet</servlet-class>--> <!-- <load-on-startup>1</load-on-startup>--> <!-- </servlet>--> <!-- <servlet-mapping><servlet-name>ControlServlet</servlet-name><url-pattern>/control/*</url-pattern></servlet-mapping>--> <session-config><session-timeout>60</session-timeout><!-- in minutes --></session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list> </web-app>
edit hot-deploy/cstest/webapp/cstest/index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="org.ofbiz.entity.Delegator"%> <%@page import="org.ofbiz.entity.DelegatorFactory"%> <%@page import="org.ofbiz.base.util.Debug"%> <%@page import="org.ofbiz.entity.transaction.TransactionUtil"%> <%@page import="org.ofbiz.entity.GenericValue"%> <%@page import="java.util.List"%> <%@page import="org.ofbiz.base.util.UtilMisc"%> <%@page import="java.util.Map"%> <%@page import="java.util.Date"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% Delegator delegator = DelegatorFactory.getDelegator("default"); TransactionUtil.begin(); Long timeMs = (new Date()).getTime(); String id = timeMs.toString(); Map data = UtilMisc.toMap( "id", id ); GenericValue newEntity = delegator.makeValue("CsTest", data); delegator.create(newEntity); TransactionUtil.commit(); TransactionUtil.begin(); List<GenericValue> items = delegator.findList("CsTest", null, null, null, null, false); for (GenericValue item : items) { response.getWriter().print("Id: " + item.get("id") + "<br/>"); } TransactionUtil.commit(); %> </body> </html>
build and run:
./ant ./startofbiz.sh ignore the error: EntityEcaHandler class with name org.ofbiz.entityext.eca.DelegatorEcaHandler was not found,
test web page:http://localhost:8080/cstest/index.jsp
you should see something like:
Id: 1267430281292
The id you get will be different
See also:
http://sourceforge.net/projects/ofbiz-osgi/
2 Comments
Michael Brohl
Outdated pages or pages which should be revised/rewritten to be up-to-date can be moved to Wiki Attic / Outdated Resources. Done for this page.
Jacques Le Roux
Thanks Michael