Skip to content

Commit

Permalink
Massive overhaul. Translation from Milmove GO to Lambda Java. Removed…
Browse files Browse the repository at this point in the history
… web server aspects. Beginning to conduct TGET flow internally.
  • Loading branch information
cameroncaci committed Dec 9, 2023
1 parent d90156e commit 599f530
Show file tree
Hide file tree
Showing 20 changed files with 415 additions and 216 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SAM CLI
.aws-sam/

# Compiled class file
*.class

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of Contents
- [Table of Contents](#table-of-contents)
- [Disabled RESTful to SOAP Conversion Capabilities](#disabled-restful-to-soap-conversion-capabilities)
- [API Gateway](#api-gateway)
- [TRDM](#trdm)
- [Whitelisted tables](#whitelisted-tables)
Expand All @@ -21,6 +22,11 @@
- [lastTableUpdate](#lasttableupdate)
- [getTable](#gettable)

# Disabled RESTful to SOAP Conversion Capabilities
This lambda function as of version 1 received an overhaul to function as a cron based lambda function invoked via a timer.

It has the complete capability of providing a REST to SOAP conversion service. This can be of use in the future when other services may need to interface through us. It currently is running as spring boot application which is not necessarily needed for a cron job, but due to time sensitivity it was not phased out when overhauling. It does still offer the future ability to turn back on the RESTful aspects to provide said conversion service, but as of right now it is disabled.

# API Gateway
Please see documentation [here](https://dp3.atlassian.net/wiki/spaces/MT/pages/2275573761/TRDM+Soap+Proxy+API+Gateway+Lambda+Function).

Expand Down
28 changes: 7 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>0.4.2.4</version>
<version>1.0.0.0</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java RESTful interface for SOAP requests to TRDM.</description>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.21.40</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -41,15 +42,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-springboot3</artifactId>
<version>2.0.0-M2</version>
Expand Down Expand Up @@ -90,21 +82,15 @@
<version>4.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java</artifactId>
<version>2.20.162</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-core</artifactId>
<version>2.20.162</version>
<version>2.21.40</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssm</artifactId>
<version>2.20.162</version>
<version>2.21.40</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.milmove.trdmlambda.milmove;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Logger;

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
Expand All @@ -20,7 +17,6 @@
public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
private static final Logger logger = (Logger) LoggerFactory.getLogger(StreamLambdaHandler.class);

static {
try {
logger.info("Initializing Spring Boot application...");
Expand All @@ -31,23 +27,19 @@ public class StreamLambdaHandler implements RequestStreamHandler {
throw new RuntimeException("Could not initialize Spring Boot application", e);
}
}

@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
try {
String inputContent = convertStreamToString(inputStream);
logger.info("Incoming request content: {}", inputContent);

InputStream reprocessedStream = new ByteArrayInputStream(inputContent.getBytes(StandardCharsets.UTF_8));
handler.proxyStream(reprocessedStream, outputStream, context);

logger.info("Lambda request handled successfully.");
} catch (Exception e) {
logger.error("Error processing Lambda request", e);
}
}

private static String convertStreamToString(InputStream is) {
try (Scanner s = new Scanner(is).useDelimiter("\\A")) {
return s.hasNext() ? s.next() : "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.milmove.trdmlambda.milmove;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.milmove.trdmlambda.milmove.handler.TransportationAccountingCodesHandler;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import ch.qos.logback.classic.Logger;

public class TrdmCronLambdaHandler implements RequestHandler<Object, String> {
private static final Logger logger = (Logger) LoggerFactory.getLogger(TrdmCronLambdaHandler.class);
private static final ApplicationContext context;

static {
logger.info("Initializing Spring Boot application...");
context = SpringApplication.run(TrdmRestApplication.class);
logger.info("Spring Boot application initialized successfully.");
}

@Override
public String handleRequest(Object input, Context lambdaContext) {
try {
logger.info("trdm cron job triggered, starting TAC handler and TGET flow");
TransportationAccountingCodesHandler tacHandler = context.getBean(TransportationAccountingCodesHandler.class);
tacHandler.tacCron();

logger.info("starting LOA handler");
logger.info("trdm cron job finished execution");
return "trdm cron job finished execution";
} catch (Exception e) {
logger.error("error executing cron job", e);
return "error in executing cron job";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;

Expand All @@ -21,7 +24,7 @@

import ch.qos.logback.classic.Logger;

@SpringBootApplication()
@SpringBootApplication(exclude = {ServletWebServerFactoryAutoConfiguration.class, WebMvcAutoConfiguration.class})
public class TrdmRestApplication {
private Logger logger = (Logger) LoggerFactory.getLogger(TrdmRestApplication.class);
@Autowired
Expand All @@ -34,7 +37,9 @@ public class TrdmRestApplication {
DecodeTruststore decodeTruststore;

public static void main(String[] args) {
SpringApplication.run(TrdmRestApplication.class, args);
SpringApplication app = new SpringApplication(TrdmRestApplication.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.run(args);
}

@EventListener(ApplicationReadyEvent.class)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.milmove.trdmlambda.milmove.handler;

public class LinesOfAccountingHandler {

}
Loading

0 comments on commit 599f530

Please sign in to comment.