Monday, March 3, 2008

Apache Based SOA Stack

Recently I'm thinking about building a completely Apache based SOA stack by using many Apache first level projects or incubator projects. Here is a simple idea:

  • Database:
    • Derby
  • Web Server
    • Tomcat
  • Application Servers:
    • Geronimo
  • Messaging Systems:
    • ActiveMQ
  • ESB:
    • Apache CFX
    • Apache Synapse
    • Apache ServiceMix
    • Apache Mule
  • Orchestration Engine
    • Ode
  • UDDI/ebXML
    • Apache jUDDI
  • Directory Server
    • ApacheDS

Wednesday, December 19, 2007

OpenID 2.0 final released

OpenID

check these

The Sound of Crickets Chirping » Blog Archive » OpenID != SSO

The Sound of Crickets Chirping » Blog Archive » OpenID != SSO: "OpenID != SSO"

Well, I understood what the author wants to say, but from an user point of view, they are the same.

Friday, October 26, 2007

Dev Thoughts » Blog Archive » JMX meets Log4J

Dev Thoughts » Blog Archive » JMX meets Log4J

Today, after repeating this routine a few times, for the first time I told myself “There must be a better way…”. It didn’t take me long to feature out that spring’s jmx support and jdk 5 practically hand me the solution to this problem on a silver plate - Just create a simple management bean that controls the log levels for categories, export this bean as an MBean using spring superb JMX’s support, and use jdk5 jconsole application to manage the logging levels. Here’s a quick recipe:

1. Create the management bean:

public class Log4jMBean {

public void activateInfo(String category) {
LogManager.getLogger(category).setLevel(Level.INFO);
}

public void activateDebug(String category) {
LogManager.getLogger(category).setLevel(Level.DEBUG);
}

public void activateWarn(String category) {
LogManager.getLogger(category).setLevel(Level.WARN);
}

public void activateError(String category) {
LogManager.getLogger(category).setLevel(Level.ERROR);
}

public void activateFatal(String category) {
LogManager.getLogger(category).setLevel(Level.FATAL);
}
}

2. Export the bean in the application context.

3. Run your application with the following system property -Dcom.sun.management.jmxremote

4. Run jconsole tool (found at JAVA_HOME/bin)

5. Look for the exported MBean (”logging” in our case)

6. Change the log level of categories just by invoking the management methods.

Done!

After googling a bit, I found out that loads of people already thought about this solution (hell… there’s even an MBean class in the jdk that does the same for jdk’s logging mechanism). Unfortunately, I only gave it a thought today - if I had done so long time ago it would have probably saved me quite a lot of time… So if it’s new to you aswell, stop wasting your time and add it to your project today.

Note: This can be quite useful at production phase as well, but keep in mind that a more secured schema should be applied - possibly using jdk’s jmx security support (for more information, see the resources below).

Some resources:
Monitoring and Management Using JMX
Spring JMX support

Sunday, October 14, 2007

SEO Title Tag: A WordPress Plugin for SEO (Search Engine Optimization)

SEO Title Tag: A WordPress Plugin for SEO (Search Engine Optimization)

Features include:

  • Allows you to override a page’s or a post’s title tag with a custom one.
  • New for v2.0 A Title Tag input box in the Edit Post and Write Post forms. (Previously in version 1.0 you had to use the Custom Field box.)
  • New for v2.0 Mass editing of title tags for all posts, static pages, category pages, tag pages, tag conjunction pages, archive by month pages, — indeed, any URL — all in one go.
  • Define a custom title tag for your home page (or, more accurately, your Posts page, if you have chosen a static Front Page set under Options -> Reading), through the Options -> SEO Title Tag page in the WordPress admin.
  • New for v2.0 Define the title tag of 404 error pages, also through Options -> SEO Title Tag.
  • New for v2.0 Handles internal search result pages too.
  • For users of the UltimateTagWarrior plugin (which should be everybody!), incorporates the tag name into the title tag on “tag pages” (sorry for the confusing use of “tag” in two contexts here — as in tagging and HTML title tags).
  • New for v2.0 (When used with Ultimate Tag Warrior) Customize the title tags on tag pages, and on tag conjunction pages too (e.g. http://www.netconcepts.com/tag/seo+articles). The latter is done through Manage -> Title Tags -> URLs; see this screenshot for an example.
  • New for v2.0 Title tags of category pages can optionally be set to the category description. If you use a Meta Tag plugin like Add Meta Tags, then you should not use this feature and instead let the Meta Tag plugin use the category description for the meta description on category pages.
  • If you choose to keep the blog name in your title tags (not recommended!), the order of the blog name and the title are automatically reversed, giving more keyword prominence to the title instead of the blog name. Note there is also an option to replace your blog name with a shorter blog nickname.

And best of all, the plugin is FREE!

Suitably convinced? Then Download the plugin!

Friday, October 12, 2007

Enterprise Java Community: Introduction to the Spring Framework

Enterprise Java Community: Introduction to the Spring Framework

This is a basic introduction of Spring Framework.

The author thinks the Spring Framework is unique as:
Spring is unique, for several reasons:
  • It addresses important areas that many other popular frameworks don't.
  • Spring is both comprehensive and modular.
  • Spring is designed from the ground up to help you write code that's easy to test.
  • Spring is an increasingly important integration technology
I fully agree with it. The loose couple and tight couple inside way makes Spring eases to be used in any kind of applications.

Architectural benefits of Spring

Before we get down to specifics, let's look at some of the benefits Spring can bring to a project:

  • Spring can effectively organize your middle tier objects, whether or not you choose to use EJB. Spring takes care of plumbing that would be left up to you if you use only Struts or other frameworks geared to particular J2EE APIs. And while it is perhaps most valuable in the middle tier, Spring's configuration management services can be used in any architectural layer, in whatever runtime environment.
  • Spring can eliminate the proliferation of Singletons seen on many projects.
  • Spring can eliminate the need to use a variety of custom properties file formats, by handling configuration in a consistent way throughout applications and projects. Ever wondered what magic property keys or system properties a particular class looks for, and had to read the Javadoc or even source code? With Spring you simply look at the class's JavaBean properties or constructor arguments. The use of Inversion of Control and Dependency Injection (discussed below) helps achieve this simplification.
  • Spring can facilitate good programming practice by reducing the cost of programming to interfaces, rather than classes, almost to zero.
  • Spring is designed so that applications built with it depend on as few of its APIs as possible. Most business objects in Spring applications have no dependency on Spring.
  • Applications built using Spring are very easy to unit test.
  • Spring can make the use of EJB an implementation choice, rather than the determinant of application architecture. You can choose to implement business interfaces as POJOs or local EJBs without affecting calling code.
  • Spring helps you solve many problems without using EJB. Spring can provide an alternative to EJB that's appropriate for many applications. For example, Spring can use AOP to deliver declarative transaction management without using an EJB container; even without a JTA implementation, if you only need to work with a single database.
  • Spring provides a consistent framework for data access, whether using JDBC or an O/R mapping product such as TopLink, Hibernate or a JDO implementation.
  • Spring provides a consistent, simple programming model in many areas, making it an ideal architectural "glue." You can see this consistency in the Spring approach to JDBC, JMS, JavaMail, JNDI and many other important APIs.

Spring is essentially a technology dedicated to enabling you to build applications using POJOs. This desirable goal requires a sophisticated framework, which conceals much complexity from the developer.


What does Spring do?

Mission statement
POJO-based programming model
Spring is portable between application servers.
Inversion of control container
The core of Spring is the org.springframework.beans package, designed for working with JavaBeans.
The most commonly used BeanFactory definitions are:
  • XmlBeanFactory. This parses a simple, intuitive XML structure defining the classes and properties of named objects. We provide a DTD to make authoring easier.
  • DefaultListableBeanFactory: This provides the ability to parse bean definitions in properties files, and create BeanFactories programmatically.
The concept behind Inversion of Control is often expressed in the Hollywood Principle: "Don't call me, I'll call you." IoC moves the responsibility for making things happen into the framework, and away from application code. Whereas your code calls a traditional class library, an IoC framework calls your code. Lifecycle callbacks in many APIs, such as the setSessionContext() method for session EJBs, demonstrate this approach.

Spring provides sophisticated support for both Setter Injection (injection via JavaBean setters); and Constructor Injection (injection via constructor arguments), and even allows you to mix the two when configuring the one object.

JDBC abstraction and data access exception hierarchy

Spring addresses these problems in two ways:

  • By providing APIs that move tedious and error-prone exception handling out of application code into the framework. The framework takes care of all exception handling; application code can concentrate on issuing the appropriate SQL and extracting results.
  • By providing a meaningful exception hierarchy for your application code to work with in place of SQLException.
This is really cute feature that I like. It frees most of 3 tiers application developers paint.



Spring JDBC can help you in several ways:

  • You'll never need to write a finally block again to use JDBC
  • Connection leaks will be a thing of the past
  • You'll need to write less code overall, and that code will be clearly focused on the necessary SQL
  • You'll never need to dig through your RDBMS documentation to work out what obscure error code it returns for a bad column name. Your application won't be dependent on RDBMS-specific error handling code.
  • Whatever persistence technology use, you'll find it easy to implement the DAO pattern without business logic depending on any particular data access API.
  • You'll benefit from improved portability (compared to raw JDBC) in advanced areas such as BLOB handling and invoking stored procedures that return result sets.
O/R mapping integration

Of course often you want to use O/R mapping, rather than use relational data access. Your overall application framework must support this also. Thus Spring integrates out of the box with Hibernate (versions 2 and 3), JDO (versions 1 and 2), TopLink and other ORM products. Its data access architecture allows it to integrate with any underlying data access technology. Spring and Hibernate are a particularly popular combination.

Why would you use an ORM product plus Spring, instead of the ORM product directly? Spring adds significant value in the following areas:

  • Session management.
  • Resource management.
  • Integrated transaction management.
  • Exception wrapping, as described above.
  • To avoid vendor lock-in.
  • Ease of testing.

Above all, Spring facilitates a mix-and-match approach to data access. Spring enables a consistent architecture, and transaction strategy, even if you mix and match persistence approaches, even without using JTA.

AOP

The first goal of Spring's AOP support is to provide J2EE services to POJOs. Spring AOP is portable between application servers, so there's no risk of vendor lock in.

Spring AOP supports method interception. Key AOP concepts supported include:

  • Interception: Custom behaviour can be inserted before or after method invocations against any interface or class. This is similar to "around advice" in AspectJ terminology.
  • Introduction: Specifying that an advice should cause an object to implement additional interfaces. This can amount to mixin inheritance.
  • Static and dynamic pointcuts: Specifying the points in program execution at which interception should take place. Static pointcuts concern method signatures; dynamic pointcuts may also consider method arguments at the point where they are evaluated. Pointcuts are defined separately from interceptors, enabling a standard interceptor to be applied in different applications and code contexts.

Spring supports both stateful (one instance per advised object) and stateless interceptors (one instance for all advice).

Spring does not support field interception.

Spring integrates with AspectJ, providing the ability to seamlessly include AspectJ aspects into Spring applications

MVC web framework
  • Spring provides a very clean division between controllers, JavaBean models, and views.
  • Spring's MVC is very flexible. Unlike Struts, which forces your Action and Form objects into concrete inheritance (thus taking away your single shot at concrete inheritance in Java), Spring MVC is entirely based on interfaces. Furthermore, just about every part of the Spring MVC framework is configurable via plugging in your own interface. Of course we also provide convenience classes as an implementation option.
  • Spring, like WebWork, provides interceptors as well as controllers, making it easy to factor out behavior common to the handling of many requests.
  • Spring MVC is truly view-agnostic. You don't get pushed to use JSP if you don't want to; you can use Velocity, XLST or other view technologies. If you want to use a custom view mechanism - for example, your own templating language - you can easily implement the Spring View interface to integrate it.
  • Spring Controllers are configured via IoC like any other objects. This makes them easy to test, and beautifully integrated with other objects managed by Spring.
  • Spring MVC web tiers are typically easier to test than Struts web tiers, due to the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.
  • The web tier becomes a thin layer on top of a business object layer. This encourages good practice. Struts and other dedicated web frameworks leave you on your own in implementing your business objects; Spring provides an integrated framework for all tiers of your application.
Implementing EJBs
Using EJBs
Testing


Most of the key point of spring framework already mentioned here, but there are lots of part we haven't covered, or didn't touch the details: e.g. Spring Web Flow, Spring AOP, Available modules.