Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Spring Tutorials >>> Spring Local Stateless SessionBean >>> Calling Local SessionBean Example code
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : ISHTEK
Title :
Spring singleton
Description : Spring Container Example
More...


Written By : ISHTEK
Title :
Spring Features Updates News
Description : Bringing To Page
More...


Written By : ISHTEK
Title :
Spring Service
Description : Web Service Example
More...


Written By : ISHTEK
Title :
Spring WebService
Description : Example Code Discussed
More...


Written By : Amit
Title :
Spring Web MVC
Description : Example code discussed
More...


Written By : ISHTEK
Title :
Spring Remote Stateless SessionBean
Description : Calling SessionBean Example code
More...


Written By : ISHTEK
Title :
Spring Local Stateless SessionBean
Description : Calling Local SessionBean Example code
More...


Written By : guddu
Title :
Struts 2 Spring
Description : Integration Example and Details
More...

Tags/Keywords : Spring Local, Spring Bean, Spring and SessionBean, Spring example, Example, Code, Tutorial, Article, Session Bean code
Author : ISHTEK
Date (Year/Month/Date): 2010-07-08 Using Spring to call remote and local stateless session beans with example code

Please be informed that NONE of the design/code/matter from this page is claiming to be some
sort of best practice and we DO NOT expect any of our visitor/reader of this page to assume
this as some sort of best practice for any context and should not be using this as it is
without appropriate evaluation.
This page intends only to provide bits and pieces of known ways  for doing some sort of example
and may not be fit for any other purpose.

In spite of all precautions taken to provide accurate and avoid any typo in these pages,
there might be some issues like grammatical mistakes and typo being observed in these pages,
We extend our sincerest apologies for the same.


Using SpringFramework's LocalStatelessSessionProxyFactoryBean class Extending that already developed example using SimpleRemoteStatelessSessionProxyFactoryBean, I am going to add one more stateless session bean, that is going to be called from the session facade stateless session bean by using LocalStatelessSessionProxyFactoryBean in configuration and injectable way. As both these stateless session beans are co-located within the same EJB container, provided by the JBoss Application Server version 4.0.5, I don't see any issues using LocalStatelessSessionProxyFactoryBean, in order to provide business interface runtime instance being injected into the example POJOhelper class "PaymentProcessInterface.java", as shown in the configuration below: applicationContext.xml This XML configuration file is to be read by Spring in the EJB Container at the time when any of the declared bean is retrieved from the Spring Application Context. <?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"> <!-- Either by reading hibernate.cfg.xml file or by defining hibernateProperties one can create SessionFactory for using along with Hibernate API. --> <!-- <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> <bean id="paymentOperation" class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"> <property name="jndiName" value="payment-operation"/> <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.process.IPaymentOperation"/> </bean> <bean id="paymentProcessInterface" class="example.facade.PaymentProcessInterface"> <property name="paymentProcess" ref="paymentOperation"/> </bean> </beans> The section marked as green above, will be used in the AccountDAO.java file for retrieving HibernateTemplate, and the section marked as red above, will be used by the SessionBean to fetch the helper class (PaymentProcessInterface.java), this helper class is having the local stateless session bean being injected by using SpringFramework's LocalStatelessSessionProxyFactoryBean. As shown above, JNDI name "payment-operation" is used to bind local stateless session bean, such as "IPaymentOperation" on deployment onto the EJB Application server. This stateless session bean is made simplest by having a single business method like "sendPayment", and I am going to make this SessionBean compatible with EJB 2.0 specification with deployment descriptor files used, such as ejb-jar.xml and jboss.xml files under META-INF folder. This example is targeted to use a test client java program and a remote session bean is called from this test harness using a separate applicationContext.xml file. The remote session bean is using a helper bean from the server side Spring application context. This helper bean is having another local stateless session bean instance being injected to it. The test client has the Spring's configuration file as follows: 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> Let us take a look at the test client java code and try to understand this example's end to end logical execution flow. TestClient.java package example.test; import java.math.BigDecimal; import java.rmi.RemoteException; import org.springframework.context.support.ClassPathXmlApplicationContext; import example.businessobject.Account; import example.facade.ExampleFacade; /** * This is provide AS IS without any Guarantee 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) { e.printStackTrace(); } public static void main(String[] args) { new TestClient(); } } The section marked in green in the above code, is a one time execution logic when this class is getting loaded in the classloader. This example's delegate called as "ExampleBusinessDelegate", is just holding the remote interface of the stateless session bean ExampleFacade. ExampleBusinessDelegate.java package example.test; import example.facade.ExampleFacade; public class ExampleBusinessDelegate { private ExampleFacade exampleFacade; public ExampleFacade getExampleFacade() { return exampleFacade; } public void setExampleFacade(ExampleFacade exampleFacade) { this.exampleFacade = exampleFacade; } } This means there is a stateless session bean ExampleFacade that is remote in nature and being deployed on a remote application server not even located in the machine where this test client is being executed. So SimpleRemoteStatelessSessionProxyFactoryBean class from Spring api requires JNDI name and environment including Naming provider URL, initial factory etc., in order to find the remotely bound session bean. Once this test client is used to call the remote session bean, then comes understanding of the portion from the application server and Spring's application context from within application server. This example has the flow from the remote stateless session bean to the helper class, then to the local stateless session bean, then to the example service, DAO and then using HibernateTemplate to persist domain object to the corresponding mapped table in database.
Author of this article/writeup has expressed his/her willingness
to help or guide users with any technical difficulties he/she faces while working with the example code environment setting up, running and resolving any such exception raised during compile or at runtime. You may ask for any technical doubt or seek technical help related to this article by using following form to reach for technical help from the Author for FREE. This article's Author shall be reading your request and responding within reasonable time (no resolution timeframe defined as such).


	
Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
25,34
Enter bigger number from above :*
Home >>> Spring Tutorials >>> Spring Local Stateless SessionBean >>> Calling Local SessionBean Example code
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
24,13
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2010, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
 

Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners

This web site's Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example code, tips, tutorials etc. Like any printed materials,
content of these pages may become out of date over a period of time. Therefore all visitor/users of this web site are requested/advised
to refer to the originating parties/sources for the latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating parties/sources. These examples with source code or
without source code, have not been thoroughly tested under all conditions. Interview-questions-tips-forum.net therefore, cannot guarantee
or imply reliability of these example source code or programs.

By accessing and using this website in any ways, including, without limitation, browsing the website pages, using any information, using
any content and/or downloading any materials, you agree to and are bound by the terms of use described in this page and Usage Terms and Conditions.
If you do not agree to all of the terms and conditions contained in the terms of use described in this page and
Usage Terms and Conditions, do not use this website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being taken for providing accurate and up-to-date
information but like any printed materials, these blog(s)/contents may eventually be outdated one day, so if you are using any of these
information, please refer original content/documentation from respective sources. And under no circumstances shall the Author of these
contents and/or this web site be liable for any loss, damage, expense incurred or suffered which is claimed to have occurred because of
usage of the contents of this web site. If you have any questions/queries/feedback/suggestions then please write to this web site owner
at contact.