-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a spring remoting server.
- Loading branch information
Showing
6 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
########################################### | ||
### Build Stage 1 ### | ||
########################################### | ||
FROM maven:3.8.6-openjdk-8-slim AS maven-builder | ||
COPY ./resources/server /usr/src/app | ||
WORKDIR /usr/src/app | ||
RUN mvn clean package | ||
|
||
########################################### | ||
### Build Stage 2 ### | ||
########################################### | ||
FROM alpine:latest AS jdk-builder | ||
RUN set -ex \ | ||
&& apk add --no-cache openjdk11 \ | ||
&& /usr/lib/jvm/java-11-openjdk/bin/jlink --add-modules java.rmi,java.management.rmi,jdk.unsupported --verbose --strip-debug --compress 2 \ | ||
--no-header-files --no-man-pages --output /jdk | ||
|
||
########################################### | ||
### Container Stage ### | ||
########################################### | ||
FROM alpine:latest | ||
|
||
COPY ./resources/scripts/start.sh /opt/start.sh | ||
COPY --from=maven-builder /usr/src/app/target/rmg-spring-remoting-server-*-jar-with-dependencies.jar /opt/remoting-server.jar | ||
COPY --from=jdk-builder /jdk /usr/lib/jvm/java-11-openjdk | ||
|
||
RUN set -ex \ | ||
&& ln -s /usr/lib/jvm/java-11-openjdk/bin/java /usr/bin/java \ | ||
&& chmod +x /opt/start.sh | ||
|
||
ENV _JAVA_OPTIONS -Djava.rmi.server.hostname=iinsecure.example | ||
|
||
EXPOSE 1099/tcp | ||
|
||
CMD ["/opt/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/ash | ||
|
||
IP=$(ip a | grep inet | grep -v 127.0.0.1 | grep -o "\([0-9]\{1,3\}\.\?\)\{4\}" | head -n 1) | ||
echo "[+] IP address of the container: ${IP}" | ||
|
||
echo "[+] Adding gateway address to /etc/hosts file..." | ||
GATEWAY=$(ip r | grep "default via" | cut -d" " -f 3) | ||
echo "$GATEWAY prevent.reverse.dns" >> /etc/hosts | ||
|
||
echo "[+] Adding RMI hostname to /etc/hosts file..." | ||
echo "127.0.0.1 iinsecure.example" >> /etc/hosts | ||
|
||
echo "[+] Starting rmi server..." | ||
exec /usr/bin/java -jar /opt/remoting-server.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.qtc.rmg</groupId> | ||
<artifactId>spring-remoting</artifactId> | ||
<version>1.0.0</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
<version>2.7.16</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<finalName>rmg-spring-remoting-server-${project.version}</finalName> | ||
<archive> | ||
<manifest> | ||
<mainClass>de.qtc.rmg.springremoting.Starter</mainClass> | ||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
...g-remoting/resources/server/src/main/java/de/qtc/rmg/springremoting/ServerOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.qtc.rmg.springremoting; | ||
|
||
public interface ServerOperations | ||
{ | ||
String notRelevant(); | ||
String execute(String cmd); | ||
String system(String cmd, String[] args); | ||
String upload(int size, int id, byte[] content); | ||
int math(int num1, int num2); | ||
} |
122 changes: 122 additions & 0 deletions
122
...oting/resources/server/src/main/java/de/qtc/rmg/springremoting/SpringRemotingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package de.qtc.rmg.springremoting; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.remoting.rmi.RmiServiceExporter; | ||
|
||
@SuppressWarnings("deprecation") | ||
public class SpringRemotingService implements ServerOperations | ||
{ | ||
Logger logger = LoggerFactory.getLogger(SpringRemotingService.class); | ||
|
||
SpringRemotingService springRemotingService() | ||
{ | ||
return new SpringRemotingService(); | ||
} | ||
|
||
@Bean | ||
RmiServiceExporter exporter(SpringRemotingService impl) | ||
{ | ||
Class<ServerOperations> serverInterface = ServerOperations.class; | ||
RmiServiceExporter exporter = new RmiServiceExporter(); | ||
|
||
exporter.setServiceInterface(serverInterface); | ||
exporter.setService(impl); | ||
exporter.setServiceName("spring-remoting"); | ||
exporter.setRegistryPort(1099); | ||
|
||
return exporter; | ||
} | ||
|
||
public String notRelevant() | ||
{ | ||
logger.info("Method", "notRelevant", "was called."); | ||
return "Hello World :D"; | ||
} | ||
|
||
public String execute(String command) | ||
{ | ||
logger.info("Processing call for", "String execute(String command)"); | ||
String result = ""; | ||
|
||
try | ||
{ | ||
Process p = java.lang.Runtime.getRuntime().exec(command); | ||
p.waitFor(); | ||
result = readFromProcess(p); | ||
} | ||
|
||
catch (IOException | InterruptedException e) | ||
{ | ||
result = "Exception: " + e.getMessage(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public String system(String command, String[] args) | ||
{ | ||
logger.info("Processing call for", "String system(String command, String[] args)"); | ||
String result = ""; | ||
|
||
String[] commandArray = new String[args.length + 1]; | ||
commandArray[0] = command; | ||
System.arraycopy(args, 0, commandArray, 1, args.length); | ||
|
||
try | ||
{ | ||
Process p = java.lang.Runtime.getRuntime().exec(commandArray); | ||
p.waitFor(); | ||
result = readFromProcess(p); | ||
} | ||
|
||
catch (IOException | InterruptedException e) | ||
{ | ||
result = "Exception: " + e.getMessage(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public String upload(int size, int id, byte[] content) | ||
{ | ||
logger.info("Processing call for", "String upload(int size, int id, byte[] content)"); | ||
return "Upload of size " + size + " was saved as user_uploads_" + id + "."; | ||
} | ||
|
||
public int math(int num1, int num2) | ||
{ | ||
logger.info("Processing call for", "int math(int num1, int num2)"); | ||
return num1 / num2; | ||
} | ||
|
||
private static String readFromProcess(Process p) throws IOException | ||
{ | ||
StringBuilder result = new StringBuilder(); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
String line = reader.readLine(); | ||
|
||
while (line != null) | ||
{ | ||
result.append(line); | ||
line = reader.readLine(); | ||
} | ||
|
||
reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); | ||
line = reader.readLine(); | ||
|
||
while (line != null) | ||
{ | ||
result.append(line); | ||
line = reader.readLine(); | ||
} | ||
|
||
return result.toString(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
docker/spring-remoting/resources/server/src/main/java/de/qtc/rmg/springremoting/Starter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.qtc.rmg.springremoting; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
|
||
public class Starter | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
SpringApplication.run(SpringRemotingService.class, args); | ||
} | ||
} |