You want to access a remote service by RMI or web service transparently.


Obviously there should be a remoting implementation instead of normal local implementation of your service. However, we still need to write code to do real thing. Why reinvent wheels? There is a package named spring-remoting in spring framework, it handle this problem well, and the solution has been proved. Let's make it hivemind way!


First, a service point to provide service like usual:

    <service-point id="FinanceService" interface="mypackage.FinanceService"/>

Then, a remote implementation:

    <service-point id="rmiFinanceInterceptor" 
            <construct class="org.springframework.remoting.rmi.RmiClientInterceptor">
                <set property="serviceUrl" value="rmi://myserver:1399/financeService"/>
                <set-object property="serviceInterface"
    <implementation service-id="mypackage.FinanceService">
       <invoke-factory service-id="hivemind.lib.PlaceholderFactory"/>
       <interceptor service-id="hivemind.lib.MethodInterceptorFactory">
           <impl object="service:rmiFinanceInterceptor"/>

That's it! The magic here is the hivemind.lib.MethodInterceptorFactory service, it opens the door to spring interceptors. In this way, we can even use spring transaction package to declare hivemind transactional service!

How about go further

Make a ServiceImplementationFactory (let's name it RMI!RemotingServiceFactory) to declare the service easier and cleaner, so we can do:

    <implementation service-id="mypackage.FinanceService">
        <invoke-factory service-id="hivemind.contrib.RMIRemotingServiceFactory">
            <remote url="rmi://myserver:1399/financeService"/>

UsingSpringRemoting (last edited 2009-09-20 22:01:34 by localhost)