91-9990449935 0120-4256464 |
Spring Remoting by HTTP Invoker ExampleSpring provides its own implementation of remoting service known as HttpInvoker. It can be used for http request than RMI and works well across the firewall. By the help of HttpInvokerServiceExporter and HttpInvokerProxyFactoryBean classes, we can implement the remoting service provided by Spring's Http Invokers. Http Invoker and Other Remoting techniquesYou can use many Remoting techniques, let's see which one can be best for you. Http Invoker Vs RMIRMI uses JRMP protocol whereas Http Invokes uses HTTP protocol. Since enterprise applications mostly use http protocol, it is the better to use HTTP Invoker. RMI also has some security issues than HTTP Invoker. HTTP Invoker works well across firewalls. Http Invoker Vs Hessian and BurlapHTTP Invoker is the part of Spring framework but Hessian and burlap are proprietary. All works well across firewall. Hessian and Burlap are portable to integrate with other languages such as .Net and PHP but HTTP Invoker cannot be. Example of Spring HTTP InvokerTo create a simple spring's HTTP invoker application, you need to create following files.
It is the simple interface containing one method cube. 2) CalculationImpl.java This class provides the implementation of Calculation interface. 3) web.xml In this xml file, we are defining DispatcherServlet as the front controller. If any request is followed by .http extension, it will be forwarded to DispatcherServlet. 4) httpInvoker-servlet.xml It must be created inside the WEB-INF folder. Its name must be servletname-servlet.xml. It defines bean for CalculationImpl and HttpInvokerServiceExporter. 5) client-beans.xml In this xml file, we are defining bean for HttpInvokerProxyFactoryBean. You need to define two properties of this class.
6) Client.java This class gets the instance of Calculation and calls the method. OutputHow to run this exampleStart and deploy the project, here we are assuming that server is running on 8888 port number. If the port number is different, change the serviceURL in client-beans.xml. Then, Compile and Run the Client.java file. Web-based ClientIn the example given above, we used console based client. We can also use web based client. You need to create 3 additional files. Here, we are using following files:
ClientInvoker.java It defines only one method getCube() that returns cube of the given number index.jspIt creates a form to get number. process.jspIt creates a form to get number. Output
Next TopicSpring Remoting by Hessian
|