JBoss Seam

Yet another Web Application Framework! This time it is from JBoss Community. JBoss provides a new Web Application Framework called “JBoss Seam” which combines the advantages from the two rapidly growing technologies Enterprise Java Beans 3.0 and Java Server Faces. JBoss Seam, by sitting on top of J2EE provides a nice way of integration between JSF and EJB Components with other great functionalities

EJB 3 Vs Hibernate

 

what is Hibernate?

HIBERNATE is an ORM ( Object-Relational-Mapping) technology. It is an Open-Source and free technology , developed in SourceForge.net. There have been a number of such ORM technologies,in recent past.. TopLink is one such tool , subsequently adopted by Oracle and so proprietory.

Hibernate from SourceForge and OJB(Object-Relational-Bridge) from Apache are two well known ORM tools,open-source and free. JDO , also falls within the same category.

Hibernate and EJB 3.0

EJB-3 , is the latest version and it is heavily influenced by Hibernate. Some readers equate EJB-3 with Hibernate. Some even equate EJB-3 with JBOSS! Oracle supports EJB-3 proposals and as it is the main Database company in j2ee world, EJB-3 has bright future. J2EE( Java Enterprise Edition) by its very name is an Enterprise level technology, and as EJB is the essence of such Enterprise applications, because of the built-in container services offered, the significance of the surging interest in Hibernate can be really appreciated only in association with EJB and hence a detour into EJB is inevitable.

EJB has three types. One type is the SESSION BEAN,residing in ENTERPRISE container, which can be thought of as a function-bean, invoked in RMI-IIOP style. (this is a rough definition).Such session-bean , may be either stateless or stateful.

This type of EJB has stood the test of time during the last six years and has even gained wide approval, even for data-access, especially since it fits very well with the emerging XML WebService technology, and is very easy to learn and implement.( The earlier tutorial on EJB as webservice in Feb-2005, in DeveloperIQ illustrates this feature).The stateless bean working in Enterprise container has an exact counter-part in Microsoft COM+(MTS), but the other types are said to be available in MS platform only through third-party extensions.

ORM tools have been sometimes used along with Session beans. The only problem till recently was that they were proprietary and rather costly. But nowadays, very reliable open-source ORM tools are available, and even Richard Monson Haefel ( an acknowledged authority and author on EJB)approves this method as a safe and productive alternative to Entity beans.( page-467..EJB by Haefel-OReilly).

The other branch, the ENTITY BEAN has been less lucky. EJB-1.1, EJB-2.0 and then EJB-2.1 , have meant a number of changes in the specification relating to Entity Beans. We can say that an Entity bean is an ‘Attribute bean’ or ‘property-bean’, with setter and getter methods, invoked in RMI-IIOP style and persisted in Enterprise container. The pattern of defining a typical Javabean is a recurring theme in Java. The same style occurs in BDK,EJB-Entity beans, Struts,JSF and now in Hibernate too. So, it is very important and elegant.

The third branch is Messaging paradigm and MDB. A recent article in the web dubbed the ‘RPC’ style, on which the previous two types of EJB are based, as stone-age technologies! An Enterprise by its very name implies huge number of customers and concurrent transactions, RPC style being like telephone call, could result in ‘line-engaged!’ problem. If the call involves the called person referring to some records before replying, it leads to line- blocking. But, messaging style, as in email, at least ensures that the message has been sent. It is evident that dubbing RPC( read ‘telephone’) as unsuitable , is over-statement. Sometimes, we desire immediate response, too. By the same token, even XML webservice , if it is really serious, should adopt messaging style and it does.MDB (Message-Driven bean) has weathered the storm and is in fact gaining more and more acceptance.

custom message with acegi

Hi!

I have got the problem while define the custom message in acegi with spring.

 Reading the reference guide does not help me, since following code snip from it does not work:

<bean id=”messageSource” class=”org.springframework.context.support.Reloada bleResourceBundleMessageSource”>

<property name=”basename”><value>my/project/securitymessages</value></property>

</bean>

After reading the Source Code of Acegi, I have got the following idea:

<bean id=”messageSource” class=”org.acegisecurity.AcegiMessageSource”>

<property name=”basename”><value>my/project/securitymessages</value></property>

</bean>

This bean definition works. I have no idea, if the reference guide is wrong or I simply used the MessagesSource otherwise than expected, but since it works for now, it is fine for me and fine for you, too. I hope .

Tagsoup

TagSoup is a library for extracting information out of unstructured HTML code, sometimes known as tag-soup. The HTML does not have to be well formed, or render properly within any particular framework. This library is for situations where the author of the HTML is not cooperating with the person trying to extract the information, but is also not trying to hide the information.

Please find the below URL for more details :http://mercury.ccil.org/~cowan/XML/tagsoup/

 

simple fast programming

To make integration code simple, flexible and fast, you need to separate technical code from business code, use integration layers wisely, and be aware of different ways of processing XML.

Separating technical code from business code simplifies coding and testing, and makes it possible to support multiple data transfer methods. Design business code so that it does not care whether data is sent using messaging middleware, files, or in-memory calls.

If your system already has a well-defined programming interface (API), but not one that is suitable for broad integration, build or acquire an integration layer to map between the API and your integration standards. For example, I have used a separate integration layer to map between XML messages sent on IBM’s WMQ messaging middleware and calls to and from Oracle PL/SQL stored procedures.

Not all integration layers add value. I have seen some which have required the business code to call the layer’s API, which is simply the wrong way around. It would be just as easy to hand code the integration without the additional layer.

Resist the temptation to add snippets of business logic to the integration layer, even though it may seem a quick and simple solution. It is very easy to lose sight of business logic in an integration layer. Keep all the business logic in the core system.

Programming with XML can be daunting. You can make it less daunting by using only simple XML structures. You also need to pick the most appropriate approach for processing XML.

Event-based XML processing, such as the simple API for XML (SAX), invokes your code as it reads an XML message. It is more suitable for technical programming than for business programming.

Object-based XML processing, such as the world wide web consortium (W3C) document object model (DOM), reads an XML document into memory and then allows the program to query the XML. DOM-based XML processing is widely available. Use DOM-based processing where it is available, where performance is not a major consideration, and when XML documents are not huge.

The W3C DOM API can be daunting. Consider writing some additional routines which simplify the main XML processing tasks that you need.

Pull-based processing, such as the streaming API for XML (StAX), involves calling a parser repeatedly to retrieve each item in the XML document. This is very fast, and can process documents of indefinite size.

If you are using an older language for which there is no XML support, such as COBOL, it is relatively simple to write your own pull-based parser. This provides a much more “traditional” view of XML than the other methods. For example, I have developed adapters which call a pull-based parser, and then present the data to legacy program using file-like semantics.

There is no silver bullet for programming interfaces. Be sceptical of tool vendors that promise to make it easy. In my experience, hand coding is usually the easiest way. But with a little forethought and care, it is possible to build simple, flexible and fast interfaces.

Java 5

This JavaOne 2006 presentation looks at the benefits and issues of migrating to Java 1.5.
The presentation also looks at how to take advantage of the superior VM performance, security enhancements, XML support, JMX and JDBC enhancements and deployment improvements.

Why Hibernate Shards ?

If you want to adopt a shard architecture, but don’t want to start from scratch, you may want to consider Hibernate’s sharding system.

Hibernate Shards is a framework that is designed to encapsulate and minimize this complexity by adding support for horizontal partitioning to Hibernate Core.

Hibernate Shards key features:

* Standard Hibernate programming model - Hibernate Shards allows you to continue using the Hibernate APIs you know and love: SessionFactory, Session, Criteria, Query. If you already know how to use Hibernate, you already know how to use Hibernate Shards.

* Flexible sharding strategies - Distribute data across your shards any way you want. Use one of the default strategies we provide or plug in your own application-specific logic.

* Support for virtual shards - Think your sharding strategy is never going to change? Think again. Adding new shards and redistributing your data is one of the toughest operational challenges you will face once you’ve deployed your shard-aware application. Hibernate Sharding supports virtual shards, a feature designed to simplify the process of resharding your data.

* Free/open source - Hibernate Shards is licensed under the LGPL (Lesser GNU Public License)

Integrate with struts2 and spring

 This post will describe how to do integrate with struts2 and spring. The only major step that needs to be done here is to override the default Struts 2.0 ObjectFactory. Changing the ObjectFactory to spring give control to spring framework to instantiate action instances etc. Most of the code is from the previous post, but I will list only the additional changes here.

  1. Changing the default Object factory: In order to change the Ojbect factory to Spring, you have to add a declaration in the struts.properties file.

 

struts.objectFactory = spring struts.devMode = true struts.enable.DynamicMethodInvocation = false

 

src/struts.properties

  1. The Action class: Here is the code for the action class

 

package actions;

 

import java.util.List;

import business.BusinessInterface;

import com.opensymphony.xwork2.ActionSupport;

 

public class SearchAction extends ActionSupport {

      private BusinessInterface businessInterface;

      private String minSalary;

      private String submit;

      private List data;

 

      public String getSubmit() {

            return submit;

      }

 

      public void setSubmit(String submit) {

            this.submit = submit;

      }

 

      public BusinessInterface getBusinessInterface() {

            return businessInterface;

      }

 

      public String execute() throws Exception {

            try {

                  long minSal = Long.parseLong(getMinSalary());

                  System.out.println(“Business Interface: “ + businessInterface

                              + “Minimum salary : “ + minSal);

                  data = businessInterface.getData(minSal);

                  System.out.println(“Data : “ + data);

            } catch (Exception e) {

                  e.printStackTrace();

            }

            return SUCCESS;

      }

 

      public void setBusinessInterface(BusinessInterface bi) {

            businessInterface = bi;

      }

 

      public String getMinSalary() {

            return minSalary;

      }

 

      public void setMinSalary(String minSalary) {

            this.minSalary = minSalary;

      }

 

      public List getData() {

            return data;

      }

 

      public void setData(List data) {

            this.data = data;

      }

}

SearchAction.java

  1.  
    • The Action class here does not have access to the HttpServetRequest and HttpServletResponse. Hence the action class itself was changed to the session scope for this example (see below)
    • In order for the action class to be aware of the Http Session, the action class has to implement the ServletRequestAware interface, and define a setServletRequest method, which will be used to inject the ServletRequest into the action class.
    • The BusinessInterface property is injected by Spring framework.
  2. The struts Configuration:

 

 

<!DOCTYPE struts PUBLIC      “-//Apache Software Foundation//DTD Struts Configuration 2.0//EN”      “http://struts.apache.org/dtds/struts-2.0.dtd”>

<struts>

      <package name=“Struts2Spring” namespace=“/actions”

            extends=“struts-default”>

            <action name=“search” class=“actions.SearchAction”>

                  <result>/search.jsp</result>

            </action>

      </package>

</struts>

src/struts.xml

  1.  
    • The action’s class attribute has to map the id attribute of the bean defined in the spring bean factory definition.

The Spring bean factory definition

 

<?xml version=“1.0″ encoding=“UTF-8″?>

<beans xmlns=“http://www.springframework.org/schema/beans”

      xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

      xsi:schemaLocation=“http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd”

      default-autowire=“autodetect”>

      <bean id=“dataSource”

            class=“org.apache.commons.dbcp.BasicDataSource”

            destroy-method=“close”>

            <property name=“driverClassName”>

                  <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>

            </property>

            <property name=“url”>

                  <value>

                        jdbc:microsoft:sqlserver://WEBSERVER:1433;DatabaseName=EBOOK_TEST

                  </value>

            </property>

            <property name=“username”>

                  <value>sa</value>

            </property>

            <property name=“password”>

                  <value>sa</value>

            </property>

      </bean>

      <!– Configure DAO –>

      <bean id=“empDao” class=“data.DAO”>

            <property name=“dataSource”>

                  <ref bean=“dataSource”></ref>

            </property>

      </bean>

      <!– Configure Business Service –>

      <bean id=“businessInterface” class=“business.BusinessInterface”>

            <property name=“dao”>

                  <ref bean=“empDao”></ref>

            </property>

      </bean>

      <bean id=“actions.SearchAction” name=“search”

            class=“actions.SearchAction” scope=“session”>

            <property name=“businessInterface” ref=“businessInterface”/>

      </bean>

</beans>

 

 

WEB-INF/applicationContext.xml

  1.  
    • The bean definition for the action class contains the id attribute which matches the class attribute of the action in struts.xml
    • Spring 2’s bean scope feature can be used to scope an Action instance to the session, application, or a custom scope, providing advanced customization above the default per-request scoping.

 

  1. The web deployment descriptor

<?xml version=“1.0″ encoding=“UTF-8″?>

<web-app id=“WebApp_9″ version=“2.4″

      xmlns=“http://java.sun.com/xml/ns/j2ee”

      xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

      xsi:schemaLocation=“http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>

      <display-name>Struts2Spring</display-name>

      <filter>

            <filter-name>struts2</filter-name>

            <filter-class>

                  org.apache.struts2.dispatcher.FilterDispatcher

            </filter-class>

      </filter>

      <filter-mapping>

            <filter-name>struts2</filter-name>

            <url-pattern>/*</url-pattern>

      </filter-mapping>

      <listener>

            <listener-class>

                  org.springframework.web.context.ContextLoaderListener

            </listener-class>

      </listener>

      <listener>

            <listener-class>

                  org.springframework.web.context.request.RequestContextListener

            </listener-class>

      </listener>

      <welcome-file-list>

            <welcome-file>index.html</welcome-file>

      </welcome-file-list>

</web-app>

 

web.xml

The only significant addition here is that of the RequestContextListener. This listener allows Spring framework, access to the HTTP session information.

 

 

 

 

struts with tiles

This post describes a way I figured out how to integrate Struts 2 with tiles. Struts 2 provides a plugin for integrating tiles 2. This plugin is included in the complete bundle (struts-2.x.x.x-all.zip). The following are are the steps needed to integrate struts2 with tiles.

  1. Download the struts complete bundle from the struts 2 website
  2. Download tiles 2 from tiles 2 website
  3. Download the tiles dependencies from the jakarta commons site
    • Commons BeanUtils 1.7.0 or above
    • Commons Digester 1.8 or above
    • Commons Logging 1.1 or above
  4. Create the layout page, and related files (except the layout, all the other files are basic jsps )

<%@ taglib uri=“http://tiles.apache.org/tags-tiles” prefix=“tiles” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1″>

<title>Insert title here</title>

</head>

<body>

<table width=“100%” height=“100%”>

      <tr height=“20%”>

            <td colspan=“2″ align=”centerbgcolor=“skyblue”><tiles:insertAttribute

                  name=“header” /></td>

      </tr>

      <tr>

            <td bgcolor=“cyan” width=“75%”><tiles:insertAttribute name=“body” /></td>

      </tr>

      <tr height=“20%”>

            <td colspan=“2″ align=”centerbgcolor=“skyblue”><tiles:insertAttribute

                  name=“footer” /></td>

      </tr>

</table>

</body>

</html>

  1. Create the HelloWorld Action class package example; import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport { public String execute() throws Exception { System.out.println(”Hello World”); return SUCCESS; } }
  2. Configure the Web Deployment descriptor by adding a tiles listener to the web.xml file of your web application.

<?xml version=“1.0″ >

<web-app xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns=“http://java.sun.com/xml/ns/javaee” xmlns:web=“http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” xsi:schemaLocation=“http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd” id=“WebApp_ID” version=“2.5″>

 

  <display-name>tilesTest</display-name>

   <listener>

    <listener-class> org.apache.struts2.tiles.StrutsTilesListener </listener-class>

    </listener>

 

 

     <filter>

      <filter-name>struts2</filter-name>

      <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class>

       </filter>

      

      <filter-mapping>

      <filter-name>struts2</filter-name>

       <url-pattern>/*</url-pattern>

       </filter-mapping>

      

       <welcome-file-list>

       <welcome-file>index.html</welcome-file>

       </welcome-file-list>

</web-app>

 

  1. Configure struts to work with tiles, this can be done by either

1.      Extending the sturts package from “tiles-default” <package name=”tilesTest” extends=”tiles-default”>OR

2.      Declaring a new “result-type”, tiles, that will map to “org.apache.struts2.views.tiles.TilesResult” <result-types> <result-type name=”tiles” class=”org.apache.struts2.views.tiles.TilesResult” /> </result-types>

  1. Set the type of the results in the package to “tiles” <result name=”success” type=”tiles”>helloworld.home</result>struts.xml

<?xml version=”1.0″ encoding=”UTF-8″ ?>

<!DOCTYPE struts PUBLIC “-//Apache Software Foundation//DTD Struts Configuration 2.0//EN” “http://struts.apache.org/dtds/struts-2.0.dtd”>

<struts>

      <package name=”tilesTest” extends=”struts-default”>

            <result-types>

                  <result-type name=”tiles”

                        class=”org.apache.struts2.views.tiles.TilesResult” />

            </result-types>

            <action name=”helloWorld” class=”example.HelloWorld”>

                  <result name=”success” type=”tiles”>helloworld.home</result>

            </action>

      </package>

</struts>

 

Note that the result “helloword.home” must match the definition name in tiles.xml file.

  1. Create definitions for tiles in WEB-INF/tiles.xml file.

<!DOCTYPE tiles-definitions PUBLIC “-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN” “http://tiles.apache.org/dtds/tiles-config_2_0.dtd”>

<tiles-definitions>

      <definition name=”helloworld.home” template=”/layouts/layout.jsp”>

            <put-attribute name=”header” value=”/layouts/header.jsp” />

            <put-attribute name=”body” value=”/index.html” />

            <put-attribute name=”footer” value=”/layouts/footer.jsp” />

      </definition>

</tiles-definitions>

 

 

spring acegi against with database

hi dude,

here I given acegi configuration with database. 

add applicationContext-acegi-security.xml into your web-inf folder.

<?xml version=“1.0″ encoding=“UTF-8″?>

<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”>

<beans>

 

<!– ======================== FILTER CHAIN ======================= –>

 

<bean id=“filterChainProxy”

class=“org.acegisecurity.util.FilterChainProxy”>

 

<property name=“filterInvocationDefinitionSource”>

 

<value>

CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON

 

PATTERN_TYPE_APACHE_ANT