samaxes

samaxes logo

Ramblings about Open Source, Java and other Web technologies by Samuel Santos

JBoss PojoCache configuration

Everyone knows that documentation is not one of JBoss strengths.
This article is meant to fill this gap. It describes and exemplifies how to configure JBoss PojoCache as a MBean service, using loadtime transformations with JBossAop framework, so you don’t need precompiled instrumentation.

Introduction

This section gives you an introduction about PojoCache and its advantages over TreeCache (a plain cache system).

PojoCache is an in-memomy, transactional, and replicated POJO (plain old Java object) cache system that allows users to operate on a POJO transparently without active user management of either replication or persistency aspects. PojoCache, a component of JBossCache (uses PojoCache class as an internal implementation, the old implementation TreeCacheAop has been deprecated.), is the first in the market to provide a POJO cache functionality. JBossCache by itself is a 100% Java based library that can be run either as a standalone program or inside an application server.

TreeCache limitations:

  • Users will have to manage the cache specifically; e.g., when an object is updated, a user will need a corresponding API call to update the cache content.
  • If the object size is huge, even a single field update would trigger the whole object serialization. Thus, it can be unnecessarily expensive.
  • The object structure can not have a graph relationship. That is, the object can not have sub-objects that are shared (multiple referenced) or referenced to itself (cyclic). Otherwise, the relationship will be broken upon serialization.

PojoCache advantages:

  • No need to implement Serializable interface for the POJOs.
  • Replication (or even persistency) is done on a per-field basis (as opposed to the whole object binary level).
  • The object relationship and identity are preserved automatically in a distributed, replicated environment. It enables transparent usage behavior and increases software performance.

Read the rest of this entry »

Internationalization of the File Upload Form Field

Internationalization, or i18n, is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language. Localization refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a “locale”).

Adapting application to various languages is for me, as a Java and HTML developer, more than a common task. Usually the solution involves a set of supported locales, which is very often different from the system locale and/or browser configuration. Majority of such cases are covered by the scenario when user chooses particular language settings and the only place where the locale setting can be stored is the HTTP Session.

Support for this behavior is now handled by majority of frameworks; nevertheless there is still one HTML element that you can’t effectively change - the file upload form field.
Read the rest of this entry »

Speed up your site by compressing and caching your content with .htaccess

.htaccess - gzip and cache your site for faster loading and bandwidth saving” is one of the most popular posts on samaxes.
It’s basically on how to compress and cache your site content with Apache and .htaccess file.

It works like a charm, but it’s not yet the perfect configuration for me.
I wanted something that I can use out-of-the-box without having to rely on external extension modules or tools.

If you are lucky enough to have Apache 2 with your hosting provider you can use the mod_deflate module that comes bundled with it.

In order to compress your text files with this Apache’s module you just have to add the following lines to your .htaccess file:

?View Code APACHE
<IfModule mod_deflate.c>
  <FilesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </FilesMatch>
</IfModule>

This will gzip all your *.css, *.js, *.html, *.html, *.xhtml, and *.php files.
Read the rest of this entry »

Fresh Layout for 2009

With the new year starting, I decided to try some changes here at samaxes.com.

First, I’ve changed the blog theme to a slightly modified Derek Punsalan’s Grid Focus.
Some of these modifications were mostly due to some complains about the size of the content column versus the sidebars columns on the previous theme. Since this is mainly a technical blog it makes it easily on the eye to have a wider content column.

Another visual change was the code syntax highlighting plugin. I was using the SyntaxHighlighter Plus and now I’m using WP-CodeBox.
SyntaxHighlighter Plus served me well in the past, but it has some disadvantages, such as:

  • Escapes the code special characters, making it harder to edit code (also has a bug when escaping ‘&’ ampersand characters);
  • Require that a lot of JavaScript files are sent to the client in order to style the code.

Although I’m using browser caching, 70-80% of this blog visitors are new visitors, so the cache won’t help them. This means that I should try to minimize the number of HTTP requests as much as I can.
WP-CodeBox is based on the GeSHi syntax highlighter. All the parsing is executed on the server side and it supports a lot more languages than the SyntaxHighlighter.
Read the rest of this entry »

Stripes and jQuery Autocomplete

I really enjoy jQuery. But finding the right UI widget can be a daunting task.
Autocomplete is one of those widgets.

I decided to share an asynchronous example on how to use the jQuery Autocomplete plugin with Stripes.

Here’s an example output:
Stripes and jQuery Autocomplete example
Read the rest of this entry »

JBoss AS 5.0 is out!

JBoss announced the GA release of JBoss AS 5.0.

JBoss 5 is the next generation of the JBoss Application Server build on top of the new JBoss Microcontainer. The JBoss Microcontainer is a lightweight container for managing POJOs, their deployment, configuration and lifecycle. It is a standalone project that replaces the famous JBoss JMX Microkernel of the 3.x and 4.x JBoss series. The Microcontainer integrates nicely with the JBoss framework for Aspect Oriented Programming, JBoss AOP. Support for JMX in JBoss 5 remains strong and MBean services written against the old Microkernel are expected to work.

JBoss5 is designed around the advanced concept of a Virtual Deployment Framework (VDF), that takes the aspect oriented design of many of the earlier JBoss containers and applies it to the deployment layer. Aspectized Deployers operate in a chain over a Virtual File System (VFS), analyze deployments and produce metadata to be used by the JBoss Microcontainer, which in turn instantiates and wires together the various pieces of a deployment, controlling their lifecycle and dependencies.

See the full release notes and downloads page.

And good luck to get your J2EE applications working with this new version.

Stripes and jQuery: AJAX forms and HTTP Session Validation

This example was greatly inspired by the Stripes and jQuery AJAX Forms article from Freddy Daoud, but with some nice improvements

Last week I was working on a new Stripes/AJAX example. It involves having a table listing entities, being the last row of the table a form for adding new ones.
The form gets submitted via AJAX, using jQuery, and the response is validated in order to check if the HTTP session is still valid.

If everything is OK, the list is refreshed and a success message appears. On the other hand, if validation errors occur, the list is refreshed and an error message appears.
Also, if the user’s session has expired on the server, an alert is shown to inform the user that his session is invalid, and the page is reloaded so the user can login once more.
Read the rest of this entry »

The Semantic Web and RDFa

There is a lot of momentum around Semantic Web and RDFa.
This may be caused by the big milestone reached for RDFa, a Candidate Recommendation of RDFa in XHTML: Syntax and Processing.

Recently, several discussion threads have been started on the WHATWG mailing list around the effort of integrating RDFa into the HTML5 specification as XHTML1.1 and XHTML2 that will have it integrated.

While I was pretty aware of the Microformats activity, I can’t say the same about RDFa. But Manu Sporny makes it a lot easier. In fact, this is by far the most comprehensive explanation of RDFa that I have ever seen.
Read the rest of this entry »

samaxesJS JavaScript Controls

samaxesJS is a set of utilities and controls, written in JavaScript, for building rich interactive web applications.

The first extension is a dynamic Table of Contents script.

The TOC control dynamically builds a table of contents from the headings in a document and prepends legal-style section numbers to each of the headings:

  • adds numeration in front of all headings,
  • generates an HTML table of contents,
  • degrades gracefully if JavaScript is not available/enabled.

More information available in the project home page at Google Code Hosting.

BIRT/Stripes example

A long time has passed since my previous BIRT examples Deploying BIRT Report Engine API with Jakarta Struts and Deploying BIRT Report Engine API with Stripes.
Although they have received a lot of attention and downloads, the examples were really basic and are now outdated.

Since I had to use BIRT in my last projects I decided to update my BIRT/Stripes example.
This example doesn’t depend on the Tribix project anymore since BIRT supports HTML/Paginated HTML, PDF, Excel, Word, PowerPoint, and PostScript outputs (images/charts are not embedded in Excel output).

BIRT WebReport Example

I’ve tried to follow some good practices that I think are important to use in a production application:

  • There is a significant cost associated with creating an engine instance, due primarily to the cost of loading extensions. Therefore, each application should create just one ReportEngine instance and use it to run multiple reports. In this example the engine is started in the context listener and the same instance is always used.
  • All texts in the report should be loaded from the resources so the application can be fully localizable and fully internationalized.
  • You should use a JDBC data set to preview your report with BIRT designer but you must swap the data set in runtime to use data from your business logic.
  • You should use predefined styles instead of custom styles as much as you can.
  • Not a good practice but often a requirement, hide the master page when generating a HTML report, and change the visibility of elements so they are visible only to specified outputs.

For this example BIRT Runtime Engine 2.2.2 2.3.1, and Stripes Framework 1.5 were used.
Read the rest of this entry »

Sponsors