File tree Expand file tree Collapse file tree
src/main/java/com/baeldung/client
src/main/java/com/baeldung/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments