Home Client app with CloudIQ
Client app with CloudIQ PDF Print E-mail
Written by Administrator   
Saturday, 13 February 2010 00:00

Client app with CloudIQ, Spring Client

Hello World Spring Client Application

The code for HelloWorldSpringClient is plain Java code using the Spring application context to get and call beans. 

There is no need to include Fabric APIs in your code. 

 Here, our client gets both a local instance and a fabric instance of the HelloWorld Spring bean, and calls each one.

HelloWorldSpringClient.java 

(in tutorial_samples/java/spring_hello_world/spring_hello_world_client/com/appistry/samples/spring_hello_world/client)

01. package com.appistry.samples.spring_hello_world.client;
02. 
03. import org.springframework.context.support.ClassPathXmlApplicationContext;
04. 
05. import com.appistry.samples.spring_hello_world.bean.IHelloWorldBean;
06. 
07. public class HelloWorldSpringClient 
08. {
09.     public static void main(String args[])
10. 	{    	
11. 		ClassPathXmlApplicationContext context = 
12.                                 new ClassPathXmlApplicationContext("spring_hello_world_bean.xml");	
13. 		IHelloWorldBean localBean  = (IHelloWorldBean)context.getBean("localHelloWorldBean");
14. 		IHelloWorldBean fabricBean = (IHelloWorldBean)context.getBean("fabricHelloWorldBean"); 
15. 		
16. 		System.out.println(localBean.greet("locally.")); 
17. 		System.out.println(fabricBean.greet("from the fabric.")); 
18. 	}
19. }

IHelloWorldBean interface

When using Spring remoting to call a remote Spring bean instance, we are required to declare an interface.

Here is our IHelloWorldBean interface. IHelloWorldBean.java

(in tutorial_samples/java/spring_hello_world/spring_hello_world_client/com/appistry/samples/spring_hello_world/bean)

1. package com.appistry.samples.spring_hello_world.bean;
2. 
3. public interface IHelloWorldBean 
4. {
5. 	public abstract String greet(String name);
6. }

Client Spring Bean XML

The following Spring application context XML is used by the Hello World Spring client application.

In this Spring application context XML, we wire two definitions for our HelloWorld Spring bean.

The first, localHelloWorldBean is a local instance of the bean. The second, fabricHelloWorldBean, is wired using the FabricProxyFactoryBean.

The FabricProxyFactoryBean works similarly to the Spring RMI remoting proxies.

It forwards calls on an interface (in this case the IHelloWorldBean interface) into the fabric, specifically to an instance of that interface running

in a fabric application. Last, we wire the Fabric API bean used by the FabricProxyFactoryBean to locate and talk to the fabric.

spring_hello_world_bean.xml (in tutorial_samples/java/spring_hello_world/spring_hello_world_client)

01. <?xml version="1.0"?>
02. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
03. <beans>
04.     <bean id="localHelloWorldBean" class="com.appistry.samples.spring_hello_world.bean.HelloWorldBean"/>
05.     <bean id="fabricHelloWorldBean" class="com.appistry.spring.FabricProxyFactoryBean">
06.         <property name="serviceInterface" value="com.appistry.samples.spring_hello_world.bean.IHelloWorldBean"/>
07.         <property name="fabric">
08.             <ref local="fabric"/>
09.         </property>
10.         <property name="applicationName" 
 value=amp;lt;mce:script type=">amp;lt;mce:script type="><mce:script type=">: 0px; margin: 0px;">"spring_hello_world_app"/>
11.         <property name="componentName" value="hello_world_component"/>
12.     </bean>
13.     <bean id="fabric" class="com.appistry.fabric.Fabric"langs/en.js" type="text/javascript">t;/span>>
14.         <constructor-arg value="239.255.0.1"/>
15.         <constructor-arg value=t;>"31000"/>
16.     </bean>
17. </beans>
Last Updated on Saturday, 13 February 2010 18:10
 
Banner
Copyright © 2010 Bloberry IT Consulting. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.