Skip to content

Commit 2e119a5

Browse files
danidemipivovarit
authored andcommitted
BAEL-557 Spring Remoting with RMI (eugenp#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
1 parent fc33d62 commit 2e119a5

7 files changed

Lines changed: 166 additions & 0 deletions

File tree

‎spring-remoting/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<module>remoting-hessian-burlap</module>
3434
<module>remoting-amqp</module>
3535
<module>remoting-jms</module>
36+
<module>spring-remoting-rmi</module>
3637
</modules>
3738

3839
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-remoting</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<packaging>pom</packaging>
12+
<modules>
13+
<module>remoting-rmi-server</module>
14+
<module>remoting-rmi-client</module>
15+
</modules>
16+
<artifactId>spring-remoting-rmi</artifactId>
17+
18+
19+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-remoting-rmi</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>remoting-rmi-client</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-activemq</artifactId>
18+
<exclusions>
19+
<exclusion>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-tomcat</artifactId>
22+
</exclusion>
23+
</exclusions>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.baeldung</groupId>
27+
<artifactId>api</artifactId>
28+
</dependency>
29+
</dependencies>
30+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.client;
2+
3+
import com.baeldung.api.Booking;
4+
import com.baeldung.api.BookingException;
5+
import com.baeldung.api.CabBookingService;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
10+
11+
@SpringBootApplication public class RmiClient {
12+
13+
@Bean RmiProxyFactoryBean service() {
14+
RmiProxyFactoryBean rmiProxyFactory = new RmiProxyFactoryBean();
15+
rmiProxyFactory.setServiceUrl("rmi://localhost:1099/CabBookingService");
16+
rmiProxyFactory.setServiceInterface(CabBookingService.class);
17+
return rmiProxyFactory;
18+
}
19+
20+
public static void main(String[] args) throws BookingException {
21+
CabBookingService service = SpringApplication.run(RmiClient.class, args).getBean(CabBookingService.class);
22+
Booking bookingOutcome = service.bookRide("13 Seagate Blvd, Key Largo, FL 33037");
23+
System.out.println(bookingOutcome);
24+
}
25+
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-remoting-rmi</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>remoting-rmi-server</artifactId>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
<exclusions>
23+
<exclusion>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-tomcat</artifactId>
26+
</exclusion>
27+
</exclusions>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.baeldung</groupId>
31+
<artifactId>api</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.baeldung</groupId>
35+
<artifactId>api</artifactId>
36+
<version>${project.version}</version>
37+
</dependency>
38+
</dependencies>
39+
40+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.server;
2+
3+
import com.baeldung.api.Booking;
4+
import com.baeldung.api.BookingException;
5+
import com.baeldung.api.CabBookingService;
6+
7+
import static java.lang.Math.random;
8+
import static java.util.UUID.randomUUID;
9+
10+
public class CabBookingServiceImpl implements CabBookingService {
11+
12+
@Override public Booking bookRide(String pickUpLocation) throws BookingException {
13+
if (random() < 0.3) throw new BookingException("Cab unavailable");
14+
return new Booking(randomUUID().toString());
15+
}
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.server;
2+
3+
import com.baeldung.api.CabBookingService;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.remoting.rmi.RmiServiceExporter;
8+
9+
@SpringBootApplication public class RmiServer {
10+
11+
@Bean CabBookingService bookingService() {
12+
return new CabBookingServiceImpl();
13+
}
14+
15+
@Bean RmiServiceExporter exporter(CabBookingService implementation) {
16+
17+
// Expose a service via RMI. Remote obect URL is:
18+
// rmi://<HOST>:<PORT>/<SERVICE_NAME>
19+
// 1099 is the default port
20+
21+
Class<CabBookingService> serviceInterface = CabBookingService.class;
22+
RmiServiceExporter exporter = new RmiServiceExporter();
23+
exporter.setServiceInterface(serviceInterface);
24+
exporter.setService(implementation);
25+
exporter.setServiceName(serviceInterface.getSimpleName());
26+
exporter.setRegistryPort(1099);
27+
return exporter;
28+
}
29+
30+
public static void main(String[] args) {
31+
SpringApplication.run(RmiServer.class, args);
32+
}
33+
34+
}

0 commit comments

Comments
 (0)