Integrated Open Souce Technology Solutions

JSF - Rendering Images stored in Database

November 3rd, 2008 Posted in JAVA, JSF, Spring | 2 Comments »

by Michael Root

This article shows how to render images from data stored in the database to a JSF view.

This solution was created for the following environment, but will work in other configurations.

  • JavaServer Faces (JSF) 1.2
  • Richfaces 3.2.2.GA
  • SpringFramework 2.5.5
  • Spring Webflow 2.0.3
  • Hibernate 3.2.6.ga

Instead of storing the image data in the database one could store the images to an external directory. I have used external image directories in several projects but I find scalability and image management is more difficult. This post will describe how to perform image management using the database to store the images.

Read the rest of this entry »

Developing a Lightweight DND Portal

February 13th, 2008 Posted in JAVA, Web | 4 Comments »

Many web sites have this drag-n-drop portal management feature like the home page for iGoogle. Google created their Google Gadgets that are simple HTML and JavaScript mini-applications served in iFrames that can be embedded in webpages and other apps.

Although there are several technologies available that one could use to develop this functionality within their web application, this article will focus on requirements, technology alternatives and in latter posts I will develop this technology with our chose technology alternative.

Requirements:

  1. Drag - and - Drop AJAX functionality which allows customization for logged on users.
  2. There will be a fixed number of components that can be displayed.
  3. Each component has its own display and controller for handling requests. All components are developed to a standard interface.
  4. Each component has a wrapper that contains a title bar and menu.

Technology Alternatives:

  1. JSR 168 / 268 Solution
  2. Utilize YUI Drag & Drop Component
  3. Utilize Google Web Toolkit (GWT) with DND extensions by Allen Sauer

The JSR 168 defines a Java Portlet Specification that defines a contract between the portlet container and portlets and provides a convenient programming model for portlet developers. There are many commercial and open source portal servers:

Commercial Portal Servers:

  • IBM WEbSphere
  • Sun Java System Portal Server
  • BEA Weblogic
  • Oracle iAS
  • Liferay
  • Vignette
  • SAP
  • TIBCO
  • uPortal
  • OpenPortal

Open Source Portal Servers:

  • JBoss Enterprise Portal Platform
  • Apache Pluto
  • JetSpeed Portal
  • eXo Platform Portal

The JSR 168 standard is an overkill to our solution and require s a full blown portal server which is not what we are looking for.

YUI has some amazing components and I use these on several web sites. They have a Drag & Drop component that could be used but from my experience this control would only give me a partial solution which then would require modification of the YUI javascript. I don’t mind tweaking 3rd party components but this would require major modification to achieve our requirements.

From my initial research I believe the only alternative would be to develop a component using GWT. Future articles will describe the development of this component that we will call PortLight.

Maven 2 Life Cycle

December 12th, 2006 Posted in JAVA | 9 Comments »

This post contains information helpful in using maven 2.0. Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

Maven’s Default Build Life Cycle

validate Validate the project is correct and all necessary information is available.
initialize Initialize the build process.
generate-sources Generate any source code for inclusion in compilation.
process-sources Process the source code, for example to filter any values.
generate-resources Generate resources for inclusion in the package.
process-resources Copy and process the resources into the destination directory, ready for packaging.
compile Compile the source code of the project.
process-classes Post-process the generated files from compilation, for example to do byte code enhancement on Java classes.
generate-test-sources Create resources for testing.
process-test-sources Process the test source code, for example to filter any values.
generate-test-resources Create resources for testing.
process-test-resources Copy and process the resources into the test destination directory.
test-compile Compile the test source code into the test destination directory test Run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
test Run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
package Take the compiled code and package it in its distributable format, such as a JAR.
pre-integration-test Perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test Process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test Perform actions required after integration tests have been executed. This may including cleaning up the environment.
verify Run any checks to verify the package is valid and meets quality criteria.
install Install the package into the local repository, for use as a dependency in other projects locally.
deploy Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.


AOP Definitions

October 7th, 2006 Posted in Uncategorized | 9 Comments »

Aspect-Oriented Programming (AOP) complements OOP by providing another way of thinking about program structure. While OO decomposes applications into a hierarchy of objects, AOP decomposes programs into aspects or concerns. This enables modularization of concerns such as transaction management that would otherwise cut across multiple objects. (Such concerns are often termed crosscutting concerns.)

AOP Concepts

There are two distinct types of AOP:

  • static: crosscutting logic is applied to your code at compile time, and you cannot change it without modifying the code and recompiling. Aspectj provides this type of implementation.
  • dynamic: With dynamic AOP, like spring AOP, crosscutting logic is applied dynamically, at runtime.

These types of AOP are complementary and, when used together, they form a powerful combination that you can use in your applications.In defining the copcepts of AOP the definitions that I use will be SpringFramwork centric.

  • Aspect: A modularization of a concern for which the implementation might otherwise cut across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. Aspects are implemented using Spring as Advisors or interceptors.
  • Joinpoint: Point during the execution of a program, such as a method invocation or a particular exception being thrown. In Spring AOP, a joinpoint is always method invocation. Spring does not use the term joinpoint prominently; joinpoint information is accessible through methods on the MethodInvocation argument passed to interceptors, and is evaluated by implementations of the org.springframework.aop.Pointcut interface.
  • Advice: Action taken by the AOP framework at a particular joinpoint. Different types of advice include “around,” “before” and “throws” advice. Advice types are discussed below. Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors “around” the joinpoint.
  • Pointcuts: Are predicates determining which joinpoints a piece of advice should apply to. It’s more intuitive — although not entirely accurate — to think of a pointcut as a set of jointponts. Pointcuts identify where advice should apply. Thye majic of AOP lies more in the specification of where action should be taken (pointcut) than what action to apply (advice).

Spring Advice Types

  • Around Advice: Advice that surrounds a joinpoint such as a method invocation. This is the most powerful kind of advice. Around advices will perform custom behavior before and after the method invocation. They are responsible for choosing whether to proceed to the joinpoint or to shortcut executing by returning their own return value or throwing an exception.
  • Before Advice: Advice that executes before a joinpoint, but which does not have the ability to prevent execution flow proceeding to the joinpoint (unless it throws an exception).
  • After Returning Advice: is invoked when a method returns successfully, without throwing an exception. As with before advice, the return type is void; after returning advices are not intended to change the return value.
  • Throws Advice: Advice to be executed if a method throws an exception. Spring provides strongly typed throws advice, so you can write code that catches the exception (and subclasses) you’re interested in, without needing to cast from Throwable or Exception.

DarwinPorts to Install Apache2 and PHP5

July 8th, 2006 Posted in MAC OSX | 1 Comment »

This post discusses the installation of Apache 2.2.2and PHP 5.1.4 on Mac OS X 10.4.7. Initially I tried to build the open source applications and install but after a few attempts I decided to use DarwinPorts to automatically build and install these two applications.This weekend I decided to upgrade my apache and php versions on my MacBook to the latest version. I searched the web for any existing articles regarding this upgrade and came across the following article:

Building and Installing Apache 2.2.2 and PHP 5.1.4 on Mac OS X 10.4.6

I had no problem building and installing Apache 2.2.2, at least after I installed XTools from the OS X development disk. During the make of PHP there was an issue with dependency. After doing more research others having the same problem had to buid php with mySQL 4.x instead of 5.x. I decided to utilize DarwinPorts to build and install the open source software.

I downloaded and installed DarwinPorts-1.2.1. After DarwinPorts was install I peformed the following steps to install apache2:

  1. Build and install Apache2.
    sudo port install apache2
  2. Create a default conf file for apache.
    cd /opt/local/apache2/conf
    sudo cp httpd.conf.sample httpd.conf
  3. Start apache2 on startup.
    sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.apache2.plist

When apache2 is installed the default DocumentRoot is /opt/local/apache2/htdocs/. I modified the DocumentRoot to point back to the default OS X location of /Library/WebServer/Documents/.

I would refer to the apache2 documentation to configure the httpd.conf according to your requirements.

To start apache2 execute the followng command:

sudo /opt/local/apache2/bin/apachectl -k start

The following steps were followed to install php5.

  1. Install wget which is required by php5.
    sudo port install wget
  2. Build and install php5.
    sudo port install php5 +apache2 +mysql4
  3. Register PHP with Apache.
    cd /opt/local/apache2/modules
    /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
  4. Create php.ini file
    cp /opt/local/etc/php.ini-dist to  /opt/local/etc/php.ini

One other article was useful in installing apache2 using DarwinPorts: DarwinPorts:MAMP
I hope this post helps in setting up apache2 and php5.

JAXB

June 6th, 2006 Posted in JAVA, XML | 4 Comments »

The JavaTM Architecture for XML Binding (JAXB) provides an API and tools that automate the mapping between XML documents and Java objects.

The JAXB framework enables developers to perform the following operations:

  1. Unmarshal XML content into a Java representation
  2. Access and update the Java representation
  3. Marshal the Java representation of the XML content into XML content

JAXB gives Java developers an efficient and standard way of mapping between XML and Java code. Java developers using JAXB are more productive because they can write less code themselves and do not have to be experts in XML. JAXB makes it easier for developers to extend their applications with XML and Web Services technologies.

Extending Acegi Security

April 9th, 2006 Posted in JAVA, Web | 5 Comments »

This article shows how to add several security enhancements to a web application that is utilizing Acegi Security. These security enhancements include:

  • How to add funcitonality to force the user to change thier password on thier first login
  • After a selected number of failed login attempts the system will temporarily lock the user account for a pre-determined amount of time
  • Not allow the user to re-use a pe-selected number of previous passwords that are stored in a password history.

Read the rest of this entry »