Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Liberty support #283

Merged
merged 13 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ To set up in Visual Studio Code, follow these steps:

You can similarly use GlassFish in Visual Studio Code.


## Getting Started with Open Liberty

To set up the project with Open Liberty and Maven:

* Ensure you are running Java SE 11, or Java SE 17. IBM Semeru is the recommended Java SDK for Open Liberty. Go to [IBM Semeru Runtimes Downloads](https://developer.ibm.com/languages/java/semeru-runtimes/downloads/) and select Java 11 or Java 17 from the version dropdown menu.
* Make sure the `JAVA_HOME`environment variable is set on your system.
* Navigate to the `cargotracker` directory and develop the application with the [Liberty Maven Plugin](https://github.com/OpenLiberty/ci.maven#cimaven--): `mvn -P openliberty liberty:dev`.
* You can safely ignore the shrinkwrap features warning, message-driven bean warning, and the AggregateObjectMapping nested foreign key warning, as they don't affect the application functionality.
* The application starts without any additional errors and you can visit it at the http://localhost:8080/cargo-tracker URL.

To set up the project with Open Liberty in Visual Studio Code:

* Ensure you are running [Visual Studio Code](https://code.visualstudio.com/download) with Java 17.
* Install [Liberty Tools for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=Open-Liberty.liberty-dev-vscode-ext).
* Open the Cargo Tracker project by selecting **Explorer** > **Open Folder**. Select the `cargotracker` directory.
* The `cargo-tracker` project appears under the `LIBERTY DASHBOARD` extension in the Explorer sidebar.
* Right-click the `cargo-tracker` project and select `Start...` to start the application. Type `-P openliberty` in the pop-up entry field and then press the Enter/return key.
* A terminal window in the IDE opens and the Liberty Maven Plugin starts the application. Liberty is running in dev mode.
* You can safely ignore the shrinkwrap features warning, message-driven bean warning, and the AggregateObjectMapping nested foreign key warning, as they don't affect the application functionality.
* You can visit the application at http://localhost:8080/cargo-tracker when you see the following message at the terminal:
```
************************************************************************
[INFO] * Liberty is running in dev mode.
...
[INFO] Source compilation was successful.
[INFO] Tests compilation was successful.
```


## Exploring the Application

After the application runs, it will be available at:
Expand Down
72 changes: 72 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,5 +422,77 @@
</plugins>
</build>
</profile>
<profile>
<id>openliberty</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<db.driverClass>org.hsqldb.jdbc.JDBCDriver</db.driverClass>
<db.jdbcUrl>jdbc:hsqldb:file:./cargo-tracker-data/cargo-tracker-database;create=true</db.jdbcUrl>
</properties>
<dependencies>
<!-- Provided dependencies -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.7.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
m-reza-rahman marked this conversation as resolved.
Show resolved Hide resolved
<artifactId>jersey-server</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-json-binding-provider</artifactId>
<version>6.2.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-sse</artifactId>
<version>3.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Enable liberty-maven plugin -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.8.2</version>
<configuration>
<copyDependencies>
<dependencyGroup>
<location>${project.build.directory}/liberty/wlp/usr/shared/resources</location>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
</dependencyGroup>
</copyDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<excludes>
<exclude>org/**/BookingServiceTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
6 changes: 6 additions & 0 deletions src/main/liberty/config/bootstrap.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
org.apache.el.parser.SKIP_IDENTIFIER_CHECK=true
com.ibm.ws.logging.max.file.size=100
com.ibm.ws.logging.max.files=3
default.http.port=8080
default.https.port=8081
# com.ibm.ws.logging.trace.specification=*=info=enabled:logservice=all:com.ibm.ws.jaxrs*=all:com.ibm.websphere.jaxrs*=all:org.apache.cxf.*=all:EJBContainer=all:Injection=all
142 changes: 142 additions & 0 deletions src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<server description="Cargo Tracker service">

<featureManager>
<feature>batch-2.1</feature>
<feature>beanValidation-3.0</feature>
<feature>cdi-4.0</feature>
<feature>enterpriseBeansLite-4.0</feature>
<feature>enterpriseBeansPersistentTimer-4.0</feature>
<feature>faces-4.0</feature>
<feature>jdbc-4.3</feature>
<feature>jndi-1.0</feature>
<feature>jsonb-3.0</feature>
<feature>mdb-4.0</feature>
<feature>messaging-3.1</feature>
<feature>messagingClient-3.0</feature>
<feature>messagingServer-3.0</feature>
<feature>persistence-3.1</feature>
<feature>restfulWS-3.1</feature>
<feature>xmlBinding-4.0</feature>
</featureManager>

<!--
<logging traceSpecification="*=info:EJBContainer=all:Injection*=all:com.ibm.websphere.jaxrs*=all:com.ibm.ws.jaxrs*=all:logservice*=all:org.apache.cxf.*=all:rarInstall*=all:WAS.j2c*=all:runtime.update*=all:resource*=all"
traceFileName="trace.log"
maxFileSize="0"
maxFiles="0"
traceFormat="BASIC"
/>
-->

<variable defaultValue="8080" name="default.http.port"/>
<variable defaultValue="8081" name="default.https.port"/>

<httpEndpoint host="*" httpPort="${default.http.port}" httpsPort="${default.https.port}" id="defaultHttpEndpoint"/>
<wasJmsEndpoint host="*" id="InboundJmsCommsEndpoint" wasJmsPort="7276" wasJmsSSLPort="9100"/>

<quickStartSecurity userName="usr" userPassword="pwd"/>

<authorization-roles id="com.ibm.ws.batch">
<security-role name="batchAdmin">
<special-subject type="EVERYONE"/>
</security-role>
</authorization-roles>

<connectionManager id="CargoCM" maxPoolSize="400" minPoolSize="1"/>

<messagingEngine id="defaultME">
<queue forceReliability="ReliablePersistent" id="CargoHandledQueue" maxQueueDepth="5000"/>
<queue forceReliability="ReliablePersistent" id="MisdirectedCargoQueue" maxQueueDepth="5000"/>
<queue forceReliability="ReliablePersistent" id="DeliveredCargoQueue" maxQueueDepth="5000"/>
<queue forceReliability="ReliablePersistent" id="HandlingEventRegistrationAttemptQueue" maxQueueDepth="5000"/>
<queue forceReliability="ReliablePersistent" id="RejectedRegistrationAttemptsQueue" maxQueueDepth="5000"/>
</messagingEngine>

<jmsQueueConnectionFactory connectionManagerRef="CargoCM" jndiName="java:app/jms/QueueConnectionFactory">
</jmsQueueConnectionFactory>

<jmsQueue id="CargoHandledQueue" jndiName="jms/CargoHandledQueue">
<properties.wasJms queueName="CargoHandledQueue"/>
</jmsQueue>

<jmsActivationSpec id="cargo-tracker/CargoHandledConsumer">
<properties.wasJms destinationLookup="java:app/jms/CargoHandledQueue" destinationRef="CargoHandledQueue" destinationType="jakarta.jms.Queue" maxConcurrency="200"/>
</jmsActivationSpec>

<jmsQueue id="MisdirectedCargoQueue" jndiName="jms/MisdirectedCargoQueue">
<properties.wasJms queueName="MisdirectedCargoQueue"/>
</jmsQueue>

<jmsActivationSpec id="cargo-tracker/MisdirectedCargoConsumer">
<properties.wasJms destinationRef="MisdirectedCargoQueue" destinationType="jakarta.jms.Queue" maxConcurrency="200"/>
</jmsActivationSpec>

<jmsQueue id="DeliveredCargoQueue" jndiName="jms/DeliveredCargoQueue">
<properties.wasJms queueName="DeliveredCargoQueue"/>
</jmsQueue>

<jmsActivationSpec id="cargo-tracker/DeliveredCargoConsumer">
<properties.wasJms destinationRef="DeliveredCargoQueue" destinationType="jakarta.jms.Queue" maxConcurrency="200"/>
</jmsActivationSpec>

<jmsQueue id="HandlingEventRegistrationAttemptQueue" jndiName="jms/HandlingEventRegistrationAttemptQueue">
<properties.wasJms queueName="HandlingEventRegistrationAttemptQueue"/>
</jmsQueue>

<jmsActivationSpec id="cargo-tracker/HandlingEventRegistrationAttemptConsumer">
<properties.wasJms destinationRef="HandlingEventRegistrationAttemptQueue" destinationType="jakarta.jms.Queue" maxConcurrency="200"/>
</jmsActivationSpec>

<jmsQueue id="RejectedRegistrationAttemptsQueue" jndiName="jms/RejectedRegistrationAttemptsQueue">
<properties.wasJms queueName="RejectedRegistrationAttemptsQueue"/>
</jmsQueue>

<jmsActivationSpec id="cargo-tracker/RejectedRegistrationAttemptsConsumer">
<properties.wasJms destinationRef="RejectedRegistrationAttemptsQueue" destinationType="jakarta.jms.Queue" maxConcurrency="200"/>
</jmsActivationSpec>

<jdbcDriver id="dbDriver" libraryRef="dbLib"/>

<library id="dbLib">
<fileset dir="${shared.resource.dir}" includes="hsqldb*.jar"/>
</library>

<dataSource id="cargoTrackerDataStore" jndiName="jdbc/CargoTrackerDatabase">
<jdbcDriver libraryRef="dbLib"/>
<properties URL="jdbc:hsqldb:mem:CargoTrackerDB" password="pwd" user="usr"/>
</dataSource>

<databaseStore id="EJBPersistentTimerStore" keyGenerationStrategy="SEQUENCE" tablePrefix="WLP2_"/>
<persistentExecutor enableTaskExecution="true" id="EJBPersistentTimerExecutor" ignore.minimum.for.test.use.only="true" initialPollDelay="-1" retryInterval="300s" retryLimit="-1" taskStoreRef="EJBPersistentTimerStore">
</persistentExecutor>

<databaseStore id="ejbTimerDataStore" keyGenerationStrategy="SEQUENCE"/>
<dataSource id="DefaultDataSource" jdbcDriverRef="dbDriver">
<properties URL="jdbc:hsqldb:mem:EJBTimerDS" password="pwd" user="usr"/>
</dataSource>

<ejbContainer>
<timerService persistentExecutorRef="EJBPersistentTimerExecutor"/>
<timerService missedPersistentTimerAction="ONCE"/>
</ejbContainer>

<webApplication contextRoot="cargo-tracker" location="cargo-tracker.war">
<classloader commonLibraryRef="dbLib"/>
<web-bnd moduleName="cargo-tracker">
<env-entry name="java:app/configuration/GraphTraversalUrl" value="http://localhost:8080/cargo-tracker/rest/graph-traversal/shortest-path"/>
</web-bnd>
<application-bnd>
<security-role name="batchAdmin">
<special-subject type="EVERYONE"/>
</security-role>
</application-bnd>
</webApplication>

<keyStore id="defaultKeyStore" password="password"/>
<applicationMonitor updateTrigger="mbean"/>
<applicationManager autoExpand="true"/>
<httpSession cookieName="COOKIE"/>
<channelfw chainQuiesceTimeout="60s"/>

</server>
gkwan-ibm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.eclipse.cargotracker.rest;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import org.eclipse.pathfinder.api.TransitEdge;
import org.eclipse.pathfinder.api.TransitPath;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class GraphTraversalServiceIT {

@Test
public void testShortestPath() {

SimpleDateFormat f = new SimpleDateFormat("MMddyyyy");
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
String deadline = f.format(nextYear.getTime());

Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/graph-traversal/shortest-path");
WebTarget shortPathTarget = webTarget.queryParam("origin", new Object[] { "USNYC" }).queryParam("destination", new Object[] { "CNHKG" }).queryParam("deadline", new Object[] { deadline });
Response response = shortPathTarget.request(new String[] { "application/json" }).get();
Assertions.assertEquals(200, response.getStatus(), "Unexpected response code");

String responseStr = (String)response.readEntity(String.class);
Jsonb jsonb = JsonbBuilder.create();
TransitPath[] transitPaths = (TransitPath[]) jsonb.fromJson(responseStr, TransitPath[].class);
Assertions.assertTrue((transitPaths.length > 0), "Expected at least 1 transit path.");
for (TransitPath p : transitPaths) {
List<TransitEdge> edges = p.getTransitEdges();
Assertions.assertTrue((edges.size() > 0), "Expected at least 1 transit edge.");
}
}

}

gkwan-ibm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.eclipse.cargotracker.rest;

import jakarta.json.bind.JsonbBuilder;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Properties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class HandlingReportServiceIT {

@Test
public void testHandlingRreports() {

SimpleDateFormat f = new SimpleDateFormat("M/dd/yyyy");
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
String completionDate = f.format(nextYear.getTime());

Properties p = new Properties();
p.put("completionTime", completionDate + " 3:3 a.m.");
p.put("trackingId", "ABC123");
p.put("eventType", "LOAD");
p.put("unLocode", "CNHGH");
p.put("voyageNumber", "0100S");
String jsonParms = JsonbBuilder.create().toJson(p);

Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target("http://localhost:8080/cargo-tracker/rest/handling/reports");
Response response = webTarget.request().post(Entity.entity(jsonParms, "application/json"));
Assertions.assertEquals(204, response.getStatus(), "Unexpected response code");
}

}

Loading