Skip to content

Commit 673faed

Browse files
danidemiKevinGilmore
authored andcommitted
baeldung-articlesBAEL-553 Intro to Spring Remoting with HTTP Invokers (eugenp#1034)
* First test with log4j rolling appenders * small fix * Log4j rolling appender * First set up with rolling file on log4j 2 * Added logback code. * log4j2 more detailed example * log4j2 more detailed example * Improved names and examples * Fixed configurations * improved configs * formatted * Final fix * fixed formatting * Formatting fix * Fix sample apps to avoid try / catch * Fix request to replace files * Fix end lines * Log4j2 logger is shot down at the end. * Initial commit, the server starts launched from maven * made room for client and server projects * made room for client and server projects * base example works * poms restructured * packages restructured * packages restructured * Some renaming and a proper formatting string * Small renamings * Small renamings * Fixed invoked URL in client through fixing bean name * java.time.* instead of java.util.Date * java.time.* instead of java.util.Date * Removed log on file, kepts log on console * Updated Spring and Logback version to latest release. * Exception removed from run() * Code simplification. - Interfaces and objects simplified. - Spring Boot instead of plain Spring - No need for Tomcat plug in anymore. * Small updates to poms. * Unused classes removed. * Unused classes removed.
1 parent 9220584 commit 673faed

15 files changed

Lines changed: 68 additions & 331 deletions

File tree

‎spring-remoting/pom.xml‎

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,24 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>1.4.3.RELEASE</version>
10+
</parent>
611
<groupId>com.baeldung</groupId>
712
<artifactId>spring-remoting</artifactId>
813
<version>1.0-SNAPSHOT</version>
14+
<description>Parent for all projects related to Spring Remoting.</description>
915
<packaging>pom</packaging>
1016

1117
<properties>
12-
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
13-
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
14-
15-
<servlet.version>3.1.0</servlet.version>
16-
<logback.version>1.1.8</logback.version>
17-
<spring.version>4.3.5.RELEASE</spring.version>
18+
<java.version>1.8</java.version>
1819
</properties>
1920

2021
<dependencyManagement>
2122
<dependencies>
2223

23-
<!-- spring -->
24-
<dependency>
25-
<groupId>org.springframework</groupId>
26-
<artifactId>spring-core</artifactId>
27-
<version>${spring.version}</version>
28-
</dependency>
29-
<dependency>
30-
<groupId>org.springframework</groupId>
31-
<artifactId>spring-context</artifactId>
32-
<version>${spring.version}</version>
33-
</dependency>
34-
<dependency>
35-
<groupId>org.springframework</groupId>
36-
<artifactId>spring-web</artifactId>
37-
<version>${spring.version}</version>
38-
</dependency>
39-
<dependency>
40-
<groupId>org.springframework</groupId>
41-
<artifactId>spring-webmvc</artifactId>
42-
<version>${spring.version}</version>
43-
</dependency>
44-
45-
<!-- logback -->
46-
<dependency>
47-
<groupId>ch.qos.logback</groupId>
48-
<artifactId>logback-core</artifactId>
49-
<version>${logback.version}</version>
50-
</dependency>
51-
<dependency>
52-
<groupId>ch.qos.logback</groupId>
53-
<artifactId>logback-classic</artifactId>
54-
<version>${logback.version}</version>
55-
</dependency>
56-
57-
<!-- servlet -->
58-
<dependency>
59-
<groupId>javax.servlet</groupId>
60-
<artifactId>javax.servlet-api</artifactId>
61-
<version>${servlet.version}</version>
62-
<scope>provided</scope>
63-
</dependency>
64-
6524
<!-- companion modules -->
6625
<dependency>
6726
<groupId>${project.groupId}</groupId>
@@ -73,35 +32,6 @@
7332

7433
</dependencyManagement>
7534

76-
77-
<build>
78-
<pluginManagement>
79-
<plugins>
80-
<plugin>
81-
<artifactId>maven-compiler-plugin</artifactId>
82-
<version>${maven-compiler-plugin.version}</version>
83-
<configuration>
84-
<debug>true</debug>
85-
<optimize>true</optimize>
86-
<source>1.8</source>
87-
<target>1.8</target>
88-
<encoding>UTF-8</encoding>
89-
<showDeprecation>true</showDeprecation>
90-
<showWarnings>true</showWarnings>
91-
</configuration>
92-
</plugin>
93-
<!-- This special setup for maven-war-plugin is needed to use Servlet 3 annotation based configuration, where a WEB-INF/web.xml is not strictl needed. -->
94-
<plugin>
95-
<artifactId>maven-war-plugin</artifactId>
96-
<version>3.0.0</version>
97-
<configuration>
98-
<failOnMissingWebXml>false</failOnMissingWebXml>
99-
</configuration>
100-
</plugin>
101-
</plugins>
102-
</pluginManagement>
103-
</build>
104-
10535
<modules>
10636
<module>remoting-http</module>
10737
</modules>

‎spring-remoting/remoting-http/api/src/main/java/com/baeldung/api/Address.java‎

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,17 @@
11
package com.baeldung.api;
22

33
import java.io.Serializable;
4-
import java.time.LocalDateTime;
54

6-
public class Booking implements Serializable {
5+
import static java.lang.String.format;
76

8-
private int costInCent;
9-
private int etaInSeconds;
7+
public class Booking implements Serializable {
108
private String bookingCode;
11-
private LocalDateTime pickUptime;
12-
private Address pickUpAddress;
13-
private Address dropOffAddress;
14-
15-
public Booking(Address pickUpAddress, LocalDateTime pickUptime, Address dropOffAddress, int costInCent, int etaInSeconds, String bookingCode) {
16-
this.costInCent = costInCent;
17-
this.etaInSeconds = etaInSeconds;
18-
this.bookingCode = bookingCode;
19-
this.pickUptime = pickUptime;
20-
this.pickUpAddress = pickUpAddress;
21-
this.dropOffAddress = dropOffAddress;
22-
}
23-
24-
public int getCostInCent() {
25-
return costInCent;
26-
}
27-
28-
public int getEtaInSeconds() {
29-
return etaInSeconds;
30-
}
31-
32-
public String getBookingCode() {
33-
return bookingCode;
34-
}
35-
36-
public LocalDateTime getPickUptime() {
37-
return pickUptime;
38-
}
39-
40-
public Address getDropOffAddress() {
41-
return dropOffAddress;
42-
}
439

4410
@Override public String toString() {
45-
return String.format("Booking: pick up @ %tr in %s, drop down in %s after %d minutes, %.2f $.", pickUptime, pickUpAddress, dropOffAddress, etaInSeconds / 60, costInCent / 100.0);
11+
return format("Ride confirmed: code '%s'.", bookingCode);
4612
}
4713

48-
public static void main(String[] args) throws InterruptedException {
49-
System.out.println(new Booking(new Address("a", "b"),
50-
LocalDateTime.now(), new Address("c", "d"), 123_00, 600, "abc"));
14+
public Booking(String bookingCode) {
15+
this.bookingCode = bookingCode;
5116
}
5217
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.baeldung.api;
22

33
public interface CabBookingService {
4-
Booking bookPickUp(Address pickUpLocation, Address dropOffLocation, int pax) throws BookingException;
4+
Booking bookRide(String pickUpLocation) throws BookingException;
55
}

‎spring-remoting/remoting-http/client/pom.xml‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
<artifactId>spring-remoting-http</artifactId>
1010
<version>1.0-SNAPSHOT</version>
1111
</parent>
12-
1312
<artifactId>spring-remoting-http-client</artifactId>
14-
<description>Shows how to invoke a remote service using Spring Remoting.</description>
15-
13+
<description>Shows how to invoke a remote service using Spring Remoting HTTP.</description>
1614
<dependencies>
17-
<!-- spring -->
1815
<dependency>
19-
<groupId>org.springframework</groupId>
20-
<artifactId>spring-web</artifactId>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
<exclusions>
19+
<exclusion>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-tomcat</artifactId>
22+
</exclusion>
23+
</exclusions>
2124
</dependency>
22-
23-
<!-- companion modules -->
2425
<dependency>
2526
<groupId>${project.groupId}</groupId>
2627
<artifactId>api</artifactId>
2728
</dependency>
2829
</dependencies>
29-
3030
</project>

‎spring-remoting/remoting-http/client/src/main/java/com/baeldug/client/CabBookingClient.java‎

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldug.client;
2+
3+
import com.baeldung.api.BookingException;
4+
import com.baeldung.api.CabBookingService;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
9+
10+
import static java.lang.System.out;
11+
12+
@Configuration
13+
public class Client {
14+
15+
@Bean
16+
public HttpInvokerProxyFactoryBean invoker() {
17+
HttpInvokerProxyFactoryBean invoker = new HttpInvokerProxyFactoryBean();
18+
invoker.setServiceUrl("http://localhost:8080/booking");
19+
invoker.setServiceInterface(CabBookingService.class);
20+
return invoker;
21+
}
22+
23+
public static void main(String[] args) throws BookingException {
24+
CabBookingService service = SpringApplication.run(Client.class, args).getBean(CabBookingService.class);
25+
out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037"));
26+
}
27+
28+
}

‎spring-remoting/remoting-http/client/src/main/java/com/baeldug/client/Main.java‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎spring-remoting/remoting-http/pom.xml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
<version>1.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>spring-remoting-http</artifactId>
12-
<description>Parent for all modules related to HTTP Spring Remoting</description>
12+
<description>Parent for all modules related to HTTP Spring Remoting.</description>
1313
<packaging>pom</packaging>
14-
1514
<modules>
1615
<module>server</module>
1716
<module>client</module>

‎spring-remoting/remoting-http/server/pom.xml‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,16 @@
88
<artifactId>spring-remoting-http</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010
</parent>
11-
<packaging>war</packaging>
12-
1311
<artifactId>spring-remoting-http-server</artifactId>
14-
<description>Shows how to expose a service using Spring Remoting</description>
15-
16-
<properties>
17-
<tomcat7-maven-plugin.version>2.2</tomcat7-maven-plugin.version>
18-
</properties>
19-
12+
<description>Shows how to expose a service using Spring Remoting HTTP.</description>
2013
<dependencies>
21-
22-
<!-- spring -->
23-
24-
<!-- spring-webmvc is mainly needed to have access to the Spring's DispatcherServler -->
2514
<dependency>
26-
<groupId>org.springframework</groupId>
27-
<artifactId>spring-webmvc</artifactId>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-web</artifactId>
2817
</dependency>
29-
30-
<!-- servlet -->
31-
<dependency>
32-
<groupId>javax.servlet</groupId>
33-
<artifactId>javax.servlet-api</artifactId>
34-
</dependency>
35-
36-
<!-- companion modules -->
3718
<dependency>
3819
<groupId>${project.groupId}</groupId>
3920
<artifactId>api</artifactId>
4021
</dependency>
41-
4222
</dependencies>
43-
44-
<build>
45-
<plugins>
46-
<plugin>
47-
<artifactId>maven-compiler-plugin</artifactId>
48-
</plugin>
49-
50-
<plugin>
51-
<artifactId>maven-war-plugin</artifactId>
52-
</plugin>
53-
54-
<plugin>
55-
<groupId>org.apache.tomcat.maven</groupId>
56-
<artifactId>tomcat7-maven-plugin</artifactId>
57-
<version>${tomcat7-maven-plugin.version}</version>
58-
<configuration>
59-
<port>9090</port>
60-
</configuration>
61-
</plugin>
62-
</plugins>
63-
</build>
64-
6523
</project>

0 commit comments

Comments
 (0)