| |
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 : Amit
Title :
Spring Remoting
Description :
Java RMI Example More...
|
Written By : ISHTEK
Title :
Spring Reflection
Description :
POC Idea example code More...
|
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...
|
| Tags/Keywords : Spring Calling Stateless Session Bean, Spring Remote, Spring example, Example, Code, Tutorial, Article Author : ISHTEK Date (Year/Month/Date): 2010-07-07
SpringFrameworks SessionBean Stateless 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 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.
 | 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).
|
|
|
|
| Home >>> Spring Tutorials >>> Spring Remote Stateless SessionBean >>> Calling SessionBean Example code |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- 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.
|  |
|
|
|
|
|