Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note: The following Integration Guide is aimed at OFBiz Developers with a Basic Knowledge of the actual System.

...

The following approach is meant to implement the Magnolia CMS (http://www.magnolia-cms.com) on top of the OFBIz System. I used the latest Maven Install of Magnolia (3.7) and Trunk Revision 711975 of OFBiz, there is no guerantee that the approach will work on any other Combination of System Versions, but taken from how this is done, it may as well work (wink).

This method works as the following: Magnolia remains a pure content provider and will render the data by its own means - OFBiz will fetch the data and include it to its current context (hence, this approach could be used to render any other content outside the ofbiz system).

Prerequisits

Installation of OFbiz

I recommend downloading and installing the latest trunk

Installation of Magnolia

I used the latest Maven Installation (see Magnolia Maven Install Reference for Installation) and deployed the war file onto the Ofbiz System (remember to add and edit the ofbiz_component file)

Integration Steps

Step 1 Add a service definition file to your application

...

Create a new service.xml file in your appication directory (i created it in an extra folder: servicedef) and add the very same to the ofbizcomponent.xml file --> e.g. by adding:

Code Block
xml
xml
 
<service-resource type="model" loader="main" location="servicedef/services.xml"/>

Step 2 Create the Services to collect the Magnolia data

Open the service.xml file and add:

Code Block
xml
xml
 
[...]
<\!-\- CMS Services \-->


<service name="runCMSQuery" engine="java"
transaction-timeout="72000"
location="org.brandsparadise.cms.Magnolia"
invoke="runCMSQuery" debug="true" validate="true">
<description>Run a query on CMS and return the results</description>
<attribute mode="IN" name="query" optional="false"
type="String" />
<attribute name="queryResult" type="String" mode="OUT" optional="true"/>

</service>

[...]

(take a look at any other service.xml file on the exact layout of a service.xml file)

Step 3 Get OFBiz to load a java source

Create a new src folder and load the sources via ofbiz-component.xml:

Code Block
xml
xml
 
<classpath type="dir" location="src/*" />

Step 4 Create the method classes to fetch the content

Create a new package and call it any name you like (I called mine: org.brandsparadise.cms). Add a class to it (i called mine: Magnolia.java) and add something along the line of :

Code Block
java
java
 

package org.brandsparadise.cms;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Map;
import java.net.*;
import junit.framework.TestCase;

import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;

/*\*
* Base class for OFBiz Test Tools test case implementations.
\*/

public abstract class Magnolia extends TestCase {

public static final String module = Magnolia.class.getName();
public static String cmsUrl = "http://www.google.com";

/*\*
* runs a query on a url and return the results
\*
\*/
public static Map runCMSQuery(DispatchContext dctx, Map context) {

try {
// get Connection
StringBuilder result = new StringBuilder();
byte\[\] buffer = new byte[8192];

InputStream s;

URL url = new URL(cmsUrl + context.get("query").toString());
s = url.openStream();

int size = 0;

do
{                 size = s.read(buffer);                 if (size != -1)                     result.append(new String(buffer, 0, size));             }
while (size \!= \-1);
context = ServiceUtil.returnSuccess();
context.put("queryResult", result.toString());

} catch (MalformedURLException e)
{             // TODO Auto-generated catch block             e.printStackTrace();             context = ServiceUtil.returnError(e.toString());          }
catch (IOException e)
{             // TODO Auto-generated catch block             e.printStackTrace();             context = ServiceUtil.returnError(e.toString());         }
// Debug.log("Query Result: "+results.toString());
return context;
}

public static void main(String\[\] args)
{         junit.textui.TestRunner.run(Magnolia.class);         System.exit(0);     }
}