All posts by Wim Bervoets

I'm a senior Java developer with 13 years of experience in Java. My current interests include web development, internet marketing and enterprise Java frameworks (Spring, ...) Agile development and associated tooling is also a topic of interest.

Weblets 1.1 now officially released

Weblets 1.1 has been released at weblets.dev.java.net

Weblets is a Java servlet based framework that provides an easy way of loading resources (Javascript, CSS, images, …) directly out of JAR files. For an overview of what Weblets can do for you, check our Weblets overview.

Below we’ll highlight some of the new features in Weblets v1.1:

  • Weblets 1.1 provides a stable api to build your own Weblets upon
  • Asynchronous In-server reporting of url usage is possible. (eg. for traffic analysis). In-server means that the logging is done in the same JVM server process. Asynchronous because reports that are triggered and executed can run for a longer period of time.
  • General reporting API for in server reporting instances
  • Configurable cache timeouts for better browser cache control

Weblets 1.0 only had the possibility to host resources within your classpath. It was only possible to host Weblets related resources within a jar or within your WEB-INF/classes directory!

Weblets 1.1 now enhances this with a very common usecase. expanded application hosted resources . This means you can put any resource hosted within your local web application under Weblet control. For instance if your application is hosted under /myapplication and your resource under /myapplication/images/myimage.png it until now was not possible to put this resource under Weblets control.

  • Server Mime Type overrides: some servers don’t set default mime types. (eg Weblogic 8.1). If you’re not able to edit them in the web.xml, the Weblets configuration provides another possibility.
  • Resource Whitelists: a mechanism to allow the serving of resources only for certain filetypes given in a resource whitelist (eg. only allow serving of png files)
  • Weblets 1.1 corrects Maven2.0 transitive dependencies (Maven should now pickup all needed dependencies of Weblets)

See http://weblets.dev.java.net/doc_11/longdoc/whatsnew.html for a more detailed description of the new features!

How to install Flex3 builder in RAD7

The IBM Rational Application Developer 7 (RAD 7) IDE, based on Eclipse 3.3 doesn’t work out-of-the-box with Flex Builder 3. This is due to the IBM Java SDK using a different Xerces version then the one Flex Builder needs.

You’ll likely receive the following error:

java.lang.IllegalAccessError:
org.apache.xerces.util.XMLAttributesImpl$Attribute

Here is an easy guide to get you up and running quickly:

  1. Install RAD7
  2. Install Flex Builder 3
  3. At the end of the install, the installer will complain about not being able to automatically setup an Extension Location. Be sure to execute the given instructions manually
  4. Quit RAD7 if running
  5. Edit the eclipse.ini file in c:\Program Files\IBM\SDP70 (directory where you installed RAD7)
  6. Add the following line on a new line at the end of the file:
-Xbootclasspath/a:c:\progra~1\adobe\flexbu~1\sdks\3.0.0\lib\xercesImpl.jar

Restart RAD7 and open the Flex Development perspective to start developing the next-gen Flex app :-)

JSF 1.1 performance fixes

JSF 1.1_02 is the latest officially released reference implementation of JSF1.1 by Sun. It’s still widely used by companies who have not yet migrated to Java5 (as it is not always easy to migrate all applications to a new target platform).

While looking through the FishEye source code view, I came accross some interesting unreleased performance fixes:

https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=125

I have been investigating the size of views as they are stuffed in the session for scalability reasons, and have found a couple of issues with the RI code:

1. The biggest problem I found was in StateManagerImpl.The function removeTransientChildrenAndFacets causes the lazy init of the child list, facet map, and client id of every component in the tree! Very, very sloppy.

Fixing this literally halved the size of the view in memory.

https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=223

StateManager for stateSaving Server has a synchronization lock on (this), blocking all threads. I thought this was fixed a while back.

https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=222

Currently the checkIdUniqueness forces creation of child and facet arrays onevery component, the suggestion is to switch over togetFacetsAndChildren() which is now optimized within UIComponentBase to avoid unecessary eden creation in memory.

Has anybody already used these JSF 1.1_03 rolling fixes and noticed memory reduction? If so please let us know in the comments!

Fix your Richfaces AJAX (performance) problems

Richfaces supports AJAX functionality in a lot of it components. However a servlet filter is needed for correct functioning of partial page refreshes.

In this post we’ll show you how to add this filter and at the same time optimize Richfaces performance.

The following Richfaces filter is defined in the web.xml:

<filter>
        <filter-name>richfaces</filter-name>
        <display-name>RichFaces Filter</display-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
        <init-param>
			<param-name>forceparser</param-name>
			<param-value>false</param-value>
		</init-param>
    </filter>

What this filter does, is to ‘tidy’ all HTML HTTP Responses so that they are valid XHTML (thus XML compliant). This is needed as dynamic DOM updates in the browser need correct XML.

If you don’t define this filter, it is possible that you’ll not see your AJAX update being rendered on the screen, although you’ll see the html response coming back in eg. Firebug

Of course, parsing HTML incurs a performance overhead.
This can be minimized by setting the forceparser setting to false. In that case only AJAX responses will be ‘tidied’. In the other case all JSF responses are ‘tidied’. That is because the filter is mapped on the Faces servlet:

<filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

Richfaces has a few parsers onboard. The default one is based on Tidy, but it is quite slow. The Neko parser is faster and can be used by setting the following context-param’s:
<context-param>
        <param-name>org.ajax4jsf.xmlparser.ORDER</param-name>
        <param-value>NEKO</param-value>
    </context-param>

    <context-param>
        <param-name>org.ajax4jsf.xmlparser.NEKO</param-name>
        <param-value>.*\..*</param-value>
    </context-param>

Here we say we only use the NEKO filter and it should be applied to all URLs (.)
There is more configuration possible, like using NONE for some pages that don’t need HTML correction to further speedup things if needed.

Example can be found at: http://jboss.com/index.html?module=bb&op=viewtopic&t=116231

Showcase: Google Analytics AIR beta 3 (for AIR 1.0)

Adobe Flex 3 and AIR 1.0 certainly have generated quite a buzz in the Java world in the last few months. Not in the least by the very nice Parleys.com site which is hosting all the Javapolis talks and videos.

Adobe AIR is a technology which lets you download and run webapps seamlessly on your desktop. (similar to Google Gears).

Another well known Google app, Google Analytics has now been ported to AIR by Nicolas Lierman. Analytics features all sorts of interesting statistics about your site visitors, allowing you to make informed choices on how to improve your site (eg. which pages are popular, which are not, which pages have high exit points, …)

The AIR version (with really nice Flex chart animations), can be download at AboutNico

How to redirect to an external link with Spring Webflow?

Below you can find an easy way to redirect to an external site via a Spring Webflow view state. What happens here is the following:

  1. a JSF command link backing bean action method returns the String link1
  2. Spring Webflow will redirect you to the viewstate OpenLink1
  3. The OpenLink1 view-state uses the externalRedirect functionality with a backingbean/dataholder stored link value

<view-state id=”myViewState” view=”/viewstates/mypage.jspx”>
<transition to=”OpenLink1″ on=”link1″/>
</view-state>

<view-state id=”OpenLink1″ view=”externalRedirect:${conversationScope.dataHolder.link1}”/>

Javapolis becomes Javoxx

A new name, a new logo but the same concept: Javapolis became Javoxx this week as javoxx.com was launched.

We still have to wait a bit about the exact reasoning behind the name switch, but the goal of the conference is clear: be the java community conference. (as it’s organized by the Belgian Java User Group (BeJUG).

Javoxx will take place from December 8th till 12th in Antwerp, Belgium.

Setup Weblets 1.0 for JSF on Weblogic 8.1

This week I’ve tried to upgrade from Weblets 0.4 to 1.0 while using the following technologies: JSF1.1, JDK1.4 and Weblogic 8.1.

Here are some of my experiences:

As noted in the documentation on https://weblets.dev.java.net/doc/longdoc/setup.html, the web.xml needs the following additions:

       <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

This URL pattern will be used only by Weblets. The generated URLs whenever you call weblet:url / weblet:resource via EL, Javascript, CSS or Java will begin with /faces.
This in fact makes sure that the WebletsPhaseListener knows when to process a resource or not by looking at the url

For Weblogic 8.1 it also necessary to add the following listener to your web.xml:

 

 <listener>
<listener-class>net.java.dev.weblets.WebletsContextListener</listener-class>
</listener>

I couldn’t get Weblets to work without it.

Last but not least you should add mime-mappings to your web.xml for all the different types of static resources you want Weblets to serve:

<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/x-javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>

<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>

<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpg</mime-type>
</mime-mapping>

If you don’t do this, then a NullPointerException is thrown internally by Weblets and gives problems serving the static resources.
I don’t know about other servers, but on Weblogic doing a servletContext.getMimeType will return null when it was not defined in the web.xml

In fact, Weblets 1.0 also supports defining a <mime-mapping> in the weblets-config.xml. But adding the mime types only there didn’t work as in the Weblets source code there are few places where servletContext.getMimeType is called directly thus ignores any configuration done in the weblets-config.xml. For the next version of Weblets it would be interesting to fix this behaviour and document eg. that mime-mappings in weblets-config.xml take precedence. And if not defined there, Weblets will try to look for mime-mappings in the web.xml via the servlet context.

Weblets 1.0 has been released

Weblets 1.0 has been released at weblets.dev.java.net

Weblets is a Java servlet based framework that provides an easy way of loading resources (Javascript, CSS, images, …) directly out of JAR files.

For us the following features were the reason to start using it:

  1. Weblets has a full frontend api for neutral resource handling. This includes
    • a JSP API
    • JSF facelet integration
    • Using weblets from CSS and Javascript files is also possible.
  2. Weblets will automatically add Expires, If-Modified-Since headers to your HTTP responses. This enhances performance and is a way to implement Rule 3: Add an Expires Header from the Yahoo Performance team (http://developer.yahoo.com/performance/rules.html#expires)
  3. Weblets can automatically version your static resources. (eg. by adding a version id into the generated URL). Doing this accomplishes two things:
    • when a new version of eg. a CSS is in your jar, the URL location where it is served from will change (version id will be different). So there will be no browser issues of people still using the old version as the new URL will not yet be in the cache of the browser.
    • the first point allows you to define much more far future Expires headers; thus the chance that browser will use a cached version will be far higher, enhancing front end performance.

In the next post we will look at using Weblets 1.0 in a Weblogic 8.1 environment.

JSF 1.1 and 1.2 Support in future versions of Richfaces

Richfaces, one of the most fully featured JSF frameworks from JBoss has posted their roadmap for the future versions on their forum.

The Richfaces 3.1.x branch (the current general access production version) is now in maintenance mode and will not receive any new functionality anymore. Only bugfixes that do not require a long QA testing period will still be fixed on this branch.

This branch is also the latest one that supports JSF1.1 and Java 1.4! So it’s really getting time to upgrade to Java 5 or 6!

Richfaces 3.2.0, which supports JSF1.2 and Java 1.5 (or higher) will be released at the end of March. Richfaces 3.1.5 will be released around three weeks after the Richfaces 3.2.0 release. (e.g. the second half of April, 2008.)

More info at http://jboss.com/index.html?module=bb&op=viewtopic&t=129518