Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

HTTP Invoker

Spring 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 techniques

You can use many Remoting techniques, let’s see which one can be best for you.

Http Invoker Vs RMI

RMI 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 Burlap

HTTP 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 Invoker

To create a simple spring’s HTTP invoker application, you need to create following files.

  3. web.xml
  4. httpInvoker-servlet.xml
  5. client-beans.xml


It is the simple interface containing one method cube.

  1. package com.Kreationnext;
  2. public interface Calculation {
  3. int cube(int number);
  4. }


This class provides the implementation of Calculation interface.

  1. package com.Kreationnext;
  2. public class CalculationImpl implements Calculation{
  3.     public int cube(int number) {
  4.         return number*number*number;
  5.     }
  6. }

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.

  1. <?xml version=“1.0” encoding=“UTF-8”?>
  2. <web-app version=“2.5”
  3.     xmlns=“”
  4.     xmlns:xsi=“”
  5.     xsi:schemaLocation=” 
  7.     <servlet>
  8.     <servlet-name>httpInvoker</servlet-name>
  9.     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  10.     <load-on-startup>1</load-on-startup>
  11. </servlet>
  12. <servlet-mapping>
  13.     <servlet-name>httpInvoker</servlet-name>
  14.     <url-pattern>*.http</url-pattern>
  15. </servlet-mapping>
  16. </web-app>

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.

  1. <?xml version=“1.0” encoding=“UTF-8”?>
  2. <beans xmlns=“”
  3.     xmlns:xsi=“”
  4.     xsi:schemaLocation=” 
  6. <bean id=“calculationBean” class=“com.Kreationnext.CalculationImpl”></bean>
  7. <bean name=“/Calculation.http”
  8. class=“org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter”>
  9.     <property name=“service” ref=“calculationBean”></property>
  10.     <property name=“serviceInterface” value=“com.Kreationnext.Calculation”></property>
  11. </bean>
  12. </beans>

5) client-beans.xml

In this xml file, we are defining bean for HttpInvokerProxyFactoryBean. You need to define two properties of this class.

  1. serviceUrl
  2. serviceInterface
  1. <?xml version=“1.0” encoding=“UTF-8”?>
  2. <beans xmlns=“”
  3.     xmlns:xsi=“”
  4.     xsi:schemaLocation=” 
  6. <bean id=“calculationBean”
  7. class=“org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean”>
  8.     <property name=“serviceUrl”
  9.          value=“http://localhost:8888/httpinvoker/Calculation.http”></property>
  10.     <property name=“serviceInterface” value=“com.Kreationnext.Calculation”></property>
  11. </bean>
  12. </beans>


This class gets the instance of Calculation and calls the method.

  1. package com.Kreationnext;
  2. import org.springframework.context.ApplicationContext;
  3. import;
  4. public class Client {
  5.  public static void main(String[] args){
  6.   ApplicationContext context = new ClassPathXmlApplicationContext(“client-beans.xml”);
  7.   Calculation calculation = (Calculation)context.getBean(“calculationBean”);
  8.   System.out.println(calculation.cube(5));
  9.  }
  10. }


  1. Output: 125

How to run this example

Start 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 file.

download this example (developed using Myeclipse IDE)

Web-based Client

In 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:

  2. index.jsp
  3. process.jsp

It defines only one method getCube() that returns cube of the given number

  1. package com.Kreationnext;
  2. import org.springframework.context.ApplicationContext;
  3. import;
  4. public class ClientInvoker {
  5.     public static int getCube(int number){
  6.         ApplicationContext context = new ClassPathXmlApplicationContext(“client-beans.xml”);
  7.         Calculation calculation = (Calculation)context.getBean(“calculationBean”);
  8.         return calculation.cube(number);
  9.     }
  10. }


It creates a form to get number.

  1. <form action=“process.jsp”>
  2. Enter Number:<input type=“text” name=“number”/>
  3. <input type=“submit” value=“cube” />
  4. </form>


It creates a form to get number.

  1. <jsp:include page=“index.jsp”></jsp:include>
  2. <hr/>
  3. <%@page import=“com.Kreationnext.ClientInvoker”%>
  4. <%
  5. int number=Integer.parseInt(request.getParameter(“number”));
  6. out.print(“cube of “+number+” is: “+ClientInvoker.getCube(number));
  7. %>