Skip to content

Commit

Permalink
Finalize RequestParameterized Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Feb 5, 2023
1 parent ba7459f commit 1fff7d0
Show file tree
Hide file tree
Showing 17 changed files with 648 additions and 225 deletions.
10 changes: 2 additions & 8 deletions DeFi-Data-Engine/Api-Handler/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=17
7 changes: 7 additions & 0 deletions DeFi-Data-Engine/Api-Handler/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM maven:3.8.6-eclipse-temurin-17-alpine

ENV APP_NAME api-handler

COPY ./ ./
RUN mvn clean package spring-boot:repackage -Dmaven.skip.test=true
CMD ["java", "-jar", "target/api-handler-0.0.1.jar"]
109 changes: 43 additions & 66 deletions DeFi-Data-Engine/Api-Handler/pom.xml
Original file line number Diff line number Diff line change
@@ -1,84 +1,61 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ApiHandler</groupId>
<artifactId>ApiHandler</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>

<dependencies>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.application</groupId>
<artifactId>api-handler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>api-handler</name>
<description>Lightweight application for retrieving generalized api calls.</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
<version>20220924</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<!-- plugin to run test cases from maven -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<log4j.configuration>log4j.xml</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<properties>
<java.version>17</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.application.apihandler;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@EnableAutoConfiguration
@EnableWebMvc
@Configuration
@ComponentScan
public class ApiHandlerApplication {

public static void main(String[] args) {
SpringApplication.run(ApiHandlerApplication.class, args);
}

public final static void output(String data) {
System.out.println(data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.application.apihandler;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.stream.external.request.core.RequestManager;

import jakarta.annotation.PostConstruct;

@RestController
@RequestMapping(path = {"/api/v1"})
public class Controller {

@PostConstruct
public void initialize() {
try {
RequestManager.initialize();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException | URISyntaxException | IOException e) {
e.printStackTrace();
}
}

@PostMapping
@CrossOrigin
@RequestMapping(path = {"/request"})
public ResponseEntity<String> handleRequest(@RequestParam String name) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.stream.external.requester;
package org.stream.external.request.core;

import java.io.IOException;
import java.util.HashMap;
Expand All @@ -15,23 +15,42 @@

public abstract class RequestFramework {
private final String name;
private final String url;
private String url;
private final HashMap<String, String> properties;
private final HashMap<String, String> headers;
private final HashMap<String, String> tags;
private final String[] recursive_location;
private final String recursive_replacement;
private final String[] path;

// default constructor used for templating
public RequestFramework() {
this.name = null;
this.properties = null;
this.headers = null;
this.tags = null;
this.recursive_location = null;
this.recursive_replacement = null;
this.path = null;
}

public RequestFramework(String name, String url, HashMap<String, String> properties, HashMap<String, String> headers,
HashMap<String, String> tags, String[] path) {
HashMap<String, String> tags, String[] recursive_location, String recursive_replacement, String[] path) {
this.name = name;
this.url = url;
this.properties = properties;
this.headers = headers;
this.tags = tags;
this.recursive_location = recursive_location;
this.recursive_replacement = recursive_replacement;
this.path = path;
}

protected final Request getRequest(HashMap<String, String> properties, HashMap<String, String> headers) {
return this.getRequest(this.url, properties, headers);
}

protected final Request getRequest(String url, HashMap<String, String> properties, HashMap<String, String> headers) {
HashMap<String, String> all_properties = new HashMap<String, String>();
HashMap<String, String> all_headers = new HashMap<String, String>();

Expand All @@ -50,7 +69,7 @@ protected final Request getRequest(HashMap<String, String> properties, HashMap<S

// define builder
Builder builder = new Builder();
StringBuilder url_builder = new StringBuilder(this.url);
StringBuilder url_builder = new StringBuilder(url);
if(!all_properties.isEmpty())
url_builder.append("?");

Expand Down Expand Up @@ -116,6 +135,18 @@ public final String getName() {
return name;
}

public final String getUrl() {
return url;
}

public final String[] getRecursiveLocation() {
return recursive_location;
}

public final String getRecursiveReplacement() {
return recursive_replacement;
}

public final String[] getPath() {
return path;
}
Expand All @@ -126,12 +157,12 @@ public final void request(HashMap<String, String> properties, HashMap<String, St
HashMap<String, String> cloned_properties = (HashMap<String, String>) properties.clone();
HashMap<String, String> cloned_headers = (HashMap<String, String>) headers.clone();

process(cloned_properties, cloned_headers);
process(url, cloned_properties, cloned_headers);
}

protected void process(HashMap<String, String> properties, HashMap<String, String> headers) {
protected void process(String url, HashMap<String, String> properties, HashMap<String, String> headers) {
OkHttpClient client = new OkHttpClient();
Request request = getRequest(properties, headers);
Request request = getRequest(url, properties, headers);
if(request == null) {
System.err.println("Malformed request, killing process.");
return;
Expand All @@ -156,13 +187,13 @@ protected void process(HashMap<String, String> properties, HashMap<String, Strin
// send to specific request handler
try {
String body = response.body().string().toString();
process(body, properties, headers);
handle(body, properties, headers);
} catch(Exception e) {
e.printStackTrace();
}
}

protected abstract void process(String json, HashMap<String, String> properties, HashMap<String, String> headers);
protected abstract void handle(String json, HashMap<String, String> properties, HashMap<String, String> headers);

public abstract String getType();

Expand Down
Loading

0 comments on commit 1fff7d0

Please sign in to comment.