[fleXive] Developer Blog

July 30, 2010

Podcast on JSF Central

Filed under: Using fleXive — Tags: , , , , — Daniel Lichtenberger @ 08:47

JSF Central just published a podcast about [fleXive] recorded at last year’s JSFdays. It’s basically an introduction to [fleXive], and Kito was of course a very competent and knowledgeable interviewer, so the interview covers quite a few interesting points I wouldn’t have thought of before.

Continue to the podcast…

March 16, 2010

Maven archetype updated, Beta 3 released

Filed under: Development News,Releases,Using fleXive — Tags: , , , , , , — Daniel Lichtenberger @ 16:13

The Maven EAR archetype has been updated after the release of [fleXive] 3.1 Beta 3. It is of course based on beta 3, and includes a few minor changes and bugfixes that justified a new version.

The flexive backend is now always reached under the /flexive context (both from the embedded Jetty instance and from EAR deployments), the application itself always under /war. To get started:

  1. mvn archetype:generate -DarchetypeGroupId=com.flexive -DarchetypeArtifactId=flexive-archetype-ear -DarchetypeVersion=0.7 -DarchetypeRepository=http://repo.flexive.org/maven2/
  2. Enter the project name and group, e.g. test/test
  3. cd test
  4. mvn install
  5. cd war
  6. mvn jetty:run
  7. Open http://localhost:8080/flexive/ in your browser and complete the installation by logging in with supervisor/supervisor.

For more information on the Maven support, please refer to the reference documentation.

April 16, 2009

WAR deployment with EJB 3.1 and Glassfish v3 Preview

Filed under: Development News,Using fleXive — Tags: , , , , , , — Daniel Lichtenberger @ 15:32

Update 2009/07/15: address the Glassfish v3 Preview instead of the older Prelude release.

EJB 3.1 brings the deployment of EJBs as part of a WAR, ultimately removing any entry barriers to using EJBs with a container that supports EJB 3.1. This article will show how to deploy [fleXive] as part of a WAR application, using [fleXive]‘s WAR archetype for Maven and Glassfish v3 Preview.

Create the WAR project

To get started, create a new Maven project using our WAR archetype:
mvn archetype:generate -DarchetypeGroupId=com.flexive -DarchetypeArtifactId=flexive-archetype-war -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://repo.flexive.org/maven2/ -DgroupId=my.group.test -DartifactId=webapp-test -Dversion=1.0-SNAPSHOT

This creates a basic WAR application with the following directory structure:

    webapp-test
    |-- pom.xml
    `-- src
        `-- main
            |-- java
            |   `-- my
            |       `-- group
            |           `-- test
            |               |-- EJBExampleBean.java
            |               `-- ExampleBean.java
            `-- webapp
                |-- WEB-INF
                |   |-- faces-config.xml
                |   `-- web.xml
                `-- index.xhtml

EJBExampleBean shows a prime feature of EJB 3.1: instead of having to declare an EJB interface and packaging the EJB class in a separate EJB JAR file, we just add our EJB to the web application and annotate it with @javax.ejb.Stateless (of course, you can still use explicit local and remote interfaces). This turns it into a fully-fledged EJB that can be injected into other managed beans using the @EJB annotation.

@Stateless(name = "EJBExample")
public class EJBExampleBean {

    public Map<FxType, Integer> getInstanceCounts() throws FxApplicationException {
        final Map<FxType, Integer> result = new HashMap<FxType, Integer>();
        final FxEnvironment environment = CacheAdmin.getEnvironment();
        // Invoke fleXive query through EJB and collect the results
        for (FxFoundType foundType : new SqlQueryBuilder().select("@pk").getResult().getContentTypes()) {
            result.put(environment.getType(foundType.getContentTypeId()), foundType.getFoundEntries());
        }
        return result;
    }
}
/**
 * Request-scoped JSF bean accessing the EJB.
 */
public class ExampleBean {
    @EJB EJBExampleBean exampleEJB;
    private Map<FxType, Integer> instanceCounts;

    public Map<FxType, Integer> getInstanceCounts() throws FxApplicationException {
        if (instanceCounts == null) {
            instanceCounts = exampleEJB.getInstanceCounts();
        }
        return instanceCounts;
    }
}

In our pom.xml we add the [fleXive] EJB and JSF artifacts, as well as Glassfish itself to provide the EJB 3.1 APIs during compilation. It seems that Glassfish v3 Preview does not bring Sun’s EL-1.0 implementation (which we need for Facelets), so we have to add this too.

<properties>
    <flexive.version>3.1-SNAPSHOT</flexive.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.flexive</groupId>
        <artifactId>flexive-ejb</artifactId>
        <type>ejb</type>
        <version>${flexive.version}</version>
    </dependency>

    <dependency>
        <groupId>com.flexive</groupId>
        <artifactId>flexive-plugin-jsf-core</artifactId>
        <version>${flexive.version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.el</groupId>
        <artifactId>el-ri</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.javaee</artifactId>
        <version>3.0-Prelude-b28b</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

The pom.xml also expands the [fleXive] EJBs into the WEB-INF/classes folder of the web application, because Glassfish v3 Prelude Preview does not yet support EJB-JAR deployments:

<!--
    Unpack the flexive-ejb artifact and add it to WEB-INF/classes
    (Glassfish v3 Prelude does not support EJB-JAR deployment yet)
-->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <!-- Copy the EJBs to target/flexive -->
        <execution>
            <id>copy-ejb</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.flexive</groupId>
                        <artifactId>flexive-ejb</artifactId>
                        <version>${flexive.version}</version>
                        <overWrite>true</overWrite>
                        <outputDirectory>target/flexive/WEB-INF/classes</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-beta-1</version>
    <configuration>
        <webResources>
            <resource>
                <directory>target/flexive</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>

Invoke mvn package to compile and package the application into target/webapp-test.war.

Glassfish v3 Prelude Preview setup

Download and install Glassfish v3 Preview.

Before deploying a [fleXive] application, you need to perform additional setup steps described in the reference documentation:

  • Download the [fleXive] distribution
  • Install the required libraries to [glassfish-home]/glassfish/domains/domain1/lib/ext
  • Add the datasources
  • Initialize the database schema as described here

Deploying the WAR application to Glassfish

Finally, start Glassfish with bin/asadmin start-domain and deploy the WAR file from your project directory with [glassfish-home]/bin/asadmin deploy --force=true target/webapp-test.war. Deployment should only take a few seconds, and the application should be running and display the output from calling our EJB at http://localhost:8080/webapp-test/.

A note on JSF2

[fleXive] is a JSF 1.2 application. As such, it should work without changes in a JSF2 container. However, we ran into some issues, mostly due to RichFaces’ Ajax4JSF implementation. In the backend application, you need to force client-side state saving (through a config parameter in the web.xml), and some administration pages don’t work yet. The JSF components themselves appear to be working without problems, however they are still based on JSF 1.2 and Facelets – thus they cannot be used in a true JSF2 application.

April 10, 2009

The Global Configuration Plugin (or: Division not defined)

Filed under: Using fleXive,documentation — Tags: , , , , , , — Daniel Lichtenberger @ 10:45

I recently installed the minicms demo on a virtual server (VPS) with 256 MB of RAM. While the good news is that it all went rather well given the memory constraints (there are even 80-100 MB of RAM remaining after booting minicms and the backend), I got caught on an unexpected front: if you access the server using a domain name (as in http://my.domain.net:8080), you get a “Division not defined” message when accessing the /war or /flexive-backend-war context. The quick solution (which wasn’t apparent to me, until I remembered the cause): use the IP address instead. What’s the problem, and how do we solve it?

[fleXive] has the concept of divisions. A single [fleXive] instance can serve multiple “divisions”, which are fully independent from each other and use separated databases (possibly on different hosts and from different vendors). The division of a web request is determined by looking at the URL: each division has a regular expression to match the URL pattern, the first division that matches the request pattern will be used to serve the request.

Now, this is less interesting for our small demo project, but very important for ASP-like deployments where you serve multiple customers using a single server. The major gotcha is that by default, the first (default) division matches only requests that use localhost or an IP address as the hostname. Any other request will lead to the “Division not defined” error, because the request URL does not match the pattern of the first (and only) division.

So how do we redefine the URL pattern of the first division? [fleXive] provides a web-based UI for the division mapping table through the global configuration plugin. Unluckily for us, this plugin does not get packaged by our default Maven project (mainly for  security reasons, because it uses a default login and this can of course wreak havoc with a running [fleXive] server).

First, since we use the Maven Jetty plugin, we have to deploy the plugin to Jetty. Open minicms/war/pom.xml and add the following dependency to the Jetty configuration:

<plugin>
   <groupId>org.mortbay.jetty</groupId>
   ...
   <dependencies>
      ...
      <dependency>
         <groupId>com.flexive</groupId>
         <artifactId>flexive-plugin-globalconfig</artifactId>
         <version>${flexive.version}</version>
      </dependency>
      ...
   </dependencies>
</plugin>

Restart Jetty, and open (using the IP address of your host) the URI /flexive-backend-war/globalconfig/index.xhtml. You should see a screen similar to this one:

Global configuration login screen

Login using the default credentials of the global configuration. You get to the division configuration table, which lists for every division the pattern to be used for match request URLs and the assigned datasources (that must be defined in the application server).

Global configuration division table

Here we can see that the first division (the one that uses our H2 database) matches the following regular expression: (\d+\.\d+\.\d+\.\d+|localhost). Thus it will match either an IP address in the form of x.x.x.x (the first part) or the hostname localhost (the second part). To specify a “catch-all” pattern for the first division, click the “Edit” button of the row.

Edit a fleXive division entry
In the first column, enter “.*” (without the quotation marks!) as our new mapping. Click “Save changes”. The settings are not applied immediately, so we can still use the input box below the table for checking our pattern. Enter the desired URLs in “Find division for URL”, and verify that the first division is returned as a result. Finally, click “Store divisions in database” to have the settings applied to the running installation. You can then access the [fleXive] application using any hostname, and of course you could also add more divisions to serve other websites.

Of course the entire situation is somewhat unsatisfying, as it is very difficult for you as a fleXive user to figure out what’s going on. I think we need to address this issue in several ways:

  • Improve the documentation of the global configuration plugin. While it’s pretty easy to understand once you get there, it’s not apparent that the global configuration plugin even exists.
  • Perhaps use “.*” as the default mapping. If you want to use multiple divisions, you have to edit the division table anyway, and you’d use your own, hostname- or path-based naming scheme.
  • Add a (disabled) dependency for the global configuration plugin to the Maven archetype (already did this, but this affects only new projects). The Ant-based distribution by default already packages the plugin for your own projects.
  • Possibly figure out a way to configure the divisions without a web frontend. The problem I faced was that I couldn’t (and didn’t want to) launch Firefox on the virtual server (to be able to use localhost access), but I also couldn’t access the global configuration from the outside (you need a valid division to access the global configuration) – at least until I figured out that the IP would work. And by using an embedded, file-based H2 database, there’s no database server to connect to and modify the mappings manually.

April 8, 2009

Improved result preferences

Filed under: Development News,Using fleXive — Daniel Lichtenberger @ 14:07

2009_04_08-backend-resultpreferences-previewIn the [fleXive] backend administration, the user can define the columns of the search result view (click on the “result preferences” button in the search results page, or click on the gear icon in the toolbar). You can also use this in your own code by selecting the @* pseudo-column in FxSQL. Depending on the type of the search result items, the corresponding “result preferences” are used for determining the columns shown to the user.

The current snapshot versions (currently only available through the automated 3.1-SNAPSHOT Maven builds) include the following improvements:

  • Derived properties are listed under the first type that defined (or reused) them.
  • Group properties are available in the dropdown (as in “Address/…”)
  • If a derived type has no own result preferences defined for the current user, the settings from the parent type(s) are used first before using the main fallback (the “all types” setting)

These improvements make the backend search results a lot more usable when you’re working with type inheritance and groups.

March 31, 2009

JSFDays2009 examples

Filed under: Miscellaneous,Using fleXive — Tags: , , , , , , , , , , — Daniel Lichtenberger @ 14:26

In this post you can find the examples from the presentation “Challenges of JSF Web Site Development” held by Yours Truly at the  JSFDays2009 conference in Vienna, Austria. The slides will also be made available after the conference.

minicms

Download: minicms.zip (3.3M)
Prerequisites: Java 1.5+, Maven 2

Instructions:

  • Unpack into a local directory
  • cd minicms
  • mvn install
  • cd war
  • mvn jetty:run

Note for those that attended the session: the ResourceResolver in minicms is actually different from the one presented in the slides, it is based on temporary files that are updated by a servlet filter. The main reason is that when I wrote minicms I hadn’t yet discovered the more elegant approach using a URLStreamHandler as described in the slides. If time permits, I’ll update the minicms ResourceResolver. This would make the Filter obsolete and also make caching easier (and it’s probably faster, too).

JSF web site development examples

Download: jsfdays09-website-examples.zip (17.4M)
Prerequisites: Java 1.5+, Apache Ant

This package contains examples covering the following areas:

  • Accessibility: MyFaces Trinidad
  • Accessibility: Yahoo UI (progressive enhancement)
  • Dynamic templates (Facelets ResourceResolver)
  • RESTful URLs: PrettyFaces
  • RESTful URLs: PrettyUrlPhaseListener (Mojarra)
  • RESTful URLs: RestFaces
  • RESTful URLs: UrlRewriteFilter

Instructions:

  • Unpack into local directory
  • cd jsfDays09
  • ant

Deploy any of the generated WAR files to a web container like Tomcat.

March 23, 2009

Tutorial application stands alone

Filed under: Development News,Using fleXive,documentation — Tags: , , — Daniel Lichtenberger @ 09:14

I reworked parts of the tutorials section of our reference documentation.  The tutorials are now offered as stand-alone source downloads that can be compiled with a current fleXive distribution. The chapter on the hello-world application also explains how to build this application “from scratch”. It should be possible to complete the application just by copy-and-pasting the source listings and following the instructions.

The previous version focused on explaining the source code itself, but it assumed that you’d only want to compile the example inside the main fleXive source tree (this still works, of course, it’s just not very useful for anybody developing a new application). You may also want to check out the chapter on Writing [fleXive] applications, which also explains how to use Maven for your own projects.

December 20, 2008

Sun Business Breakfast [fleXive] slides available

Filed under: Announcements,Using fleXive — Tags: , , , , , , , — Markus Plesser @ 10:21

December 3rd was a great morning – I had the opportunity to give a short presentation of [fleXive] at the Sun Business Breakfast in Vienna/Austria. The feedback received was very valueable and I think we are on the right track with [fleXive] – there is a high demand for secure and multilingual content centric frameworks supporting agile development.

Slides are available for download here (german).

December 18, 2008

Run-once and startup scripts in the classpath

Filed under: Development News,Using fleXive — Tags: , , , , , — Daniel Lichtenberger @ 15:59

[fleXive] run-once and startup scripts provide an easy way for running customized code at application installation and server startup time inside the EJB container (documentation).

Today I checked in code that allows those scripts to be stored in any JAR file of your application (previously a build task had to index the files and store them under a unique path). This greatly simplifies the usage of those scripts in custom projects that do not use the distribution’s build infrastructure.

To execute run-once scripts from a JAR file, you have to:

  • add a file named flexive-application.properties in the JAR’s root folder, and
  • store the scripts under scripts/runonce and scripts/startup.

flexive-application.properties contains at least the application name and may provide additional information about your [fleXive] application:

# Application name
name=hello-flexive
displayName=Hello World Application

# The web application context root (if any)
contextRoot=war

For an example create a new project using the current version of our EAR archetype for Maven (instructions). In the “shared” module you find two scripts that will be executed at application startup time:

|– shared
|   |– pom.xml
|   `– src
|       `– main
|           |– java
|           `– resources
|               |– ApplicationMessages.properties
|               |– flexive-application.properties
|               `– scripts
|                   |– runonce
|                   |   `– 01-runonce.groovy
|                   `– startup
|                       `– 01-startup.groovy

The implementation is based on a JarInputStream, the JAR filename is extracted from the URL of the flexive-application.properties resource. A simplified version is shown below:
[Update 2009/04/30: fixed the JAR read method. Apparently JarInputStream#read delivers data in arbitrary sized chunks, which was not really clear to me from looking at the documentation alone]

final Enumeration<URL> fileUrls =
        Thread.currentThread()
        .getContextClassLoader()
        .getResources("flexive-application.properties");

while (fileUrls.hasMoreElements()) {

    final String path =
            fileUrls.nextElement().getPath()
            .replace("/flexive-application.properties", "");

    final JarInputStream jarStream =
            new JarInputStream(new URL(path).openStream());

    JarEntry entry;
    while ((entry = jarStream.getNextJarEntry()) != null) {

        if (!entry.isDirectory()
            && entry.getName().startsWith("scripts/startup/")) {

            int offset = 0;
            int readBytes;
            while ((readBytes = jarStream.read(buffer, offset, (int) entry.getSize() - offset)) > 0) {
                offset += readBytes;
            }
            if (offset == entry.getSize()) {
                final String code = new String(buffer, "UTF-8");
                // do something...
            }
        }
    }
    jarStream.close();
}

December 4, 2008

A [fleXive] server in 150 MB RAM

Filed under: Miscellaneous,Using fleXive — Tags: , , , , , , , , , , , , — Daniel Lichtenberger @ 16:12

63.56 - 21.88 = about 40Who said JavaEE servers have to be resource hogs? It turns out that the combination of Jetty, OpenEJB and H2 mentioned in the Maven integration article is actually relatively lightweight in terms of memory usage (for a JavaEE application, that is).

While it required some fixes to get the [fleXive] content cache under control, a [fleXive] application including the backend clocks in at about 40 megabytes heap usage (Linux, 32 bit). Looking at the system resources reveals slightly less encouraging numbers, but still more than manageable even on a shared host:

25587 11335 158440 247972 30.4 4.7 /usr/lib/jvm/java-6-sun/bin/java -Xmx64M -client -classpath /usr/share/maven2/boot/classworlds.jar -Dclassworlds.conf=/usr/share/maven2/bin/m2.conf -Dmaven.home=/usr/share/maven2 org.codehaus.classworlds.Launcher “jetty:run” “-Dflexive.cache.config=cacheconfig.xml”

This means about 150 MB of memory for the web and EJB containers, the (in-process) H2 database engine, all flexive libraries (about 30 MB in compressed JAR files), and the cluster-enabled JBoss Cache.

Since Maven and Jetty already consume about 70 MB of memory right after startup (I assume most of it is on Maven), it should be possible to reduce memory usage considerably by launching Jetty outside Maven (but then I’d lose the convenient dependency injection, so I left it at that for now).

Blog at WordPress.com.