Easy remoting with Spring HttpInvoker
If you're looking for a simple solution to expose/access services using Java, maybe you should consider using SpringHttpInvoker. Here's a quick recipe of how to use it (extracted from Spring docs). Let's start with the domain class:
The service interface:
And some implementation of the service:
In order to expose this service you'll need a ServletDispatcher configured inside your web.xml like the following:
And then it's just a matter of exposing your service in the WEB-INF/remoting-servlet.xml file:
And that's all you need! To access it on the client application, you just need to declare the remote service:
After this point your client application can use your service transparently via the accountService proxy. As simple as it should be!
public class Account implements Serializable{
private String name;
public String getName(){
return this.name;
}
public void setName(String name) {
this.name = name;
}
}public interface AccountService {
public void insertAccount(Account account);
public List getAccounts(String name);
}// the implementation doing nothing at the moment
public class AccountServiceImpl implements AccountService {
public void insertAccount(Account acc) {
// do something...
}
public List getAccounts(String name) {
// do something...
}
}remoting
org.springframework.web.servlet.DispatcherServlet
1
remoting
/remoting/*