From 40d63b97f5956c8c18bbcd823011a250bf1bd50d Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 12 Sep 2023 08:12:03 -0400 Subject: [PATCH 1/5] About the test, we update String Vowel Test --- spring-remoting-modules/.idea/.gitignore | 10 +++ .../.idea/checkstyle-idea.xml | 16 ++++ spring-remoting-modules/.idea/compiler.xml | 17 ++++ spring-remoting-modules/.idea/encodings.xml | 21 +++++ .../.idea/jarRepositories.xml | 30 +++++++ spring-remoting-modules/.idea/jpa-buddy.xml | 7 ++ spring-remoting-modules/.idea/misc.xml | 18 +++++ spring-remoting-modules/.idea/vcs.xml | 6 ++ spring-remoting-modules/README.md | 13 +++ spring-remoting-modules/pom.xml | 58 ++++++++++++++ .../remoting-amqp/README.md | 3 + spring-remoting-modules/remoting-amqp/pom.xml | 21 +++++ .../remoting-amqp-client/pom.xml | 35 ++++++++ .../java/com/baeldung/client/AmqpClient.java | 46 +++++++++++ .../src/main/resources/application.properties | 19 +++++ .../src/main/resources/logback.xml | 13 +++ .../java/org/baeldung/SpringContextTest.java | 17 ++++ .../remoting-amqp-server/pom.xml | 38 +++++++++ .../java/com/baeldung/server/AmqpServer.java | 53 +++++++++++++ .../src/main/resources/application.properties | 19 +++++ .../src/main/resources/logback.xml | 13 +++ .../org/baeldung/SpringContextManualTest.java | 17 ++++ .../remoting-hessian-burlap/README.md | 12 +++ .../remoting-hessian-burlap/pom.xml | 24 ++++++ .../remoting-hessian-burlap-client/pom.xml | 79 +++++++++++++++++++ .../com/baeldung/client/BurlapClient.java | 28 +++++++ .../com/baeldung/client/HessianClient.java | 28 +++++++ .../src/main/resources/logback.xml | 13 +++ .../CabBookingServiceIntegrationTest.java | 74 +++++++++++++++++ .../java/org/baeldung/SpringContextTest.java | 18 +++++ .../src/test/resources/application.properties | 1 + .../remoting-hessian-burlap-server/pom.xml | 50 ++++++++++++ .../main/java/com/baeldung/server/Server.java | 41 ++++++++++ .../src/main/resources/logback.xml | 13 +++ .../java/org/baeldung/SpringContextTest.java | 17 ++++ .../remoting-http/README.md | 8 ++ spring-remoting-modules/remoting-http/pom.xml | 23 ++++++ .../remoting-http/remoting-http-api/pom.xml | 16 ++++ .../main/java/com/baeldung/api/Booking.java | 17 ++++ .../com/baeldung/api/BookingException.java | 7 ++ .../com/baeldung/api/CabBookingService.java | 5 ++ .../remoting-http-client/pom.xml | 34 ++++++++ .../main/java/com/baeldug/client/Client.java | 28 +++++++ .../src/main/resources/logback.xml | 13 +++ .../remoting-http-server/pom.xml | 28 +++++++ .../remoting-http-server/readme.md | 12 +++ .../server/CabBookingServiceImpl.java | 16 ++++ .../main/java/com/baeldung/server/Server.java | 27 +++++++ .../src/main/resources/logback.xml | 13 +++ .../java/org/baeldung/SpringContextTest.java | 17 ++++ .../remoting-jms/README.md | 8 ++ spring-remoting-modules/remoting-jms/pom.xml | 21 +++++ .../remoting-jms/remoting-jms-client/pom.xml | 33 ++++++++ .../java/com/baeldung/client/JmsClient.java | 39 +++++++++ .../src/main/resources/application.properties | 10 +++ .../src/main/resources/logback.xml | 13 +++ .../java/org/baeldung/SpringContextTest.java | 17 ++++ .../remoting-jms/remoting-jms-server/pom.xml | 33 ++++++++ .../server/CabBookingServiceImpl.java | 16 ++++ .../java/com/baeldung/server/JmsServer.java | 51 ++++++++++++ .../src/main/resources/application.properties | 10 +++ .../src/main/resources/logback.xml | 13 +++ .../com/baeldung/SpringContextLiveTest.java | 23 ++++++ .../remoting-rmi/README.md | 7 ++ spring-remoting-modules/remoting-rmi/pom.xml | 21 +++++ .../remoting-rmi/remoting-rmi-client/pom.xml | 33 ++++++++ .../java/com/baeldung/client/RmiClient.java | 26 ++++++ .../src/main/resources/logback.xml | 13 +++ .../com/baeldung/SpringContextLiveTest.java | 23 ++++++ .../remoting-rmi/remoting-rmi-server/pom.xml | 33 ++++++++ .../server/CabBookingServiceImpl.java | 16 ++++ .../java/com/baeldung/server/RmiServer.java | 34 ++++++++ .../src/main/resources/logback.xml | 13 +++ .../java/org/baeldung/SpringContextTest.java | 17 ++++ 74 files changed, 1675 insertions(+) create mode 100644 spring-remoting-modules/.idea/.gitignore create mode 100644 spring-remoting-modules/.idea/checkstyle-idea.xml create mode 100644 spring-remoting-modules/.idea/compiler.xml create mode 100644 spring-remoting-modules/.idea/encodings.xml create mode 100644 spring-remoting-modules/.idea/jarRepositories.xml create mode 100644 spring-remoting-modules/.idea/jpa-buddy.xml create mode 100644 spring-remoting-modules/.idea/misc.xml create mode 100644 spring-remoting-modules/.idea/vcs.xml create mode 100644 spring-remoting-modules/README.md create mode 100644 spring-remoting-modules/pom.xml create mode 100644 spring-remoting-modules/remoting-amqp/README.md create mode 100644 spring-remoting-modules/remoting-amqp/pom.xml create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-client/pom.xml create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/test/java/org/baeldung/SpringContextTest.java create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-server/pom.xml create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/test/java/org/baeldung/SpringContextManualTest.java create mode 100644 spring-remoting-modules/remoting-hessian-burlap/README.md create mode 100644 spring-remoting-modules/remoting-hessian-burlap/pom.xml create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/BurlapClient.java create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/HessianClient.java create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/org/baeldung/SpringContextTest.java create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/resources/application.properties create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/java/com/baeldung/server/Server.java create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/test/java/org/baeldung/SpringContextTest.java create mode 100644 spring-remoting-modules/remoting-http/README.md create mode 100644 spring-remoting-modules/remoting-http/pom.xml create mode 100644 spring-remoting-modules/remoting-http/remoting-http-api/pom.xml create mode 100644 spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/Booking.java create mode 100644 spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/BookingException.java create mode 100644 spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/CabBookingService.java create mode 100644 spring-remoting-modules/remoting-http/remoting-http-client/pom.xml create mode 100644 spring-remoting-modules/remoting-http/remoting-http-client/src/main/java/com/baeldug/client/Client.java create mode 100644 spring-remoting-modules/remoting-http/remoting-http-client/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-http/remoting-http-server/pom.xml create mode 100644 spring-remoting-modules/remoting-http/remoting-http-server/readme.md create mode 100644 spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java create mode 100644 spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/Server.java create mode 100644 spring-remoting-modules/remoting-http/remoting-http-server/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-http/remoting-http-server/src/test/java/org/baeldung/SpringContextTest.java create mode 100644 spring-remoting-modules/remoting-jms/README.md create mode 100644 spring-remoting-modules/remoting-jms/pom.xml create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-client/pom.xml create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/java/com/baeldung/client/JmsClient.java create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/application.properties create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-client/src/test/java/org/baeldung/SpringContextTest.java create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-server/pom.xml create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/JmsServer.java create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/application.properties create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-jms/remoting-jms-server/src/test/java/com/baeldung/SpringContextLiveTest.java create mode 100644 spring-remoting-modules/remoting-rmi/README.md create mode 100644 spring-remoting-modules/remoting-rmi/pom.xml create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-client/pom.xml create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/java/com/baeldung/client/RmiClient.java create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/test/java/com/baeldung/SpringContextLiveTest.java create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-server/pom.xml create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/RmiServer.java create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/resources/logback.xml create mode 100644 spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/test/java/org/baeldung/SpringContextTest.java diff --git a/spring-remoting-modules/.idea/.gitignore b/spring-remoting-modules/.idea/.gitignore new file mode 100644 index 0000000000..0a8642fac0 --- /dev/null +++ b/spring-remoting-modules/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Zeppelin ignored files +/ZeppelinRemoteNotebooks/ diff --git a/spring-remoting-modules/.idea/checkstyle-idea.xml b/spring-remoting-modules/.idea/checkstyle-idea.xml new file mode 100644 index 0000000000..f0c49846ff --- /dev/null +++ b/spring-remoting-modules/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + 10.12.2 + JavaOnly + true + + + \ No newline at end of file diff --git a/spring-remoting-modules/.idea/compiler.xml b/spring-remoting-modules/.idea/compiler.xml new file mode 100644 index 0000000000..92b98354bd --- /dev/null +++ b/spring-remoting-modules/.idea/compiler.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/.idea/encodings.xml b/spring-remoting-modules/.idea/encodings.xml new file mode 100644 index 0000000000..9635c68aa3 --- /dev/null +++ b/spring-remoting-modules/.idea/encodings.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/.idea/jarRepositories.xml b/spring-remoting-modules/.idea/jarRepositories.xml new file mode 100644 index 0000000000..1067e4c6b5 --- /dev/null +++ b/spring-remoting-modules/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/.idea/jpa-buddy.xml b/spring-remoting-modules/.idea/jpa-buddy.xml new file mode 100644 index 0000000000..898e07a675 --- /dev/null +++ b/spring-remoting-modules/.idea/jpa-buddy.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/.idea/misc.xml b/spring-remoting-modules/.idea/misc.xml new file mode 100644 index 0000000000..a2eb346bb8 --- /dev/null +++ b/spring-remoting-modules/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/.idea/vcs.xml b/spring-remoting-modules/.idea/vcs.xml new file mode 100644 index 0000000000..6c0b863585 --- /dev/null +++ b/spring-remoting-modules/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/README.md b/spring-remoting-modules/README.md new file mode 100644 index 0000000000..91db561f83 --- /dev/null +++ b/spring-remoting-modules/README.md @@ -0,0 +1,13 @@ +## Spring Remoting + +This module contains articles about Spring Remoting + + +### Overview +This Maven project contains the Java source code for various modules used in the Spring Remoting series of articles. + +### Building the Project +You can build the project using Maven inside your IDE or from the command line: +``` +mvn clean install +``` diff --git a/spring-remoting-modules/pom.xml b/spring-remoting-modules/pom.xml new file mode 100644 index 0000000000..480e7db21d --- /dev/null +++ b/spring-remoting-modules/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + spring-remoting-modules + 1.0-SNAPSHOT + spring-remoting-modules + pom + Parent for all projects related to Spring Remoting, except remoting-hessian-burlap + + + + + com.ossez + parent-boot-2 + 0.0.2-SNAPSHOT + parent-boot-2 + + + + + remoting-http + + remoting-jms + + + + + + + + ${project.groupId} + api + ${project.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + 11 + 11 + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/README.md b/spring-remoting-modules/remoting-amqp/README.md new file mode 100644 index 0000000000..b4367f0cd0 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +- [Spring Remoting with AMQP](https://www.baeldung.com/spring-remoting-amqp) diff --git a/spring-remoting-modules/remoting-amqp/pom.xml b/spring-remoting-modules/remoting-amqp/pom.xml new file mode 100644 index 0000000000..7e1aa83cc5 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + remoting-amqp + remoting-amqp + pom + + + com.baeldung + spring-remoting-modules + 1.0-SNAPSHOT + + + + remoting-amqp-server + remoting-amqp-client + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-client/pom.xml b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/pom.xml new file mode 100644 index 0000000000..1bcab004f1 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + remoting-amqp-client + remoting-amqp-client + jar + http://maven.apache.org + + + com.baeldung + remoting-amqp + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + com.baeldung + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java new file mode 100644 index 0000000000..def80f6b5e --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/java/com/baeldung/client/AmqpClient.java @@ -0,0 +1,46 @@ +package com.baeldung.client; + +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import org.springframework.amqp.core.*; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.remoting.client.AmqpProxyFactoryBean; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import static java.lang.System.out; + +@SpringBootApplication public class AmqpClient { + + @Bean Queue queue() { + return new Queue("remotingQueue"); + } + + @Bean AmqpProxyFactoryBean amqpFactoryBean(AmqpTemplate amqpTemplate) { + AmqpProxyFactoryBean factoryBean = new AmqpProxyFactoryBean(); + factoryBean.setServiceInterface(CabBookingService.class); + factoryBean.setAmqpTemplate(amqpTemplate); + return factoryBean; + } + + @Bean Exchange directExchange(Queue someQueue) { + DirectExchange exchange = new DirectExchange("remoting.exchange"); + BindingBuilder.bind(someQueue).to(exchange).with("remoting.binding"); + return exchange; + } + + @Bean RabbitTemplate amqpTemplate(ConnectionFactory factory) { + RabbitTemplate template = new RabbitTemplate(factory); + template.setRoutingKey("remoting.binding"); + template.setExchange("remoting.exchange"); + return template; + } + + public static void main(String[] args) throws BookingException { + CabBookingService service = SpringApplication.run(AmqpClient.class, args).getBean(CabBookingService.class); + out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037")); + } + +} diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties new file mode 100644 index 0000000000..8df44a7c8d --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/application.properties @@ -0,0 +1,19 @@ +# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'. +# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details. +spring.rabbitmq.dynamic=true + +# The port to which the client should connect defaults to 5672. +spring.rabbitmq.port=32769 + +# Username and password +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest + +# The host, defaults to localhost. +spring.rabbitmq.host=192.168.99.100 + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.springframework.amqp=TRACE + diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/logback.xml b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/test/java/org/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..fe20382ab4 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-client/src/test/java/org/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.client.AmqpClient; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AmqpClient.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-server/pom.xml b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/pom.xml new file mode 100644 index 0000000000..6b6c12b41a --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + remoting-amqp-server + remoting-amqp-server + jar + http://maven.apache.org + + + com.baeldung + remoting-amqp + 1.0-SNAPSHOT + + + + + com.baeldung + remoting-http-api + ${project.version} + + + org.springframework.boot + spring-boot-starter-amqp + + + com.baeldung + remoting-http-server + ${remoting-http-server.version} + + + + + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java new file mode 100644 index 0000000000..f0155b2141 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/java/com/baeldung/server/AmqpServer.java @@ -0,0 +1,53 @@ +package com.baeldung.server; + +import com.baeldung.api.CabBookingService; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.amqp.remoting.service.AmqpInvokerServiceExporter; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration @ComponentScan @EnableAutoConfiguration +public class AmqpServer { + + /* + Please note that + - CachingConnectionFactory + - RabbitAdmin + - AmqpTemplate + are automatically declared by SpringBoot. + */ + + @Bean CabBookingService bookingService() { + return new CabBookingServiceImpl(); + } + + @Bean Queue queue() { + return new Queue("remotingQueue"); + } + + @Bean AmqpInvokerServiceExporter exporter(CabBookingService implementation, AmqpTemplate template) { + AmqpInvokerServiceExporter exporter = new AmqpInvokerServiceExporter(); + exporter.setServiceInterface(CabBookingService.class); + exporter.setService(implementation); + exporter.setAmqpTemplate(template); + return exporter; + } + + @Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, AmqpInvokerServiceExporter exporter, Queue queue) { + SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(factory); + container.setMessageListener(exporter); + container.setQueueNames(queue.getName()); + return container; + } + + public static void main(String[] args) { + SpringApplication.run(AmqpServer.class, args); + } + +} \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties new file mode 100644 index 0000000000..8df44a7c8d --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/application.properties @@ -0,0 +1,19 @@ +# This is true to make SpringBoot to automatically register a bean of type 'org.springframework.amqp.core.AmqpAdmin'. +# Check the org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration javadoc for details. +spring.rabbitmq.dynamic=true + +# The port to which the client should connect defaults to 5672. +spring.rabbitmq.port=32769 + +# Username and password +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest + +# The host, defaults to localhost. +spring.rabbitmq.host=192.168.99.100 + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.springframework.amqp=TRACE + diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/logback.xml b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/test/java/org/baeldung/SpringContextManualTest.java b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/test/java/org/baeldung/SpringContextManualTest.java new file mode 100644 index 0000000000..a6ee0b6000 --- /dev/null +++ b/spring-remoting-modules/remoting-amqp/remoting-amqp-server/src/test/java/org/baeldung/SpringContextManualTest.java @@ -0,0 +1,17 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.server.AmqpServer; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AmqpServer.class) +public class SpringContextManualTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-hessian-burlap/README.md b/spring-remoting-modules/remoting-hessian-burlap/README.md new file mode 100644 index 0000000000..cacceddc5a --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/README.md @@ -0,0 +1,12 @@ +## Spring Remoting with Hessian and Burlap + +This module contains articles about Spring Remoting with Hessian and Burlap + +### Relevant Articles + +- [Spring Remoting with Hessian and Burlap](http://www.baeldung.com/spring-remoting-hessian-burlap) + +### Overview +This Maven project contains the Java source code for the Hessian and Burlap modules + used in the [Spring Remoting](https://github.com/eugenp/tutorials/tree/master/spring-remoting) + series of articles. diff --git a/spring-remoting-modules/remoting-hessian-burlap/pom.xml b/spring-remoting-modules/remoting-hessian-burlap/pom.xml new file mode 100644 index 0000000000..e5975b9f37 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + remoting-hessian-burlap + 1.0-SNAPSHOT + remoting-hessian-burlap + pom + + + + com.baeldung + parent-boot-1 + 0.0.1-SNAPSHOT + ../../parent-boot-1 + + + + remoting-hessian-burlap-server + remoting-hessian-burlap-client + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml new file mode 100644 index 0000000000..1939e00386 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + remoting-hessian-burlap-client + remoting-hessian-burlap-client + + + com.baeldung + remoting-hessian-burlap + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + ${project.groupId} + remoting-http-api + ${project.version} + + + com.caucho + hessian + ${hessian.version} + + + + ${project.groupId} + remoting-hessian-burlap-server + ${project.version} + test + + + javax.servlet + javax.servlet-api + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-tomcat + test + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + + + + + + + + 4.0.38 + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/BurlapClient.java b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/BurlapClient.java new file mode 100644 index 0000000000..1079c4163f --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/BurlapClient.java @@ -0,0 +1,28 @@ +package com.baeldung.client; + +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.remoting.caucho.BurlapProxyFactoryBean; + +import static java.lang.System.out; + +@Configuration +public class BurlapClient { + + @Bean + public BurlapProxyFactoryBean burlapInvoker() { + BurlapProxyFactoryBean invoker = new BurlapProxyFactoryBean(); + invoker.setServiceUrl("http://localhost:8032/b_booking"); + invoker.setServiceInterface(CabBookingService.class); + return invoker; + } + + public static void main(String[] args) throws BookingException { + CabBookingService service = SpringApplication.run(BurlapClient.class, args).getBean(CabBookingService.class); + out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037")); + } + +} diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/HessianClient.java b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/HessianClient.java new file mode 100644 index 0000000000..b2a2f4ffae --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/java/com/baeldung/client/HessianClient.java @@ -0,0 +1,28 @@ +package com.baeldung.client; + +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.remoting.caucho.HessianProxyFactoryBean; + +import static java.lang.System.out; + +@Configuration +public class HessianClient { + + @Bean + public HessianProxyFactoryBean hessianInvoker() { + HessianProxyFactoryBean invoker = new HessianProxyFactoryBean(); + invoker.setServiceUrl("http://localhost:8032/booking"); + invoker.setServiceInterface(CabBookingService.class); + return invoker; + } + + public static void main(String[] args) throws BookingException { + CabBookingService service = SpringApplication.run(HessianClient.class, args).getBean(CabBookingService.class); + out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037")); + } + +} diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/resources/logback.xml b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java new file mode 100644 index 0000000000..a1fed9637f --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java @@ -0,0 +1,74 @@ +package com.baeldung.client; + +import com.baeldung.api.Booking; +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import com.baeldung.server.Server; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static java.lang.Thread.sleep; + +@SpringBootTest(classes = {BurlapClient.class, HessianClient.class}) +@RunWith(SpringRunner.class) +public class CabBookingServiceIntegrationTest { + + static Logger log = LoggerFactory.getLogger(CabBookingServiceIntegrationTest.class); + @Autowired @Qualifier("burlapInvoker") CabBookingService burlapClient; + @Autowired @Qualifier("hessianInvoker") CabBookingService hessianClient; + static Thread serverThread; + + @BeforeClass + public static void startServer() throws InterruptedException { + serverThread = serverThread(); + log.info("Starting server."); + serverThread.start(); + // increase this enough to let the server start + sleep(6000); + } + + @org.junit.Test + public void bookACabWithBurlapClient() throws InterruptedException { + bookACab(this.burlapClient); + } + + @org.junit.Test + public void bookACabWithHessianClient() throws InterruptedException { + bookACab(this.hessianClient); + } + + private void bookACab(CabBookingService burlapClient) { + Booking booking; + try { + booking = burlapClient.bookRide("Duomo place"); + log.info("Booking success: {}", booking); + } catch (BookingException e) { + log.info("Booking failed: {}", e.getMessage()); + } + } + + @AfterClass + public static void stopServer() throws InterruptedException { + serverThread.interrupt(); + serverThread.join(); + log.info("Server terminated."); + } + + static Thread serverThread() { + Thread serverThread = new Thread(()-> { + log.info("Starting Burlap and Hessian server"); + Server.main(new String[]{}); + log.info("Burlap and Hessian server terminated"); + }); + serverThread.setDaemon(true); + return serverThread; + } + +} diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/org/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..4325b0ddef --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/java/org/baeldung/SpringContextTest.java @@ -0,0 +1,18 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.client.BurlapClient; +import com.baeldung.client.HessianClient; + +@SpringBootTest(classes = {BurlapClient.class, HessianClient.class}) +@RunWith(SpringRunner.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/resources/application.properties b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/resources/application.properties new file mode 100644 index 0000000000..13577dc391 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-client/src/test/resources/application.properties @@ -0,0 +1 @@ +application.properties=9999 \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml new file mode 100644 index 0000000000..68a70f24b6 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + remoting-hessian-burlap-server + remoting-hessian-burlap-server + + + com.baeldung + remoting-hessian-burlap + 1.0-SNAPSHOT + + + + + com.baeldung + remoting-http-server + ${project.version} + + + org.springframework.boot + spring-boot-starter-web + + + com.caucho + hessian + ${hessian.version} + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + + + + + + + + 4.0.38 + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/java/com/baeldung/server/Server.java b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/java/com/baeldung/server/Server.java new file mode 100644 index 0000000000..9c825a2a80 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/java/com/baeldung/server/Server.java @@ -0,0 +1,41 @@ +package com.baeldung.server; + +import com.baeldung.api.CabBookingService; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.remoting.caucho.BurlapServiceExporter; +import org.springframework.remoting.caucho.HessianServiceExporter; +import org.springframework.remoting.support.RemoteExporter; + +import java.util.Collections; + +@Configuration @ComponentScan @EnableAutoConfiguration public class Server { + + @Bean CabBookingService bookingService() { + return new CabBookingServiceImpl(); + } + + @Bean(name = "/booking") RemoteExporter hessianService(CabBookingService service) { + HessianServiceExporter exporter = new HessianServiceExporter(); + exporter.setService(bookingService()); + exporter.setServiceInterface(CabBookingService.class); + return exporter; + } + + @Bean(name = "/b_booking") RemoteExporter burlapService(CabBookingService service) { + BurlapServiceExporter exporter = new BurlapServiceExporter(); + exporter.setService(bookingService()); + exporter.setServiceInterface(CabBookingService.class); + return exporter; + } + + public static void main(String[] args) { + SpringApplication app = new SpringApplication(Server.class); + app.setDefaultProperties(Collections.singletonMap("server.port", "8032")); + app.run(args); + } + +} \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/resources/logback.xml b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/test/java/org/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..e676bb0ff2 --- /dev/null +++ b/spring-remoting-modules/remoting-hessian-burlap/remoting-hessian-burlap-server/src/test/java/org/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.server.Server; + +@SpringBootTest(classes = Server.class) +@RunWith(SpringRunner.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-http/README.md b/spring-remoting-modules/remoting-http/README.md new file mode 100644 index 0000000000..a4f3ea82a9 --- /dev/null +++ b/spring-remoting-modules/remoting-http/README.md @@ -0,0 +1,8 @@ +## Remoting HTTP + +This module contains articles about Spring Remoting over HTTP + +### Relevant Articles: + +- [Intro to Spring Remoting with HTTP Invokers](https://www.baeldung.com/spring-remoting-http-invoker) + diff --git a/spring-remoting-modules/remoting-http/pom.xml b/spring-remoting-modules/remoting-http/pom.xml new file mode 100644 index 0000000000..cee1d82196 --- /dev/null +++ b/spring-remoting-modules/remoting-http/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + remoting-http + remoting-http + pom + Parent for all modules related to HTTP Spring Remoting. + + + com.ossez + spring-remoting-modules + 1.0-SNAPSHOT + + + + remoting-http-server + remoting-http-client + remoting-http-api + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-api/pom.xml b/spring-remoting-modules/remoting-http/remoting-http-api/pom.xml new file mode 100644 index 0000000000..d84d942659 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-api/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + remoting-http-api + remoting-http-api + API definition shared between client and server. + + + com.ossez + remoting-http + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/Booking.java b/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/Booking.java new file mode 100644 index 0000000000..5d2d3683a1 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/Booking.java @@ -0,0 +1,17 @@ +package com.baeldung.api; + +import java.io.Serializable; + +import static java.lang.String.format; + +public class Booking implements Serializable { + private String bookingCode; + + @Override public String toString() { + return format("Ride confirmed: code '%s'.", bookingCode); + } + + public Booking(String bookingCode) { + this.bookingCode = bookingCode; + } +} diff --git a/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/BookingException.java b/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/BookingException.java new file mode 100644 index 0000000000..4099db2908 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/BookingException.java @@ -0,0 +1,7 @@ +package com.baeldung.api; + +public class BookingException extends Exception { + public BookingException(String message) { + super(message); + } +} diff --git a/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/CabBookingService.java b/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/CabBookingService.java new file mode 100644 index 0000000000..b554415e07 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-api/src/main/java/com/baeldung/api/CabBookingService.java @@ -0,0 +1,5 @@ +package com.baeldung.api; + +public interface CabBookingService { + Booking bookRide(String pickUpLocation) throws BookingException; +} diff --git a/spring-remoting-modules/remoting-http/remoting-http-client/pom.xml b/spring-remoting-modules/remoting-http/remoting-http-client/pom.xml new file mode 100644 index 0000000000..219319f75d --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-client/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + remoting-http-client + remoting-http-client + Shows how to invoke a remote service using Spring Remoting HTTP. + + + com.ossez + remoting-http + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + ${project.groupId} + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-client/src/main/java/com/baeldug/client/Client.java b/spring-remoting-modules/remoting-http/remoting-http-client/src/main/java/com/baeldug/client/Client.java new file mode 100644 index 0000000000..90f6736a43 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-client/src/main/java/com/baeldug/client/Client.java @@ -0,0 +1,28 @@ +package com.baeldug.client; + +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean; + +import static java.lang.System.out; + +@Configuration +public class Client { + + @Bean + public HttpInvokerProxyFactoryBean invoker() { + HttpInvokerProxyFactoryBean invoker = new HttpInvokerProxyFactoryBean(); + invoker.setServiceUrl("http://localhost:8080/booking"); + invoker.setServiceInterface(CabBookingService.class); + return invoker; + } + + public static void main(String[] args) throws BookingException { + CabBookingService service = SpringApplication.run(Client.class, args).getBean(CabBookingService.class); + out.println(service.bookRide("13 Seagate Blvd, Key Largo, FL 33037")); + } + +} diff --git a/spring-remoting-modules/remoting-http/remoting-http-client/src/main/resources/logback.xml b/spring-remoting-modules/remoting-http/remoting-http-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-client/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-server/pom.xml b/spring-remoting-modules/remoting-http/remoting-http-server/pom.xml new file mode 100644 index 0000000000..1dd711aedc --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-server/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + remoting-http-server + remoting-http-server + Shows how to expose a service using Spring Remoting HTTP. + + + com.ossez + remoting-http + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + ${project.groupId} + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-server/readme.md b/spring-remoting-modules/remoting-http/remoting-http-server/readme.md new file mode 100644 index 0000000000..4a2abb5d03 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-server/readme.md @@ -0,0 +1,12 @@ +Build and launch with the following command. + + mvn clean package tomcat7:run-war + +Exposed service is available at following URL. + + http://localhost:9090/spring-remoting-http-server/account + +## References + + + diff --git a/spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java b/spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java new file mode 100644 index 0000000000..55ec9c5733 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java @@ -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()); + } +} diff --git a/spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/Server.java b/spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/Server.java new file mode 100644 index 0000000000..c6b198507f --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-server/src/main/java/com/baeldung/server/Server.java @@ -0,0 +1,27 @@ +package com.baeldung.server; + +import com.baeldung.api.CabBookingService; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter; + +@Configuration +@ComponentScan +@EnableAutoConfiguration +public class Server { + + @Bean(name = "/booking") HttpInvokerServiceExporter accountService() { + HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); + exporter.setService( new CabBookingServiceImpl() ); + exporter.setServiceInterface( CabBookingService.class ); + return exporter; + } + + public static void main(String[] args) { + SpringApplication.run(Server.class, args); + } + +} \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-server/src/main/resources/logback.xml b/spring-remoting-modules/remoting-http/remoting-http-server/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-server/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-http/remoting-http-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-remoting-modules/remoting-http/remoting-http-server/src/test/java/org/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..e676bb0ff2 --- /dev/null +++ b/spring-remoting-modules/remoting-http/remoting-http-server/src/test/java/org/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.server.Server; + +@SpringBootTest(classes = Server.class) +@RunWith(SpringRunner.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-jms/README.md b/spring-remoting-modules/remoting-jms/README.md new file mode 100644 index 0000000000..2f48a8f57f --- /dev/null +++ b/spring-remoting-modules/remoting-jms/README.md @@ -0,0 +1,8 @@ +## Remoting JMS + +This module contains articles about Spring Remoting with Java Message Service (JMS) + +### Relevant Articles: + +- [Spring Remoting with JMS and ActiveMQ](https://www.baeldung.com/spring-remoting-jms) + diff --git a/spring-remoting-modules/remoting-jms/pom.xml b/spring-remoting-modules/remoting-jms/pom.xml new file mode 100644 index 0000000000..fd63fa01c2 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + remoting-jms + remoting-jms + pom + + + com.ossez + spring-remoting-modules + 1.0-SNAPSHOT + + + + remoting-jms-client + remoting-jms-server + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-client/pom.xml b/spring-remoting-modules/remoting-jms/remoting-jms-client/pom.xml new file mode 100644 index 0000000000..4ef18620bb --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-client/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + remoting-jms-client + remoting-jms-client + + + com.ossez + remoting-jms + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-activemq + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + com.ossez + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/java/com/baeldung/client/JmsClient.java b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/java/com/baeldung/client/JmsClient.java new file mode 100644 index 0000000000..0c5d728f07 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/java/com/baeldung/client/JmsClient.java @@ -0,0 +1,39 @@ +package com.baeldung.client; + +import com.baeldung.api.Booking; +import com.baeldung.api.BookingException; +import com.baeldung.api.CabBookingService; +import org.apache.activemq.command.ActiveMQQueue; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.jms.remoting.JmsInvokerProxyFactoryBean; + +import javax.jms.ConnectionFactory; +import javax.jms.Queue; + +@SpringBootApplication +public class JmsClient { + + @Bean Queue queue() { + return new ActiveMQQueue("remotingQueue"); +} + + @Bean FactoryBean invoker(ConnectionFactory factory, Queue queue) { + JmsInvokerProxyFactoryBean factoryBean = new JmsInvokerProxyFactoryBean(); + factoryBean.setConnectionFactory(factory); + factoryBean.setServiceInterface(CabBookingService.class); + factoryBean.setQueue(queue); + return factoryBean; + } + + public static void main(String[] args) throws BookingException { + CabBookingService service = SpringApplication.run(JmsClient.class, args).getBean(CabBookingService.class); + System.out.println("here"); + Booking bookingOutcome = service.bookRide("13 Seagate Blvd, Key Largo, FL 33037"); + System.out.println("there"); + System.out.println(bookingOutcome); + } + +} diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/application.properties b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/application.properties new file mode 100644 index 0000000000..738b030a59 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/application.properties @@ -0,0 +1,10 @@ +spring.activemq.broker-url=tcp://127.0.0.1:61616 +spring.activemq.packages.trusted=org.springframework.remoting.support,java.lang,com.baeldung.api + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.apache.activemq=DEBUG +logging.level.org.springframework.jms=DEBUG +logging.level.org.springframework=WARN + diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/logback.xml b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/test/java/org/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..95721b6eaa --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-client/src/test/java/org/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.client.JmsClient; + +@SpringBootTest(classes = JmsClient.class) +@RunWith(SpringRunner.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-server/pom.xml b/spring-remoting-modules/remoting-jms/remoting-jms-server/pom.xml new file mode 100644 index 0000000000..697c0612e3 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-server/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + remoting-jms-server + remoting-jms-server + + + com.ossez + remoting-jms + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-activemq + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + com.ossez + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java new file mode 100644 index 0000000000..55ec9c5733 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java @@ -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()); + } +} diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/JmsServer.java b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/JmsServer.java new file mode 100644 index 0000000000..8572718042 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/java/com/baeldung/server/JmsServer.java @@ -0,0 +1,51 @@ +package com.baeldung.server; + +import com.baeldung.api.CabBookingService; +import org.apache.activemq.command.ActiveMQQueue; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.jms.listener.SimpleMessageListenerContainer; +import org.springframework.jms.remoting.JmsInvokerServiceExporter; + +import javax.jms.ConnectionFactory; +import javax.jms.Queue; + +@SpringBootApplication public class JmsServer { + + /* + This server needs to be connected to an ActiveMQ server. + To quickly spin up an ActiveMQ server, you can use Docker. + + docker run -p 61616:61616 -p 8161:8161 rmohr/activemq:5.14.3 + */ + + @Bean CabBookingService bookingService() { + return new CabBookingServiceImpl(); + } + + @Bean Queue queue() { + return new ActiveMQQueue("remotingQueue"); +} + + @Bean JmsInvokerServiceExporter exporter(CabBookingService implementation) { + JmsInvokerServiceExporter exporter = new JmsInvokerServiceExporter(); + exporter.setServiceInterface(CabBookingService.class); + exporter.setService(implementation); + return exporter; + } + + @Bean SimpleMessageListenerContainer listener(ConnectionFactory factory, JmsInvokerServiceExporter exporter) { + SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); + container.setConnectionFactory(factory); + container.setDestinationName("remotingQueue"); + container.setConcurrentConsumers(1); + container.setMessageListener(exporter); + return container; + } + + public static void main(String[] args) { + SpringApplication.run(JmsServer.class, args); + } + +} diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/application.properties b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/application.properties new file mode 100644 index 0000000000..738b030a59 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/application.properties @@ -0,0 +1,10 @@ +spring.activemq.broker-url=tcp://127.0.0.1:61616 +spring.activemq.packages.trusted=org.springframework.remoting.support,java.lang,com.baeldung.api + +# Logging +logging.pattern.console=%d{mm:ss.SSS} %-5p [%-31t] [%-54logger{0}] %marker%m%ex{full} - %logger - %F:%L%n +logging.level.root=WARN +logging.level.org.apache.activemq=DEBUG +logging.level.org.springframework.jms=DEBUG +logging.level.org.springframework=WARN + diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/logback.xml b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-jms/remoting-jms-server/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/test/java/com/baeldung/SpringContextLiveTest.java new file mode 100644 index 0000000000..4904873be2 --- /dev/null +++ b/spring-remoting-modules/remoting-jms/remoting-jms-server/src/test/java/com/baeldung/SpringContextLiveTest.java @@ -0,0 +1,23 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.server.JmsServer; + +/** + * This Live Test requires: + * * the `com.baeldung:remoting-http-api:jar:1.0-SNAPSHOT` artifact accessible. For that we can run `mvn clean install` in the 'spring-remoting/remoting-http/remoting-http-api' module. + * * an ActiveMQ instance running (e.g. `docker run -p 61616:61616 -p 8161:8161 --name bael-activemq rmohr/activemq`) + * + */ +@SpringBootTest(classes = JmsServer.class) +@RunWith(SpringRunner.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-rmi/README.md b/spring-remoting-modules/remoting-rmi/README.md new file mode 100644 index 0000000000..082b5c37ed --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/README.md @@ -0,0 +1,7 @@ +## Remoting RMI + +This module contains articles about Spring Remoting with Remote Method Invocation (RMI) + +### Relevant Articles: + +- [Spring Remoting with RMI](https://www.baeldung.com/spring-remoting-rmi) \ No newline at end of file diff --git a/spring-remoting-modules/remoting-rmi/pom.xml b/spring-remoting-modules/remoting-rmi/pom.xml new file mode 100644 index 0000000000..aece04a64f --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + remoting-rmi + remoting-rmi + pom + + + com.baeldung + spring-remoting-modules + 1.0-SNAPSHOT + + + + remoting-rmi-server + remoting-rmi-client + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-client/pom.xml b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/pom.xml new file mode 100644 index 0000000000..91630a88e9 --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + remoting-rmi-client + remoting-rmi-client + + + com.baeldung + remoting-rmi + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-activemq + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + com.baeldung + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/java/com/baeldung/client/RmiClient.java b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/java/com/baeldung/client/RmiClient.java new file mode 100644 index 0000000000..a568b749f9 --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/java/com/baeldung/client/RmiClient.java @@ -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); + } + +} diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/resources/logback.xml b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/test/java/com/baeldung/SpringContextLiveTest.java b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/test/java/com/baeldung/SpringContextLiveTest.java new file mode 100644 index 0000000000..73f7592dcc --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-client/src/test/java/com/baeldung/SpringContextLiveTest.java @@ -0,0 +1,23 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.client.RmiClient; + +/** + * This Live Test requires: + * * the `com.baeldung:remoting-http-api:jar:1.0-SNAPSHOT` artifact accessible. For that we can run `mvn clean install` in the 'spring-remoting/remoting-http/remoting-http-api' module. + * * the 'spring-remoting\remoting-rmi\remoting-rmi-server' service running + * + */ +@SpringBootTest(classes = RmiClient.class) +@RunWith(SpringRunner.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-server/pom.xml b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/pom.xml new file mode 100644 index 0000000000..ecf57018ec --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + remoting-rmi-server + remoting-rmi-server + + + com.baeldung + remoting-rmi + 1.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + com.baeldung + remoting-http-api + ${project.version} + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java new file mode 100644 index 0000000000..55ec9c5733 --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/CabBookingServiceImpl.java @@ -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()); + } +} diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/RmiServer.java b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/RmiServer.java new file mode 100644 index 0000000000..7778c65e85 --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/java/com/baeldung/server/RmiServer.java @@ -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://:/ + // 1099 is the default port + + Class 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); + } + +} diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/resources/logback.xml b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/test/java/org/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..6cae1b66fc --- /dev/null +++ b/spring-remoting-modules/remoting-rmi/remoting-rmi-server/src/test/java/org/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.server.RmiServer; + +@SpringBootTest(classes = RmiServer.class) +@RunWith(SpringRunner.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} From feff19a0fe3a286e8a4280601a9be428c5ce49d1 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 12 Sep 2023 08:12:34 -0400 Subject: [PATCH 2/5] About the test, we update String Vowel Test --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index c0abe78ea4..050a3ded48 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ + persistence-modules testing-modules toolkits From 0dea29484bcabf04f51afed7a84f3f75fcaa342b Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Tue, 12 Sep 2023 08:47:07 -0400 Subject: [PATCH 3/5] Delete un-used file --- .idea/compiler.xml | 26 +- .idea/encodings.xml | 2 + build.gradle | 74 --- .../src/main/resources/ESAPI.properties | 453 ------------------ .../src/main/resources/META-INF/BenchmarkList | 0 .../main/resources/META-INF/persistence.xml | 20 - .../services/com.sun.source.util.Plugin | 1 - .../src/main/resources/countries.properties | 3 - .../core-java-io/src/main/resources/data.csv | 3 - .../src/main/resources/datasource.properties | 6 - .../src/main/resources/js/bind.js | 15 - .../src/main/resources/js/locations.js | 1 - .../src/main/resources/js/math_module.js | 19 - .../src/main/resources/js/no_such.js | 11 - .../src/main/resources/js/script.js | 1 - .../src/main/resources/js/trim.js | 2 - .../src/main/resources/js/typed_arrays.js | 9 - .../src/main/resources/log4j.properties | 6 - .../resources/log4jstructuraldp.properties | 9 - .../src/main/resources/logback.xml | 6 +- .../src/main/resources/zipTest/file3.txt | 1 + gradlew | 172 ------- gradlew.bat | 84 ---- mvnw | 233 --------- mvnw.cmd | 145 ------ pom.xml | 2 +- settings.gradle | 25 - 27 files changed, 19 insertions(+), 1310 deletions(-) delete mode 100644 build.gradle delete mode 100644 core-java-modules/core-java-io/src/main/resources/ESAPI.properties delete mode 100644 core-java-modules/core-java-io/src/main/resources/META-INF/BenchmarkList delete mode 100644 core-java-modules/core-java-io/src/main/resources/META-INF/persistence.xml delete mode 100644 core-java-modules/core-java-io/src/main/resources/META-INF/services/com.sun.source.util.Plugin delete mode 100644 core-java-modules/core-java-io/src/main/resources/countries.properties delete mode 100644 core-java-modules/core-java-io/src/main/resources/data.csv delete mode 100644 core-java-modules/core-java-io/src/main/resources/datasource.properties delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/bind.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/locations.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/math_module.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/no_such.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/script.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/trim.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/js/typed_arrays.js delete mode 100644 core-java-modules/core-java-io/src/main/resources/log4j.properties delete mode 100644 core-java-modules/core-java-io/src/main/resources/log4jstructuraldp.properties create mode 100644 core-java-modules/core-java-io/src/main/resources/zipTest/file3.txt delete mode 100644 gradlew delete mode 100644 gradlew.bat delete mode 100644 mvnw delete mode 100644 mvnw.cmd delete mode 100644 settings.gradle diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b81cacce0b..e2b711e14d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -8,34 +8,36 @@ - - - - - - - - - - - - + + + + + + + + + + + + + +