~ overhaul for simple debugging.

pull/1/head
Ivan Olexyn 5 years ago
parent bd7e8482fb
commit 8c33c46e7e

@ -0,0 +1,13 @@
#!/bin/bash
cd ./forward
./install-locally.sh
cd ..
cd ./helper
./install-locally.sh
cd ..
cd ./mirror
./install-locally.sh
cd ..
cd ./reverse
./install-locally.sh
cd ..

@ -0,0 +1,208 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.embedded</groupId>
<artifactId>embedded</artifactId>
<version>0.1</version>
<name>embedded</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>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.min.http.server</groupId>
<artifactId>min-http-server</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>misp-helper</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
<version>9.4.28.v20200408</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>misp-mirror</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.rev</groupId>
<artifactId>misp-rev</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.reverse</groupId>
<artifactId>reverse</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.fwd</groupId>
<artifactId>misp-fwd</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.forward</groupId>
<artifactId>forward</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_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-jar-plugin</artifactId>
<version>3.0.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>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -0,0 +1,30 @@
package com.olexyn.misp.embedded;
import com.olexyn.min.http.server.MinJettyServer;
import com.olexyn.misp.forward.Forward;
import com.olexyn.misp.mirror.Mirror;
/**
* Hello world!
*/
public class Embedded implements Runnable {
@Override
public void run() {
MinJettyServer server = new MinJettyServer();
server.PORT = 8090;
server.MAX_THREADS = 100;
server.MIN_THREADS = 10;
server.IDLE_TIMEOUT = 120;
server.addServletWithMapping("/mirror", Mirror.class);
server.addServletWithMapping("/app", Mirror.class);
server.addServletWithMapping("/forward", Forward.class);
server.start();
}
}

@ -0,0 +1,19 @@
package com.olexyn.misp.embedded;
import com.olexyn.misp.reverse.ReverseApp;
public class RunAll {
public static void main(String... args) throws InterruptedException {
Thread serverT = new Thread(new Embedded());
serverT.start();
Thread.sleep(2000);
Thread reverseT = new Thread(new ReverseApp());
reverseT.start();
}
}

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
version="0.1" version="0.1"
file="target/misp-fwd-${version}.war" file="target/forward-${version}.war"
groupId="com.olexyn.misp.fwd" groupId="com.olexyn.misp.forward"
artifactId="misp-fwd" artifactId="forward"

@ -4,19 +4,19 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.test.proxy</groupId> <groupId>com.olexyn.misp.forward</groupId>
<artifactId>test-proxy</artifactId> <artifactId>forward</artifactId>
<version>0.1</version> <version>0.1</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>test-proxy Maven Webapp</name> <name>forward Maven Webapp</name>
<!-- FIXME change it to the project's website --> <!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <url>http://www.example.com</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
@ -27,60 +27,67 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>com.olexyn.misp.helper</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>misp-helper</artifactId>
<version>4.0.1</version> <version>0.1</version>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>commons-io</groupId>
<artifactId>jetty-servlet</artifactId> <artifactId>commons-io</artifactId>
<version>9.4.28.v20200408</version> <version>2.6</version>
<scope>provided</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>jetty-util</artifactId> <artifactId>javax.servlet</artifactId>
<version>9.4.28.v20200408</version> <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>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId> <artifactId>jetty-server</artifactId>
<version>9.4.28.v20200408</version> <version>9.4.28.v20200408</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>com.olexyn.min.http.server</groupId>
<artifactId>junit-jupiter</artifactId> <artifactId>min-http-server</artifactId>
<version>RELEASE</version> <version>0.1</version>
<scope>test</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-test-helper</artifactId> <artifactId>jetty-util</artifactId>
<scope>test</scope> <version>9.4.28.v20200408</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-test-helper</artifactId> <artifactId>jetty-servlets</artifactId>
<version>5.3</version> <version>9.4.28.v20200408</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId> <artifactId>jetty-servlet</artifactId>
<version>9.4.28.v20200408</version> <version>9.4.28.v20200408</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-io</artifactId> <artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version> <version>9.4.28.v20200408</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<plugin> <plugin>
@ -95,12 +102,6 @@
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.8.0</version>
<configuration>
<!-- or whatever version you use -->
<source>11</source>
<target>11</target>
<verbose>true</verbose>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>

@ -1,4 +1,4 @@
package com.olexyn.misp.fwd; package com.olexyn.misp.forward;
import com.olexyn.misp.helper.JsonHelper; import com.olexyn.misp.helper.JsonHelper;
import com.olexyn.misp.helper.Ride; import com.olexyn.misp.helper.Ride;
@ -15,7 +15,7 @@ import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class FwdProxy extends HttpServlet { public class Forward extends HttpServlet {
protected static final String MISP_CLIENT_URL = "http://localhost:9090/mispclient/core"; protected static final String MISP_CLIENT_URL = "http://localhost:9090/mispclient/core";
@ -189,6 +189,10 @@ public class FwdProxy extends HttpServlet {
* add Ride to AvailableRides * add Ride to AvailableRides
*/ */
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException { protected void handlePostRide(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException {
String jsonPayload = IOUtils.toString(request.getReader()); String jsonPayload = IOUtils.toString(request.getReader());
final Ride ride = new Ride(jsonPayload); final Ride ride = new Ride(jsonPayload);
@ -199,7 +203,7 @@ public class FwdProxy extends HttpServlet {
// ID is final/threadsafe // ID is final/threadsafe
while (!(booked.containsKey(ride.getID()))) { while (!(booked.containsKey(ride.getID()))) {
Thread.sleep(50);
} }
synchronized (booked) { synchronized (booked) {
@ -213,5 +217,6 @@ public class FwdProxy extends HttpServlet {
writer.write(ride.json()); writer.write(ride.json());
writer.flush(); writer.flush();
writer.close(); writer.close();
} }
} }

@ -11,7 +11,7 @@
<servlet> <servlet>
<servlet-name>misp-fwd</servlet-name> <servlet-name>misp-fwd</servlet-name>
<servlet-class>com.olexyn.misp.fwd.FwdProxy</servlet-class> <servlet-class>com.olexyn.misp.forward.Forward</servlet-class>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>

Before

Width:  |  Height:  |  Size: 617 B

After

Width:  |  Height:  |  Size: 617 B

@ -5,18 +5,18 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.helper</groupId> <groupId>com.olexyn.misp.helper</groupId>
<artifactId>misp-helper</artifactId> <artifactId>helper</artifactId>
<version>0.1</version> <version>0.1</version>
<name>misp-helper</name> <name>helper</name>
<description>A simple misp-helper.</description> <description>A simple helper.</description>
<!-- FIXME change it to the project's website --> <!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <url>http://www.example.com</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>

@ -5,18 +5,18 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.mirror</groupId> <groupId>com.olexyn.misp.mirror</groupId>
<artifactId>misp-mirror</artifactId> <artifactId>mirror</artifactId>
<version>0.1</version> <version>0.1</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>misp-mirror Maven Webapp</name> <name>mirror Maven Webapp</name>
<!-- FIXME change it to the project's website --> <!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <url>http://www.example.com</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>

Before

Width:  |  Height:  |  Size: 617 B

After

Width:  |  Height:  |  Size: 617 B

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

@ -1,90 +0,0 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.rev</groupId>
<artifactId>misp-rev</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>misp-rev 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>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>misp-helper</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<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>
</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>

@ -1,16 +0,0 @@
package com.olexyn.misp.rev;
import com.olexyn.misp.helper.Ride;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject;
public class ConnectionHelper {
}

@ -1,12 +0,0 @@
package com.olexyn.misp.rev;
public class Main {
public static void main(String... args){
new RevProxy();
}
}

@ -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-rev</display-name>
<servlet>
<servlet-name>misp-rev</servlet-name>
<servlet-class>com.olexyn.misp.rev.RevProxy</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>misp-rev</servlet-name>
<url-pattern>/core</url-pattern>
</servlet-mapping>
</web-app>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 617 B

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

@ -1,16 +0,0 @@
#### About
* Mockup for easy debugging.
* Mock *requests* and *responses*.
* Teleport them between *actors*.
* There are 4 actors which are mocked:
* `AppMock` : the App hosted on *localhost*.
* `ClientMock` : the *mispclient* Servlet.
* `BridgeMock` : the *mispbridge* Servlet.
* `UserMock` : the user agent accessing the *mispbridge* from the internet.
* `MockSet` knows all 4 actors, all the 4 actors know `MockSet`.
* Thus all 4 actors know each other.
<br>
##### Threads in Mock
![](threads-in-mock.png)

@ -1,99 +0,0 @@
package com.olexyn.misp.mock;
import com.olexyn.misp.helper.Ride;
import com.olexyn.misp.mock.exchange.ExchangeMock;
import com.olexyn.misp.adapter.Adapter;
import javax.servlet.ServletException;
import java.io.IOException;
/**
* Wraps a ClientServlet so it can be debugged easily, i.e. without running Tomcat.
*/
public class AdapterMock extends Adapter {
private MockSet mockSet;
public AdapterMock(MockSet mockSet) {
super();
mockSet.adapterMock = this;
this.mockSet = mockSet;
}
/**
* Send POST (Ride).
* Parse response.
*/
@Override
protected Ride doSendPostRide(Ride ride) throws IOException, InterruptedException, ServletException {
// Mock Exchange
final ExchangeMock exchange = new ExchangeMock();
exchange.request.setMethod("POST");
exchange.request.setContentType("application/json");
exchange.request.setContent(ride.json().getBytes());
synchronized (exchange) {
// Mock POST (Ride)
exchange.notify();
mockSet.bridgeMock.doPost(exchange.request, exchange.response);
exchange.wait();
exchange.notify();
}
// handle OK (Ride)(Request)
return new Ride(exchange.response.getContentAsString());
}
/**
* Send GET (Request) to App.
* Parse response.
*/
@Override
protected String doSendGetRequest(String request) throws IOException {
// Mock Exchange
final ExchangeMock exchange = new ExchangeMock();
exchange.request.setMethod("GET");
exchange.request.setContent(request.getBytes());
synchronized (exchange) {
// Mock GET (Request)
exchange.notify();
mockSet.appMock.doGet(exchange.request, exchange.response);
// handle OK (Data)
exchange.notify();
}
return exchange.response.getContentAsString();
}
/**
* Send GET (Ride)(Request)(Data).
* Parse response.
*/
@Override
protected void doSendGetRideRequest(Ride ride) throws IOException, InterruptedException {
// Mock Exchange
final ExchangeMock exchange = new ExchangeMock();
exchange.request.setMethod("GET");
exchange.request.setContentType("application/json");
exchange.request.setContent(ride.json().getBytes());
synchronized (exchange) {
// Mock GET (Ride)(Request)(Data)
exchange.notify();
mockSet.bridgeMock.doGet(exchange.request, exchange.response);
exchange.wait();
exchange.notify();
}
}
}

@ -1,20 +0,0 @@
package com.olexyn.misp.mock;
/**
* Pass the MockSet.
* Provide a Runnable.
*/
public class AdapterRunnable implements Runnable {
private MockSet mockSet;
public AdapterRunnable(MockSet mockSet){
super();
this.mockSet = mockSet;
}
@Override
public void run() {
new AdapterMock(mockSet);
}
}

@ -1,84 +0,0 @@
package com.olexyn.misp.mock;
import com.olexyn.misp.mock.exchange.ExchangeMock;
import com.olexyn.misp.mock.exchange.RequestMock;
import com.olexyn.misp.bridge.BridgeServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class BridgeMock extends BridgeServlet {
public BridgeMock(MockSet mockSet) {
super();
mockSet.bridgeMock = this;
}
/**
* handle GET (Request)<br>
* - wait for availableRides to have an entry <br>
* - move move Ride to deliveredRides <br>
* - wait for Ride to have Data <br>
* - respond to the original request with Data
*/
@Override
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException {
final ExchangeMock exchange;
synchronized (exchange = ((RequestMock) request).exchange) {
super.handleGetRequest(request,response);
exchange.notify();
}
}
/**
* handle GET (Ride)(Data)
* if Ride in ForwardedRequest
* remove Ride from ForwardedRequest
* add Ride to NewData
* send OK (Ride)(Data)
* remove Ride from NewData
* add Ride to ForwardedData
* send OK (EOL)
* remove Ride from ForwardedData
* add Ride to EOL
*/
protected void handleGetRideRequestData(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException {
final ExchangeMock exchange;
synchronized (exchange = ((RequestMock) request).exchange) {
super.handleGetRideRequestData(request,response);
exchange.notify();
}
}
/**
* handle POST (Ride)
* - wait for Ride to be booked
* - send OK to Client
*/
@Override
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException {
final ExchangeMock exchange;
synchronized (exchange = ((RequestMock) request).exchange) {
super.handlePostRide(request,response);
exchange.notify();
}
}
}

@ -1,21 +0,0 @@
package com.olexyn.misp.mock;
/**
* Pass the MockSet.
* Provide a Runnable.
*/
public class BridgeRunnable implements Runnable {
MockSet mockSet;
public BridgeRunnable(MockSet mockSet){
super();
this.mockSet = mockSet;
}
@Override
public void run() {
new BridgeMock(mockSet);
}
}

@ -1,42 +0,0 @@
package com.olexyn.misp.mock;
import com.olexyn.misp.mock.actor.AppMock;
import com.olexyn.misp.mock.actor.UserMock;
public class Main {
public static void main(String... args){
MockSet mockSet = new MockSet();
Runnable publicRunnable = new UserMock(mockSet);
Runnable bridgeRunable = new BridgeRunnable(mockSet);
Runnable adapterRunnable = new AdapterRunnable(mockSet);
//Runnable clientRunnable = new ClientRunnable(mockSet);
Runnable appRunnable = new AppMock(mockSet);
Thread userThread = new Thread(publicRunnable);
Thread bridgeThread = new Thread(bridgeRunable);
Thread adapterThread = new Thread(adapterRunnable);
//Thread clientThread = new Thread(clientRunnable);
Thread appThread = new Thread(appRunnable);
userThread.setName("userThread");
userThread.start();
bridgeThread.setName("bridgeThread");
bridgeThread.start();
adapterThread.setName("adapterThread");
adapterThread.start();
//clientThread.setName("clientThread");
//clientThread.start();
appThread.setName("appThread");
appThread.start();
}
}

@ -1,11 +0,0 @@
package com.olexyn.misp.mock;
import com.olexyn.misp.mock.actor.AppMock;
import com.olexyn.misp.mock.actor.UserMock;
public class MockSet {
public UserMock userMock;
public BridgeMock bridgeMock;
public AdapterMock adapterMock;
public AppMock appMock;
}

@ -1,57 +0,0 @@
package com.olexyn.misp.mock.actor;
import com.olexyn.misp.mock.MockSet;
import com.olexyn.misp.mock.exchange.ExchangeMock;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Generic Runnable.
* Serves as basis for Actors that are not Servlets.
*/
public abstract class ActorRunnable implements Runnable {
List<ExchangeMock> exchanges = new ArrayList<>();
protected MockSet mockSet;
public ActorRunnable(MockSet mockSet){
this.mockSet = mockSet;
}
@Override
public void run() {
//
}
public void processExchange(ExchangeMock exchange) throws IOException, ServletException {
if (exchange.request.getMethod().equalsIgnoreCase("GET")) {
doGet(exchange.request, exchange.response);
} else if (exchange.request.getMethod().equalsIgnoreCase("POST")) {
doPost(exchange.request, exchange.response);
}
}
public abstract void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException;
public abstract void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException;
}

@ -1,56 +0,0 @@
package com.olexyn.misp.mock.actor;
import com.olexyn.misp.mock.MockSet;
import com.olexyn.misp.mock.exchange.ExchangeMock;
import com.olexyn.misp.mock.exchange.RequestMock;
import org.apache.commons.io.IOUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class AppMock extends ActorRunnable {
public AppMock(MockSet mockSet) {
super(mockSet);
mockSet.appMock = this;
}
@Override
public void run() {
while (true) {
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
RequestMock mockRequest = (RequestMock) request;
ExchangeMock exchange = mockRequest.exchange;
synchronized (exchange) {
String parsedRequest = IOUtils.toString(request.getReader());
String dataString = "DATA-" + parsedRequest;
exchange.response.setStatus(200);
PrintWriter writer = exchange.response.getWriter();
writer.write(dataString);
writer.flush();
writer.close();
exchange.notify();
}
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
}
}

@ -1,91 +0,0 @@
package com.olexyn.misp.mock.actor;
import com.olexyn.misp.mock.MockSet;
import com.olexyn.misp.mock.exchange.ExchangeMock;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class UserMock extends ActorRunnable {
final String longRequest;
int requestCount = 0;
public UserMock(MockSet mockSet){
super(mockSet);
mockSet.userMock = this;
StringBuilder sb = new StringBuilder();
for (int i=0;i<100;i++){
sb.append("foo");
}
longRequest = sb.toString();
}
@Override
public void run() {
while (true){
try {
sendGetRequest();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
}
/**
* # send GET (Request)
* Generated by Loop
*/
void sendGetRequest() throws IOException, InterruptedException {
// Mock Exchange
ExchangeMock exchange = new ExchangeMock();
exchange.request.setMethod("GET");
//exchange.request.setContentType("application/json");
//String requestBody = longRequest+"-"+(++requestCount);
String requestBody = "REQUEST-"+(++requestCount);
String jsonString = "{\"request\":\""+requestBody+ "\"}";
jsonString = "asdfasdfa";
exchange.request.setContent(jsonString.getBytes());
synchronized (exchange){
// Mock GET (Request)
exchange.notify();
mockSet.bridgeMock.doGet(exchange.request,exchange.response);
exchange.wait();
// handle OK (Data)
String data = exchange.response.getContentAsString();
System.out.println(data + " of "+requestBody);
exchange.notify();
}
}
}

@ -1,50 +0,0 @@
package com.olexyn.misp.mock.exchange;
import java.util.ArrayList;
import java.util.List;
/**
* How "exchange" mocks an exchange:<br>
* <br>
* An "exchange" corresponds to request & reply pair.<br>
* - i.e. a GET & OK pair.<br>
* Steps:<br>
* 1. new Exchange()<br>
* 2. set properties of .request<br>
* 3. "send" request by using exchange.notify(); recipient.doGet();<br>
* 4. recipient does someting with request<br>
* - - recipient sets proerties of .response<br>
* - - recipient sends reply using exchange.notify();<br>
* 5. "receive" response by using exchange.wait();
*/
public class ExchangeMock {
public static List<ExchangeMock> exchangeList = new ArrayList<>();
private static int next_id=0;
public int id;
public RequestMock request =new RequestMock(this);
public ResponseMock response = new ResponseMock(this);
public ExchangeMock(){
id = next_id++;
exchangeList.add(this);
}
}

@ -1,84 +0,0 @@
package com.olexyn.misp.mock.exchange;
import org.springframework.mock.web.MockHttpServletRequest;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.util.Collection;
/**
* - Contains reference to ExchangeMock
* - Rest is dummy code.
*/
public class RequestMock extends MockHttpServletRequest implements HttpServletRequest {
public final ExchangeMock exchange;
public RequestMock(ExchangeMock exchange){
super();
this.exchange = exchange;
}
@Override
public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException {
return false;
}
@Override
public void login(String s, String s1) throws ServletException {
}
@Override
public void logout() throws ServletException {
}
@Override
public Collection<Part> getParts() throws IOException, ServletException {
return null;
}
@Override
public Part getPart(String s) throws IOException, ServletException {
return null;
}
@Override
public ServletContext getServletContext() {
return null;
}
@Override
public AsyncContext startAsync() throws IllegalStateException {
return null;
}
@Override
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException {
return null;
}
@Override
public boolean isAsyncStarted() {
return false;
}
@Override
public boolean isAsyncSupported() {
return false;
}
@Override
public AsyncContext getAsyncContext() {
return null;
}
@Override
public DispatcherType getDispatcherType() {
return null;
}
}

@ -1,209 +0,0 @@
package com.olexyn.misp.mock.exchange;
import org.springframework.mock.web.MockHttpServletResponse;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Locale;
import java.util.Set;
/**
* - Contains reference to ExchangeMock
* - Rest is dummy code.
*/
public class ResponseMock extends MockHttpServletResponse implements HttpServletResponse {
public ExchangeMock exchange;
public ResponseMock(ExchangeMock exchange){
super();
this.exchange = exchange;
}
@Override
public void addCookie(Cookie cookie) {
}
@Override
public boolean containsHeader(String s) {
return false;
}
@Override
public String encodeURL(String s) {
return null;
}
@Override
public String encodeRedirectURL(String s) {
return null;
}
@Override
public String encodeUrl(String s) {
return null;
}
@Override
public String encodeRedirectUrl(String s) {
return null;
}
@Override
public void sendError(int i, String s) throws IOException {
}
@Override
public void sendError(int i) throws IOException {
}
@Override
public void sendRedirect(String s) throws IOException {
}
@Override
public void setDateHeader(String s, long l) {
}
@Override
public void addDateHeader(String s, long l) {
}
@Override
public void setHeader(String s, String s1) {
}
@Override
public void addHeader(String s, String s1) {
}
@Override
public void setIntHeader(String s, int i) {
}
@Override
public void addIntHeader(String s, int i) {
}
@Override
public void setStatus(int i) {
}
@Override
public void setStatus(int i, String s) {
}
@Override
public int getStatus() {
return 0;
}
@Override
public String getHeader(String s) {
return null;
}
@Override
public List getHeaders(String s) {
return null;
}
@Override
public Set getHeaderNames() {
return null;
}
@Override
public String getCharacterEncoding() {
return null;
}
@Override
public String getContentType() {
return null;
}
@Override
public ServletOutputStream getOutputStream() {
return null;
}
@Override
public PrintWriter getWriter() throws UnsupportedEncodingException {
return super.getWriter();
}
@Override
public void setCharacterEncoding(String s) {
}
@Override
public void setContentLength(int i) {
}
@Override
public void setContentType(String s) {
}
@Override
public void setBufferSize(int i) {
}
@Override
public int getBufferSize() {
return 0;
}
@Override
public void flushBuffer() {
}
@Override
public void resetBuffer() {
}
@Override
public boolean isCommitted() {
return false;
}
@Override
public void reset() {
}
@Override
public void setLocale(Locale locale) {
}
@Override
public Locale getLocale() {
return null;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 33 KiB

@ -4,8 +4,8 @@
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1030</x> <x>1210</x>
<y>630</y> <y>480</y>
<w>90</w> <w>90</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -16,8 +16,8 @@ lt=-</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>630</x> <x>810</x>
<y>630</y> <y>480</y>
<w>120</w> <w>120</w>
<h>70</h> <h>70</h>
</coordinates> </coordinates>
@ -29,8 +29,8 @@ modem</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>800</x> <x>980</x>
<y>630</y> <y>480</y>
<w>100</w> <w>100</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -42,8 +42,8 @@ layer=-1</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1030</x> <x>1210</x>
<y>670</y> <y>520</y>
<w>90</w> <w>90</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -54,12 +54,12 @@ bg=#90CAF9</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>800</x> <x>980</x>
<y>670</y> <y>520</y>
<w>100</w> <w>100</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
<panel_attributes>misp.fwd <panel_attributes>forward
bg=#B39DDB bg=#B39DDB
layer=-1</panel_attributes> layer=-1</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -67,8 +67,8 @@ layer=-1</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>550</x> <x>730</x>
<y>720</y> <y>570</y>
<w>280</w> <w>280</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
@ -80,8 +80,8 @@ Generated by Loop</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>880</x> <x>1060</x>
<y>760</y> <y>610</y>
<w>200</w> <w>200</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -93,12 +93,12 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>470</x> <x>650</x>
<y>670</y> <y>520</y>
<w>100</w> <w>100</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
<panel_attributes>misp.rev <panel_attributes>reverse
bg=#B39DDB bg=#B39DDB
layer=-1</panel_attributes> layer=-1</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -106,8 +106,8 @@ layer=-1</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>550</x> <x>730</x>
<y>870</y> <y>720</y>
<w>280</w> <w>280</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
@ -119,8 +119,8 @@ GET (Ride)(Request)
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>880</x> <x>1060</x>
<y>890</y> <y>740</y>
<w>200</w> <w>200</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -132,8 +132,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>550</x> <x>730</x>
<y>930</y> <y>780</y>
<w>280</w> <w>280</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -144,8 +144,8 @@ OK (Ride)</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>270</x> <x>450</x>
<y>670</y> <y>520</y>
<w>80</w> <w>80</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -156,8 +156,8 @@ bg=#90CAF9</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>310</x> <x>490</x>
<y>800</y> <y>650</y>
<w>190</w> <w>190</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -169,8 +169,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>310</x> <x>490</x>
<y>850</y> <y>700</y>
<w>190</w> <w>190</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -182,8 +182,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>550</x> <x>730</x>
<y>780</y> <y>630</y>
<w>280</w> <w>280</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -194,8 +194,8 @@ OK (Ride)(Request)</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>270</x> <x>450</x>
<y>630</y> <y>480</y>
<w>300</w> <w>300</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -206,8 +206,8 @@ lt=-</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>240</x> <x>420</x>
<y>600</y> <y>450</y>
<w>910</w> <w>910</w>
<h>400</h> <h>400</h>
</coordinates> </coordinates>
@ -219,8 +219,8 @@ layer=-10</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>810</x> <x>990</x>
<y>740</y> <y>590</y>
<w>80</w> <w>80</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -233,8 +233,8 @@ transparency=0</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>480</x> <x>660</x>
<y>740</y> <y>590</y>
<w>80</w> <w>80</w>
<h>60</h> <h>60</h>
</coordinates> </coordinates>
@ -247,8 +247,8 @@ transparency=0</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>810</x> <x>990</x>
<y>780</y> <y>630</y>
<w>80</w> <w>80</w>
<h>110</h> <h>110</h>
</coordinates> </coordinates>
@ -262,8 +262,8 @@ layer=1</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>480</x> <x>660</x>
<y>800</y> <y>650</y>
<w>80</w> <w>80</w>
<h>70</h> <h>70</h>
</coordinates> </coordinates>
@ -276,8 +276,8 @@ transparency=0</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>480</x> <x>660</x>
<y>870</y> <y>720</y>
<w>80</w> <w>80</w>
<h>80</h> <h>80</h>
</coordinates> </coordinates>
@ -290,8 +290,8 @@ transparency=0</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>810</x> <x>990</x>
<y>890</y> <y>740</y>
<w>80</w> <w>80</w>
<h>60</h> <h>60</h>
</coordinates> </coordinates>
@ -304,8 +304,8 @@ transparency=0</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1060</x> <x>1240</x>
<y>690</y> <y>540</y>
<w>30</w> <w>30</w>
<h>310</h> <h>310</h>
</coordinates> </coordinates>
@ -316,8 +316,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>300</x> <x>480</x>
<y>690</y> <y>540</y>
<w>30</w> <w>30</w>
<h>310</h> <h>310</h>
</coordinates> </coordinates>
@ -328,8 +328,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1060</x> <x>1240</x>
<y>780</y> <y>630</y>
<w>20</w> <w>20</w>
<h>130</h> <h>130</h>
</coordinates> </coordinates>
@ -342,8 +342,8 @@ layer=4</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>300</x> <x>480</x>
<y>820</y> <y>670</y>
<w>20</w> <w>20</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
@ -356,8 +356,8 @@ layer=4</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>840</x> <x>1020</x>
<y>690</y> <y>540</y>
<w>30</w> <w>30</w>
<h>310</h> <h>310</h>
</coordinates> </coordinates>
@ -369,8 +369,8 @@ layer=-4</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>510</x> <x>690</x>
<y>690</y> <y>540</y>
<w>30</w> <w>30</w>
<h>310</h> <h>310</h>
</coordinates> </coordinates>

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

@ -4,18 +4,18 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.fwd</groupId> <groupId>com.olexyn.misp.reverse</groupId>
<artifactId>misp-fwd</artifactId> <artifactId>reverse</artifactId>
<version>0.1</version> <version>0.1</version>
<packaging>war</packaging>
<name>misp-fwd Maven Webapp</name> <name>reverse</name>
<!-- FIXME change it to the project's website --> <!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <url>http://www.example.com</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
@ -31,36 +31,22 @@
<version>0.1</version> <version>0.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<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> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20190722</version> <version>20190722</version>
<scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin> <plugin>
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version> <version>3.0.2</version>
@ -68,20 +54,14 @@
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.8.0</version>
<configuration>
<!-- or whatever version you use -->
<source>11</source>
<target>11</target>
<verbose>true</verbose>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version> <version>2.22.1</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-war-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version> <version>3.0.2</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-install-plugin</artifactId> <artifactId>maven-install-plugin</artifactId>
@ -91,6 +71,15 @@
<artifactId>maven-deploy-plugin</artifactId> <artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version> <version>2.8.2</version>
</plugin> </plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>

@ -0,0 +1,26 @@
package com.olexyn.misp.reverse;
import com.olexyn.misp.helper.Ride;
import java.io.IOException;
class GetRequestRunnable implements Runnable {
final private Reverse reverse;
public GetRequestRunnable(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
while (true) {
synchronized (reverse.booked) {
if (reverse.booked.size() > 0) {
final Ride ride = reverse.booked.entrySet().iterator().next().getValue();
try { reverse.sendGetRequest(ride); } catch (IOException ignored) {}
}
}
}
}
}

@ -0,0 +1,26 @@
package com.olexyn.misp.reverse;
import com.olexyn.misp.helper.Ride;
import java.io.IOException;
class GetRideRequestDataRunnable implements Runnable {
final private Reverse reverse;
public GetRideRequestDataRunnable(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
while (true) {
synchronized (reverse.loaded) {
if (reverse.loaded.size() > 0) {
final Ride ride = reverse.loaded.entrySet().iterator().next().getValue();
try { reverse.sendGetRideRequestData(ride); } catch (IOException ignored) {}
}
}
}
}
}

@ -0,0 +1,25 @@
package com.olexyn.misp.reverse;
import java.io.IOException;
class PostRideRunnable implements Runnable {
final private Reverse reverse;
public PostRideRunnable(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
while (true) {
synchronized (reverse.available) {
if (reverse.available.size() < reverse.AVAILABLE_RIDES_OVERHEAD_TRIGGER) {
for (int i = 0; i < reverse.AVAILABLE_RIDES_OVERHEAD; i++) {
try {reverse.sendPostRide();} catch (IOException ignored) {}
}
}
}
}
}
}

@ -0,0 +1,3 @@
* Run from `ReverseApp` :
* as `main()`
* or as `Runnable` from somewhere else.

@ -1,4 +1,4 @@
package com.olexyn.misp.rev; package com.olexyn.misp.reverse;
import com.olexyn.misp.helper.Ride; import com.olexyn.misp.helper.Ride;
@ -13,13 +13,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class RevProxy { public class Reverse {
protected static final String MISP_BRIDGE_URL = "http://localhost:9090/mispbridge/core"; public String FORWARD_URL = "http://localhost:8090/bridge";
protected static final String APP_URL = "http://localhost:9090/mirror/core"; public String APP_URL = "http://localhost:8090/app";
public static final int AVAILABLE_RIDES_OVERHEAD_TRIGGER = 4; public int AVAILABLE_RIDES_OVERHEAD_TRIGGER = 1;
public static final int AVAILABLE_RIDES_OVERHEAD = 8; public int AVAILABLE_RIDES_OVERHEAD = 2;
public final Map<Long, Ride> available = new HashMap<>(); public final Map<Long, Ride> available = new HashMap<>();
@ -27,8 +27,7 @@ public class RevProxy {
public final Map<Long, Ride> loaded = new HashMap<>(); public final Map<Long, Ride> loaded = new HashMap<>();
public RevProxy() { public void start() {
Thread postRideThread = new Thread(new PostRideRunnable(this)); Thread postRideThread = new Thread(new PostRideRunnable(this));
postRideThread.setName("postRideThread"); postRideThread.setName("postRideThread");
postRideThread.start(); postRideThread.start();
@ -49,7 +48,7 @@ public class RevProxy {
synchronized (available) { available.put(ride.getID(), ride); } synchronized (available) { available.put(ride.getID(), ride); }
final String result = send("POST", MISP_BRIDGE_URL, ride.json()); final String result = send("POST", FORWARD_URL, ride.json());
synchronized (available) { synchronized (available) {
available.remove(ride.getID()); available.remove(ride.getID());
@ -73,7 +72,7 @@ public class RevProxy {
void sendGetRideRequestData(Ride ride) throws IOException { void sendGetRideRequestData(Ride ride) throws IOException {
send("GET", MISP_BRIDGE_URL, ride.json()); send("GET", FORWARD_URL, ride.json());
synchronized (loaded) {loaded.remove(ride.getID()); } synchronized (loaded) {loaded.remove(ride.getID()); }
} }
@ -87,10 +86,15 @@ public class RevProxy {
connection.setDoOutput(true); connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
if (body != null) {
outputStream.writeBytes(body); outputStream.writeBytes(body);
}
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
int i = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String out; String out;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -100,70 +104,7 @@ public class RevProxy {
} }
}
class PostRideRunnable implements Runnable {
final private RevProxy adapter;
public PostRideRunnable(RevProxy adapter) {
this.adapter = adapter;
}
@Override
public void run() {
while (true) {
synchronized (adapter.available) {
if (adapter.available.size() < RevProxy.AVAILABLE_RIDES_OVERHEAD_TRIGGER) {
for (int i = 0; i < RevProxy.AVAILABLE_RIDES_OVERHEAD; i++) {
try {adapter.sendPostRide();} catch (IOException ignored) {}
}
}
}
}
}
}
class GetRequestRunnable implements Runnable {
final private RevProxy adapter;
public GetRequestRunnable(RevProxy adapter) {
this.adapter = adapter;
}
@Override
public void run() {
while (true) {
synchronized (adapter.booked) {
if (adapter.booked.size() > 0) {
final Ride ride = adapter.booked.entrySet().iterator().next().getValue();
try { adapter.sendGetRequest(ride); } catch (IOException ignored) {}
}
}
}
}
} }
class GetRideRequestDataRunnable implements Runnable {
final private RevProxy adapter;
public GetRideRequestDataRunnable(RevProxy adapter) {
this.adapter = adapter;
}
@Override
public void run() {
while (true) {
synchronized (adapter.loaded) {
if (adapter.loaded.size() > 0) {
final Ride ride = adapter.loaded.entrySet().iterator().next().getValue();
try { adapter.sendGetRideRequestData(ride); } catch (IOException ignored) {}
}
}
}
}
}

@ -0,0 +1,30 @@
package com.olexyn.misp.reverse;
public class ReverseApp implements Runnable {
public static void main(String... args) {
new ReverseApp().doRun();
}
@Override
public void run() {
doRun();
}
private void doRun() {
Reverse reverse = new Reverse();
reverse.FORWARD_URL = "http://localhost:8090/forward";
reverse.APP_URL = "http://localhost:8090/app";
reverse.AVAILABLE_RIDES_OVERHEAD_TRIGGER = 1;
reverse.AVAILABLE_RIDES_OVERHEAD = 2;
reverse.start();
}
}

@ -1,113 +0,0 @@
<?xml version="1.0"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- =============================================================== -->
<!-- Documentation of this file format can be found at: -->
<!-- https://www.eclipse.org/jetty/documentation/current/ -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default -->
<!-- configuration files. -->
<!-- -->
<!-- For a description of the configuration mechanism, see the -->
<!-- output of: -->
<!-- java -jar start.jar -? -->
<!-- =============================================================== -->
<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server" -->
<!-- Other configuration files may also configure the "Server" -->
<!-- ID, in which case they are adding configuration to the same -->
<!-- instance. If other configuration have a different ID, they -->
<!-- will create and configure another instance of Jetty. -->
<!-- Consult the javadoc of o.e.j.server.Server for all -->
<!-- configuration that may be set here. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Arg name="threadpool"><Ref refid="threadPool"/></Arg>
<Call name="addBean">
<Arg><Ref refid="byteBufferPool"/></Arg>
</Call>
<!-- =========================================================== -->
<!-- Add shared Scheduler instance -->
<!-- =========================================================== -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler">
<Arg name="name"><Property name="jetty.scheduler.name"/></Arg>
<Arg name="daemon" type="boolean"><Property name="jetty.scheduler.daemon" default="false" /></Arg>
<Arg name="threads" type="int"><Property name="jetty.scheduler.threads" default="-1" /></Arg>
</New>
</Arg>
</Call>
<!-- =========================================================== -->
<!-- Http Configuration. -->
<!-- This is a common configuration instance used by all -->
<!-- connectors that can carry HTTP semantics (HTTP, HTTPS, etc.)-->
<!-- It configures the non wire protocol aspects of the HTTP -->
<!-- semantic. -->
<!-- -->
<!-- This configuration is only defined here and is used by -->
<!-- reference from other XML files such as jetty-http.xml, -->
<!-- jetty-https.xml and other configuration files which -->
<!-- instantiate the connectors. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.HttpConfiguration -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme"><Property name="jetty.httpConfig.secureScheme" default="https" /></Set>
<Set name="securePort"><Property name="jetty.httpConfig.securePort" deprecated="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize"><Property name="jetty.httpConfig.outputBufferSize" deprecated="jetty.output.buffer.size" default="32768" /></Set>
<Set name="outputAggregationSize"><Property name="jetty.httpConfig.outputAggregationSize" deprecated="jetty.output.aggregation.size" default="8192" /></Set>
<Set name="requestHeaderSize"><Property name="jetty.httpConfig.requestHeaderSize" deprecated="jetty.request.header.size" default="8192" /></Set>
<Set name="responseHeaderSize"><Property name="jetty.httpConfig.responseHeaderSize" deprecated="jetty.response.header.size" default="8192" /></Set>
<Set name="sendServerVersion"><Property name="jetty.httpConfig.sendServerVersion" deprecated="jetty.send.server.version" default="true" /></Set>
<Set name="sendDateHeader"><Property name="jetty.httpConfig.sendDateHeader" deprecated="jetty.send.date.header" default="false" /></Set>
<Set name="headerCacheSize"><Property name="jetty.httpConfig.headerCacheSize" default="1024" /></Set>
<Set name="delayDispatchUntilContent"><Property name="jetty.httpConfig.delayDispatchUntilContent" deprecated="jetty.delayDispatchUntilContent" default="true"/></Set>
<Set name="maxErrorDispatches"><Property name="jetty.httpConfig.maxErrorDispatches" default="10"/></Set>
<Set name="blockingTimeout"><Property deprecated="jetty.httpConfig.blockingTimeout" name="jetty.httpConfig.blockingTimeout.DEPRECATED" default="-1"/></Set>
<Set name="persistentConnectionsEnabled"><Property name="jetty.httpConfig.persistentConnectionsEnabled" default="true"/></Set>
<Set name="requestCookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.requestCookieCompliance" deprecated="jetty.httpConfig.cookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="responseCookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.responseCookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="multiPartFormDataCompliance"><Call class="org.eclipse.jetty.server.MultiPartFormDataCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.multiPartFormDataCompliance" default="RFC7578"/></Arg></Call></Set>
</New>
<!-- =========================================================== -->
<!-- Set the default handler structure for the Server -->
<!-- A handler collection is used to pass received requests to -->
<!-- both the ContextHandlerCollection, which selects the next -->
<!-- handler by context path and virtual host, and the -->
<!-- DefaultHandler, which handles any requests not handled by -->
<!-- the context handlers. -->
<!-- Other handlers may be added to the "Handlers" collection, -->
<!-- for example the jetty-requestlog.xml file adds the -->
<!-- RequestLogHandler after the default handler -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<!-- =========================================================== -->
<!-- extra server options -->
<!-- =========================================================== -->
<Set name="stopAtShutdown"><Property name="jetty.server.stopAtShutdown" default="true"/></Set>
<Set name="stopTimeout"><Property name="jetty.server.stopTimeout" default="5000"/></Set>
<Set name="dumpAfterStart"><Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/></Set>
<Set name="dumpBeforeStop"><Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/></Set>
</Configure>

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

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="server" class="org.eclipse.jetty.server.Server">
<New id="ServletContextHandler" class="org.eclipse.jetty.servlet.ServletContextHandler">
<Set name="servletHandler">
<New id="servletHandler" class="org.eclipse.jetty.servlet.ServletHandler">
<Call id="proxyHolder" name="addServletWithMapping">
<Arg>org.eclipse.jetty.servlets.ProxyServlet$Transparent</Arg>
<Arg>/proxy/*</Arg>
<Call name="setInitParameter">
<Arg>maxThreads</Arg>
<Arg>
<Property name="jetty.proxy.maxThreads" default="128"/>
</Arg>
</Call>
<Call name="setInitParameter">
<Arg>maxConnections</Arg>
<Arg>
<Property name="jetty.proxy.maxConnections" default="256"/>
</Arg>
</Call>
<Call name="setInitParameter">
<Arg>idleTimeout</Arg>
<Arg>
<Property name="jetty.proxy.idleTimeout" default="30000"/>
</Arg>
</Call>
<Call name="setInitParameter">
<Arg>timeout</Arg>
<Arg>
<Property name="jetty.proxy.timeout" default="60000"/>
</Arg>
</Call>
<Call name="setInitParameter">
<Arg>ProxyTo</Arg>
<Arg>http://localhost:8080/misp-mirror</Arg>
</Call>
<Call name="setInitParameter">
<Arg>Prefix</Arg>
<Arg>/proxy</Arg>
</Call>
</Call>
</New>
</Set>
</New>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.HandlerList">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<Ref id="ServletContextHandler"></Ref>
</Item>
</Array>
</Set>
</New>
</Set>
</Configure>

@ -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-proxy</display-name>
<servlet>
<servlet-name>test-proxy</servlet-name>
<servlet-class>com.olexyn.test.proxy.ProxyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test-proxy</servlet-name>
<url-pattern>/core</url-pattern>
</servlet-mapping>
</web-app>

@ -1,20 +0,0 @@
<html>
<head>
<title>test-proxy</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/io42630.png">
</td>
</tr>
<tr>
<td>
<h1>test-proxy</h1>
</td>
</tr>
</table>
</body>
</html>

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Loading…
Cancel
Save