Tech I Enjoy Logo

Custom Search




  Home >> Spring Framework


Using SimpleRemoteStatelessSessionProxyFactoryBean from Spring Framework

Taking an already hosted example in this site, I shall try to use
SimpleRemoteStatelessSessionProxyFactoryBean from SpringFramework.

I have used this class from within example business delegator to get
an handle to the remote stateless session bean, that is deployed
onto an EJB container within JBoss Application Server version 4.0.5.

In this example I have used two separate application context XML
descriptor files, like applicationContext.xml in the EJB JAR
file that is deployed in an Application Server EJB container,
and client-applicationContext.xml file for the command line
Test Client written using Java Technology Platform.

applicationContext.xml
<?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-3.0.xsd">

  <bean id="sessionFactoryBean" 
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--    
    <property name="configLocation" value="classpath:config/hibernate.cfg.xml"/>   
-->
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.connection.datasource">java:MysqlDS</prop>
        <prop key="hibernate.connection.pool_size">2</prop>
        <prop key="hibernate.dialect">
	  org.hibernate.dialect.MySQLDialect
	</prop>
        <prop key="hibernate.transaction.factory_class">
	    org.hibernate.transaction.JTATransactionFactory
	</prop>
        <prop key="hibernate.transaction.manager_lookup_class">
	  org.hibernate.transaction.JBossTransactionManagerLookup
	</prop>
        <prop key="hibernate.current_session_context_class">jta</prop>
      </props>
    </property>
    <property name="mappingResources">
      <array>
        <value>example/businessobject/Account.hbm.xml</value>
      </array>
    </property>
  </bean>
  <bean id="hibernateTemplate" 
        class="org.springframework.orm.hibernate3.HibernateTemplate">
    <constructor-arg type="org.hibernate.SessionFactory" 
        ref="sessionFactoryBean"/>
  </bean>
  <bean id="hibernateDAO" class="example.dao.HibernateDAO">
    <property name="hibernateTemplate" ref="hibernateTemplate"/>
  </bean>
</beans>
AND client-applicationContext.xml
<?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-3.0.xsd">

 <bean id="exampleBD" class="example.test.ExampleBusinessDelegate">
    <property name="exampleFacade" ref="remoteSLBean"/>
 </bean>
 <bean id="remoteSLBean" 
  class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    <property name="jndiName" value="example-facade"/>
    <property name="jndiEnvironment">
    <props>
      <prop key="java.naming.provider.url">jnp://localhost:1099/</prop>
      <prop key="java.naming.factory.initial">
          org.jnp.interfaces.NamingContextFactory
      </prop>
      <prop key="java.naming.factory.url.pkgs">
          org.jboss.naming:org.jnp.interfaces
      </prop>
    </props>
    </property>
    <property name="businessInterface" value="example.facade.ExampleFacade"/>
 </bean>
</beans>
I have used the businessInterface as the remote interface from this example that is "example.facade.ExampleFacade", hence testing client will be getting runtime implementation for this business interface, as shown in the code below: TestClient.java
package example.test;

import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import example.businessobject.Account;
import example.dao.HibernateDAO;
import example.facade.ExampleFacade;
import example.facade.ExampleFacadeHome;

/**
 *  This is provide AS IS without any Guaranty of any kind
 *  Author: Guddu from IQTF
 *  Date: 15th April 2009
 */

public class TestClient {
private static ExampleBusinessDelegate exampleBD;
static {
  try {
    ClassPathXmlApplicationContext clsCtx = 
      new ClassPathXmlApplicationContext("config/client-applicationContext.xml");
    exampleBD = (ExampleBusinessDelegate) clsCtx.getBean("exampleBD");
    System.out.println("Business Delegate instance: "+exampleBD);
  }catch(Exception ex) {
    ex.printStackTrace();
  }
}    


public TestClient(){
        try {

		ExampleFacade remote = exampleBD.getExampleFacade();
        
        Account account = new Account();
        account.setAccountNumber("Test_1");
        account.setAccountType("test type");
        account.setHolderName("Test Holder");
        account.setBalanceAmount(new BigDecimal(12000.50));
        account.setAccountActiveStatus(true);
        String accountNumber = remote.createAccount(account);
        System.out.println("Account created: "+accountNumber);
        
        Account account1 = new Account();
        account1.setAccountNumber("Test_2");
        account1.setAccountType("test type");
        account1.setHolderName("Test Holder");
        account1.setBalanceAmount(new BigDecimal(62000.50));
        account1.setAccountActiveStatus(true);
        String accountNumber1 = remote.createAccount(account1);
        System.out.println("Account created: "+accountNumber1);
        
        boolean status = remote.
                   transferAmount(account, account1, new BigDecimal(4563.55));
        System.out.println("Status of the Amount Transfer func :"+status);
  } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
  }
}
/**
 * @param args
 */
public static void main(String[] args) {
  new TestClient();
}

}
So in this example there are two separate Spring's Bean Factory are created, one in the server and the another at client side Java Runtime environment. Other files are same as mentioned in some other article/page in this site, link for which is as follows: Example for Reference Set of JAR files I have used to make this example build and run, are as follows:
  • aopalliance-alpha1.jar
  • cglib-2.1.3.jar
  • commons-collections-2.1.1.jar
  • commons-logging-1.0.4.jar
  • hibernate3.jar
  • jta.jar
  • log4j-1.2.11.jar
  • org.springframework.aop-3.0.0.RELEASE.jar
  • org.springframework.asm-3.0.0.RELEASE.jar
  • org.springframework.aspects-3.0.0.RELEASE.jar
  • org.springframework.beans-3.0.0.RELEASE.jar
  • org.springframework.context-3.0.0.RELEASE.jar
  • org.springframework.context.support-3.0.0.RELEASE.jar
  • org.springframework.core-3.0.0.RELEASE.jar
  • org.springframework.expression-3.0.0.RELEASE.jar
  • org.springframework.orm-3.0.0.RELEASE.jar
  • org.springframework.transaction-3.0.0.RELEASE.jar
  • spring-aop.jar
  • I have used all these Jar files in Eclipse workspace/ project build path and in Application server runtime environment, thus resolving those classnotfound exception poping up quite often, while building/running this example. Hope this helps. If you like to share your comment/suggestions/feedback relating to this Page, you can do so by droping us an email at usingframeworks @ gmail . com with the subject line mentioning URL for this Page (i.e, /Spring-Remote-SLBean.php) or use this LINK. As per this website's privacy policy, we never disclose your email id, though we shall post your comments/suggestions/feedback with your name (optional) and date on this Page. If you don't want your comments/suggestions/feedback to be shared in this Page, please mention so in your email to us. Thank you very much..... If anything missed out , please let me know at techienjoy at yahoo . com
    Spring Framework Remote Session Bean :
    Spring Framework Example source code of
    Remote Session Bean.
    Example using Spring DAO with Hibernate :
    Example using Spring DAO with Hibernate Framework Part 2.
    Example using Spring with Hibernate :
    Example using Spring with Hibernate Framework Part 1.
    Spring Framework Web Example and WSDL :
    Spring Framework Web Example source code
    with WSDL.Step by step code walkthrough
    Example using Spring DAO with Hibernate :
    Example using Spring DAO with Hibernate Framework.
    Spring Framework Web Example :
    Spring Framework Web Example source code Explained.
    Spring Framework Web Example :
    Spring Framework Web Example source code Explained.
    Example using Spring with Hibernate :
    Example using Spring with Hibernate Framework Part 2.
    Spring Framework Local Stateless Session bean :
    Spring Framework Local Stateless Session bean with
    example source code explained.
    Spring Framework Singleton Example :
    Spring Framework Singleton Example source code 
    compared with GOF Singleton.
    Example using Spring with Hibernate :
    Example using Spring with Hibernate Framework and use
    Current Session Context.
    Spring Batch Framework Example :
    Spring Batch Framework Example source code
     and Step by step code walkthrough
    Spring Framework Example :
    Spring Framework Example source code Explained.
    Step by step code walkthrough
    Interview Questions with answer on Spring Framework :
    Interview Questions with answer on Spring Framework.
    Spring Framework MVC and Tiles :
    Spring Framework MVC and Tiles with Example 
    source code explained.


    References :
    Tags: spring dao hibernate example
    Tags: spring hibernate dao example
    Tags: spring hibernate example 2
    Tags: spring hibernate example current session context
    Tags: spring hibernate example
    Tags: Spring Interview Questions Answer
    Tags: Spring Local SLBean
    Tags: Spring MVC Tiles2
    Tags: Spring Remote SLBean
    Tags: Spring Singleton GOF Singleton Difference
    Tags: spring web example
    Tags: spring ws example
    Tags: Spring
    Tags: springws example wsdl
    

    
    
    DISCLAIMER :
    The content provided in this page is not warranted and/or guaranteed by techienjoy.com. 
    techienjoy.com is not liable for any negative consequences that may result/arise from 
    implementing directly/indirectly any information covered in these pages/articles/tutorials.
    
    All contents of this site is/are written and provided on an "AS IS" basis,
    without WARRANTIES or conditions of any kind, either express or implied, including, without
    limitation, merchantability, or fitness for a particular purpose. You are solely responsible
    for determining the appropriateness of using or refering this and assume any risks associated
    with this.
    
    In spite of all precautions taken to avoid any typo in these pages, there might be some 
    issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
    extends sincerest apologies to all our visitors for the same.
    
    
    

    Android Examples || Android Examples

    © Copyright 2010-2012, TECHIENJOY, All Rights Reserved.      Privacy Policy     Disclaimer & Terms & Conditions