Tuesday, August 5, 2008

Replacing RMI with Spring Remoting

Custom classes used

com.px.site.db.IExampleService - Service Interface

com.px.site.db.ExampleService - - Service Implementation

EXAMPLE_SERVICE_URL - urel (Ex :htpp://10.x.x.x/context/ExampleDetails

context - is the context name under jetty/tomcat where the remote service is running

All other classes are from the spring jar

Service Code(Server)

The bean is instantiated in the service side using the following entry in the spring xml

<bean id="exampleProxy" class="com.px.site.db.ExampleService"/>

The implementation is provided to the main applicatuion calling the following url

<bean name="/ExampleDetails" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="exampleProxy"/>
<property name="serviceInterface" value="com.px.site.db.IExampleService"/>
</bean>

The the application can get a reference using the url --> htpp://10.x.x.x/context/ExampleDetails


Main Application Code(client)

The service reference is obtained in the main application by adding the following in the spring xml where
EXAMPLE_SERVICE_URL is htpp://10.x.x.x/context/ExampleDetails obtained from any of the config parameters


<bean id="exampleService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="${EXAMPLE_SERVICE_URL}"/>
<property name="serviceInterface" value="com.px.site.db.IExampleService"/>
</bean>


Now this service if needed can be used directly in any action or injected into any main service.

<bean id="application" class="com.examples.main.application">
<property name="exampleService" ref="exampleService"/>
</bean>

Them main advantage of this is a application can speak to any service which is remotely located.

No comments:

 
Free Domain Names @ .co.nr!