Hessian service client
For the client project, we will be using same OrderService interface. A proxy implementation of the service will be provided by
HessianProxyFactoryBean .
A bean accessing the remote service
public class OrderBean {
@Autowired
private OrderService orderService;
public void placeOrder() {
System.out.println("-- placing orders --");
orderService.placeOrder("ABC Tablet", 2);
orderService.placeOrder("XYZ Desktop", 3);
}
public void listOrders() {
System.out.println("-- getting order list from service --");
List<Order> orderList = orderService.getOrderList();
System.out.println(orderList);
}
}
Registering HessianProxyFactoryBean and running the client
@Configuration
public class ExampleClient {
@Bean
public OrderBean orderBean() {
return new OrderBean();
}
@Bean
public HessianProxyFactoryBean exporter() {
HessianProxyFactoryBean b = new HessianProxyFactoryBean();
b.setServiceUrl("http://localhost:8080/OrderService");
b.setServiceInterface(OrderService.class);
return b;
}
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(ExampleClient.class);
OrderBean bean = context.getBean(OrderBean.class);
bean.placeOrder();
bean.listOrders();
}
} Output-- placing orders -- -- getting order list from service -- [Order{item='ABC Tablet', qty=2, orderDate=Mon Jun 12 21:23:57 CDT 2017}, Order{item='XYZ Desktop', qty=3, orderDate=Mon Jun 12 21:23:57 CDT 2017}, Order{item='ABC Tablet', qty=2, orderDate=Mon Jun 12 21:24:05 CDT 2017}, Order{item='XYZ Desktop', qty=3, orderDate=Mon Jun 12 21:24:05 CDT 2017}]
Client ProjectDependencies and Technologies Used: - spring-webmvc 4.3.8.RELEASE: Spring Web MVC.
- hessian 4.0.38: Hessian is a compact binary protocol for connecting web services.
- JDK 1.8
- Maven 3.3.9
|