BAEL-557 Spring Remoting with RMI (#2240)

* Burlap & Hessian server added

* Burlap & Hessian client work

* Fixed main

* Fixed formatting

* Spring Remote example based on Burlap & Hessian runs in a JUnit test

* Fixed main

* Fixed formatting

* Spring Remote example based on Burlap & Hessian runs in a JUnit test

* Spring Remote example based on Burlap & Hessian runs in a JUnit test

* Burlap & Hessian client work

* Fixed main

* Fixed main

* Fixed formatting

* Fixed formatting

* Spring Remote example based on Burlap & Hessian runs in a JUnit test

* Spring Remote example based on Burlap & Hessian runs in a JUnit test

* Fixed POM

* First version of remoting example based on RMI

* Fixed format

* Fixed format

* Fixed format
This commit is contained in:
Daniele Demichelis 2017-07-09 21:22:17 +02:00 committed by Grzegorz Piwowarek
parent fc33d62cc3
commit 2e119a5e99
7 changed files with 166 additions and 0 deletions

View File

@ -33,6 +33,7 @@
<module>remoting-hessian-burlap</module>
<module>remoting-amqp</module>
<module>remoting-jms</module>
<module>spring-remoting-rmi</module>
</modules>
</project>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-remoting</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>remoting-rmi-server</module>
<module>remoting-rmi-client</module>
</modules>
<artifactId>spring-remoting-rmi</artifactId>
</project>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-remoting-rmi</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>remoting-rmi-client</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baeldung</groupId>
<artifactId>api</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,26 @@
package com.baeldung.client;
import com.baeldung.api.Booking;
import com.baeldung.api.BookingException;
import com.baeldung.api.CabBookingService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
@SpringBootApplication public class RmiClient {
@Bean RmiProxyFactoryBean service() {
RmiProxyFactoryBean rmiProxyFactory = new RmiProxyFactoryBean();
rmiProxyFactory.setServiceUrl("rmi://localhost:1099/CabBookingService");
rmiProxyFactory.setServiceInterface(CabBookingService.class);
return rmiProxyFactory;
}
public static void main(String[] args) throws BookingException {
CabBookingService service = SpringApplication.run(RmiClient.class, args).getBean(CabBookingService.class);
Booking bookingOutcome = service.bookRide("13 Seagate Blvd, Key Largo, FL 33037");
System.out.println(bookingOutcome);
}
}

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-remoting-rmi</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>remoting-rmi-server</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baeldung</groupId>
<artifactId>api</artifactId>
</dependency>
<dependency>
<groupId>com.baeldung</groupId>
<artifactId>api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,16 @@
package com.baeldung.server;
import com.baeldung.api.Booking;
import com.baeldung.api.BookingException;
import com.baeldung.api.CabBookingService;
import static java.lang.Math.random;
import static java.util.UUID.randomUUID;
public class CabBookingServiceImpl implements CabBookingService {
@Override public Booking bookRide(String pickUpLocation) throws BookingException {
if (random() < 0.3) throw new BookingException("Cab unavailable");
return new Booking(randomUUID().toString());
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.server;
import com.baeldung.api.CabBookingService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.rmi.RmiServiceExporter;
@SpringBootApplication public class RmiServer {
@Bean CabBookingService bookingService() {
return new CabBookingServiceImpl();
}
@Bean RmiServiceExporter exporter(CabBookingService implementation) {
// Expose a service via RMI. Remote obect URL is:
// rmi://<HOST>:<PORT>/<SERVICE_NAME>
// 1099 is the default port
Class<CabBookingService> serviceInterface = CabBookingService.class;
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceInterface(serviceInterface);
exporter.setService(implementation);
exporter.setServiceName(serviceInterface.getSimpleName());
exporter.setRegistryPort(1099);
return exporter;
}
public static void main(String[] args) {
SpringApplication.run(RmiServer.class, args);
}
}