springify forward

master
io42630 1 year ago
parent 12ecc2b0d3
commit a86d2c3c59

@ -0,0 +1,4 @@
FROM eclipse-temurin:17-alpine
COPY /target/forward-0.1.jar /usr/local/lib/forward.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/forward.jar"]

@ -0,0 +1,9 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/forward:0.1 .

@ -1,10 +0,0 @@
#!/bin/bash
version="0.1"
file="target/forward-${version}.war"
groupId="com.olexyn.misp.forward"
artifactId="forward"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=war -DgeneratePom=true

@ -1,31 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.forward</groupId>
<parent>
<groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>spring-boot-jdk17-0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<artifactId>forward</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>forward Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<packaging>jar</packaging>
<name>forward</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>helper</artifactId>
@ -35,90 +32,28 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.0.v201112011016</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>com.olexyn.min.http.server</groupId>
<artifactId>min-http-server</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.28.v20200408</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.28.v20200408</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.28.v20200408</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version>
<!-- for some godforsaken reason this is required. -->
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -0,0 +1,13 @@
package com.olexyn.misp.forward;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class App {
public static void main(String... args) {
SpringApplication.run(App.class, args);
}
}

@ -1,12 +1,14 @@
package com.olexyn.misp.forward;
package com.olexyn.misp.forward.web;
import com.olexyn.misp.helper.JsonHelper;
import com.olexyn.misp.helper.Ride;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@ -14,7 +16,8 @@ import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
public class Forward extends HttpServlet {
@RestController
public class Forward {
private static final long WAIT_FOR_USER_REQUEST = 500;
@ -23,10 +26,10 @@ public class Forward extends HttpServlet {
private final Map<Long, Ride> loaded = new HashMap<>();
@Override
@GetMapping
public void doGet(HttpServletRequest request, HttpServletResponse response) {
Thread handleGetRequestThread = new Thread(() -> { handleGetRequest(request, response); });
Thread handleGetRequestThread = new Thread(() -> handleGetRequest(request, response));
handleGetRequestThread.setName("handleGetRequestThread");
handleGetRequestThread.start();
try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { }
@ -40,7 +43,7 @@ public class Forward extends HttpServlet {
* Wait for Ride to appear in `loaded`. This happens due to POST (Ride)(Request)(Data) from `reverse`.
* Finally send OK (Data) to `user`.
*/
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
private void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
try {
final Ride ride;
@ -99,7 +102,7 @@ public class Forward extends HttpServlet {
}
@Override
@PostMapping
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String payload = IOUtils.toString(request.getReader());
@ -138,7 +141,7 @@ public class Forward extends HttpServlet {
* Handle POST (Ride)(Request)(Data)
* Move the Ride from `booked` to `loaded`, so it can be picked up by OK (Data) of GET (Request).
*/
protected void handlePostRideRequestData(HttpServletRequest request, HttpServletResponse response, String payload) {
private void handlePostRideRequestData(HttpServletRequest request, HttpServletResponse response, String payload) {
final Ride ride = new Ride(payload);
@ -157,7 +160,7 @@ public class Forward extends HttpServlet {
* Handle POST (Available).
* Send current # of available Rides to `reverse`.
*/
protected void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) {
private void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) {
JSONObject obj = new JSONObject().put("available", available.size());
@ -177,7 +180,7 @@ public class Forward extends HttpServlet {
* Wait till a GET (Request) arrives from `user`.
* Return OK (Ride)(Request) to `reverse`.
*/
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) {
private void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) {
try {
final Ride ride = new Ride(payload);

@ -1,22 +0,0 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>misp-fwd</display-name>
<servlet>
<servlet-name>misp-fwd</servlet-name>
<servlet-class>com.olexyn.misp.forward.Forward</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>misp-fwd</servlet-name>
<url-pattern>/forward</url-pattern>
</servlet-mapping>
</web-app>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 617 B

@ -1,20 +0,0 @@
<html>
<head>
<title>misp-fwd</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/io42630.png">
</td>
</tr>
<tr>
<td>
<h1>misp-fwd</h1>
</td>
</tr>
</table>
</body>
</html>
Loading…
Cancel
Save