Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: ["**"]
pull_request:
branches: ["**"]

jobs:
build:
name: Build & test (Java 21)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Temurin JDK 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: maven

# Compiles all modules, runs the JUnit 5 regression tests and builds the
# jar/wars/ear. `package` stops before the integration-test phases, so the
# Liberty runtime is not required for CI.
- name: Build and test
run: mvn -B clean package
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: java

jdk:
- openjdk8
- openjdk21

env:
- TEST_COMMAND="gradle clean build"
- TEST_COMMAND="mvn clean install"
- TEST_COMMAND="mvn clean package"

script:
- (eval "$TEST_COMMAND")
107 changes: 107 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# DayTrader3 — Java 8 → Java 21 Migration Plan

Jira: **JEFF-DT3-JAVA21** (Java 21 upgrade for DayTrader3)

This document is the written migration plan produced during repository discovery, before
code changes. It captures the current state, the Java 8 / Java EE 6 assumptions that break
on a modern JDK, the required vs. optional work, and the high-risk areas on the trade path.

## 1. Architecture summary (as-is)

DayTrader3 is a Java EE 6 benchmark modelling an online stock-trading system (login,
portfolio, quotes, buy/sell orders, holdings). It is a Maven **and** Gradle multi-module
reactor targeting IBM WebSphere Liberty.

| Module | Packaging | Role |
| --- | --- | --- |
| `daytrader3-ee6-ejb` | jar (`dt-ejb.jar`) | Core business logic + JPA entities. EJB session beans (`TradeSLSBBean`), MDBs, and a JDBC "direct" mode (`TradeDirect`). Domain beans: `AccountDataBean`, `AccountProfileDataBean`, `QuoteDataBean`, `HoldingDataBean`, `OrderDataBean`, `MarketSummaryDataBean`; utilities `FinancialUtils`, `TradeConfig`. |
| `daytrader3-ee6-web` | war (`web.war`) | Servlets, JSPs, JSF managed beans (portfolio/quote/account UI). |
| `daytrader3-ee6-rest` | war (`Rest.war`) | JAX-RS (JSR-311) sample address-book endpoints using JAXB binding. |
| `daytrader3-ee6` | ear | Assembles the EJB jar + two wars; copies the Derby driver; wires the Liberty plugin for functional tests. |
| `daytrader3-ee6-wlpcfg` | pom | Liberty server configuration (`server.xml`, features). |

Runtime data store: **Apache Derby** (embedded), shipped as a copied driver jar.

Persistence/transactions are container-managed (JPA 2.0 + JTA 1.1). Messaging uses JMS 1.1
MDBs. All `javax.*` EE APIs (`javax.ejb`, `javax.jms`, `javax.persistence`, `javax.servlet`,
`javax.faces`, `javax.ws.rs`) are supplied by the container at runtime and by `provided`
Maven dependencies at compile time — they are **not** part of the JDK, so JDK removals do
not affect them.

## 2. Java 8 / legacy assumptions that break on Java 21

| # | Assumption | Impact on Java 21 | Required action |
| --- | --- | --- | --- |
| A1 | Compiler `source/target = 1.7` (Maven parent `java7-parent`; Gradle `sourceCompatibility = 1.7`) | javac 21 no longer supports `-source/-target 7` (min is 8). Build fails immediately. | Set release/source/target to **21** in Maven and Gradle. |
| A2 | REST module imports `javax.xml.bind.*` (JAXB) | **JAXB was removed from the JDK in Java 11** (JEP 320, `java.se.ee`). Compile fails. | Add `javax.xml.bind:jaxb-api` (+ `jaxb-runtime` at runtime) as explicit dependencies, keeping the `javax` namespace so no source changes are needed. |
| A3 | `javax.annotation.*` (`@PostConstruct`, `@Resource`) in EJB + web modules | **Common Annotations removed from the JDK in Java 11** (JEP 320). Compile fails. | Add `javax.annotation:javax.annotation-api` as a `provided` dependency (namespace preserved). |
| A4 | Legacy Maven plugin versions inherited from `java7-parent` (compiler, surefire, ear, war) | Old plugin versions can fail under a Java 21 toolchain and cannot run JUnit 5. | Pin modern plugin versions via `pluginManagement` in the root POM. |
| A5 | Apache **Derby 10.10.1.1** (2013) | Runs on old JDKs only and carries known CVEs (see §5). Newer Derby lines require newer JDKs. | Upgrade to **Derby 10.17.1.0** (the current line, which requires Java 21). |
| A6 | CI pinned to `openjdk8` (Travis) | Does not exercise Java 21. | Add a GitHub Actions workflow building + testing on **Temurin 21**; keep Travis JDK aligned. |

Notes on things that are **fine** and deliberately left unchanged:
- Deprecated boxing constructors (`new Integer(...)`, `new BigDecimal(double)`, etc., ~30
sites) still compile on Java 21 (deprecation warnings only). Rewriting them is optional
style churn and is intentionally **out of scope** to protect trade-path semantics.
- No usage of removed CORBA / JAX-WS / `sun.*` internal APIs was found.
- The `javax` EE namespace is retained end-to-end (no Jakarta `jakarta.*` rename), because
the target runtime (WebSphere Liberty EE6/`javaee-6.0`) expects `javax`. A Jakarta EE
migration is a separate, larger effort and would change runtime behavior — out of scope.

## 3. Required migration work vs. optional refactoring

**Required (in this PR):**
1. Compiler/runtime targets → Java 21 (Maven + Gradle).
2. Add JDK-removed EE APIs back as explicit dependencies (JAXB, Common Annotations).
3. Modern Maven plugin versions (compiler, surefire, ear, war).
4. Derby 10.10.1.1 → 10.17.1.0 (CVE remediation + Java 21 support).
5. Regression tests (none exist today) around order creation, quote retrieval, buy/sell
execution math, and holdings valuation.
6. CI on Java 21; refreshed docs.

**Optional (explicitly deferred, not done here):**
- Jakarta EE 9+ (`javax.*` → `jakarta.*`) namespace migration.
- Replacing deprecated boxing/`BigDecimal(double)` constructors.
- Replacing the raw-JDBC "direct" mode or the JMS MDB workload.
- Virtual threads / records / other Java 21 language adoption in domain code.

## 4. High-risk, trade-path changes to review carefully

- **Derby major upgrade (10.10 → 10.17).** Derby 10.15+ is modularized (`derby`,
`derbyshared`, `derbytools`, `derbyclient`). The embedded driver class and SQL dialect
used by `TradeDirect` are unchanged, but the runtime now needs the companion jars on the
server classpath. Money math (balances, holdings, order fees) must be re-verified against
a running server. This is the single highest-risk item for externally observable behavior.
- **Order fee / balance arithmetic.** `TradeConfig.getOrderFee` (flat `24.95` for BUY/SELL)
and `FinancialUtils` gain/holdings computations drive user-visible P&L. Covered by new
regression tests; must not change.
- **JAXB provider at runtime.** The REST address-book sample relies on a JAXB
implementation being present; on a modular JDK it must come from a dependency, not the
platform. Low business impact (sample endpoint), but verify the REST war still deploys.

## 5. Security findings addressed

Apache Derby 10.10.1.1 → 10.17.1.0 remediates:
- **CVE-2015-1832** — XXE in Derby (fixed 10.12.1.1).
- **CVE-2018-1313** — information disclosure via crafted SQL (fixed 10.14.2.0).
- **CVE-2022-46337** — LDAP-injection / auth bypass, "alwaysAllow" (fixed 10.16.1.1).

10.17.1.0 is at or above every fixed line above.

## 6. Verification strategy

- `mvn clean package` on JDK 21 compiles all modules, runs the new JUnit 5 unit tests, and
builds the jar/wars/ear — **without** requiring a Liberty download (the Liberty plugin
goals are bound to the integration-test phases, which `package` does not reach).
- Full end-to-end trade-path validation (login → quote → buy → portfolio → sell) runs
against a live Liberty + Derby server and is **not** part of unit CI; it remains a manual
functional test (see README) and is called out in the human-review checklist.

## 7. Rollback guidance

The change set is confined to build files (`pom.xml`, `build.gradle`), a Derby version bump,
added test sources, CI config, and docs — no domain/business logic is modified.
- To roll back: revert this PR (single squashed commit) and redeploy the previous EAR built
on Java 8; the schema and Derby data format are unchanged, so no data migration is needed.
- Partial rollback: if only Derby is problematic, revert the `derby.version` property to the
prior value while keeping the Java 21 compiler settings.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sample.daytrader3 [![Build Status](https://travis-ci.org/WASdev/sample.daytrader3.svg?branch=master)](https://travis-ci.org/WASdev/sample.daytrader3)
# sample.daytrader3 [![CI](https://github.com/COG-GTM/sample.daytrader3/actions/workflows/ci.yml/badge.svg)](https://github.com/COG-GTM/sample.daytrader3/actions/workflows/ci.yml)

# Java EE6: DayTrader3 Sample

Expand All @@ -9,13 +9,33 @@ This sample contains the DayTrader 3 benchmark, which is an application built ar

DayTrader is an end-to-end benchmark and performance sample application. It provides a real world Java EE workload.

## Runtime requirements

This sample builds and runs on **Java 21** (LTS). The build targets Java 21 in both
Maven and Gradle, and the embedded Apache Derby driver has been upgraded to a
current, security-patched line. The application still targets the Java EE 6 (`javax.*`)
programming model on WebSphere Liberty. See [MIGRATION.md](/MIGRATION.md) for the full
Java 8 → Java 21 migration notes.

## Getting Started

Browse the code to see what it does, or build and run it yourself:
* [Building and running on the command line using Maven and Gradle](/docs/Using-cmd-line.md)
* [Building and running using Eclipse and WebSphere Development Tools (WDT)](/docs/Using-WDT.md)
* [Downloading WAS Liberty](/docs/Downloading-WAS-Liberty.md)

### Quick build & test

```bash
# Requires JDK 21 on PATH / JAVA_HOME
mvn clean package
```

This compiles all modules, runs the JUnit 5 regression tests (order creation, quote
retrieval, buy/sell execution math, holdings valuation) and assembles the EAR. It does
not require a Liberty runtime; the Liberty functional tests remain bound to the
integration-test phases.

Once the server has been started, go to [http://localhost:9083/daytrader](http://localhost:9083/daytrader) to interact with the sample.

## Notice
Expand Down
10 changes: 9 additions & 1 deletion daytrader3-ee6-ejb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ dependencies {
compile group: 'javax.ejb', name: 'ejb-api', version: '3.0'
compile group: 'javax.jms', name: 'jms-api', version: '1.1-rev-1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
// Common Annotations removed from the JDK in Java 11 (JEP 320).
compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.10.2'
}

sourceCompatibility = 1.7
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

test {
useJUnitPlatform()
}
15 changes: 15 additions & 0 deletions daytrader3-ee6-ejb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@
<version>1.1</version>
<scope>provided</scope>
</dependency>
<!-- Common Annotations (@PostConstruct/@Resource) removed from the JDK
in Java 11 (JEP 320); provided by the container at runtime. -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax.annotation.version}</version>
<scope>provided</scope>
</dependency>
<!-- Test-only: JUnit 5 regression tests for the trading domain. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibm.websphere.samples.daytrader;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.math.BigDecimal;
import java.util.Date;

import javax.ejb.EJBException;

import org.junit.jupiter.api.Test;

/**
* Regression tests for the login/logout behaviour exposed to users.
*/
public class AccountDataBeanTest {

private AccountDataBean accountWithProfile(String userId, String password) {
AccountDataBean account = new AccountDataBean(0, 0, new Date(), new Date(),
new BigDecimal("1000000"), new BigDecimal("1000000"), userId);
AccountProfileDataBean profile =
new AccountProfileDataBean(userId, password, "full name", "addr", "e@mail", "1-2-3-4");
account.setProfile(profile);
return account;
}

@Test
public void successfulLoginIncrementsLoginCountAndSetsLastLogin() {
AccountDataBean account = accountWithProfile("uid:0", "secret");
account.login("secret");
assertEquals(1, account.getLoginCount());
assertNotNull(account.getLastLogin());
}

@Test
public void wrongPasswordThrowsAndDoesNotIncrementLogin() {
AccountDataBean account = accountWithProfile("uid:0", "secret");
assertThrows(EJBException.class, () -> account.login("wrong"));
assertEquals(0, account.getLoginCount());
}

@Test
public void missingProfileThrowsOnLogin() {
AccountDataBean account = new AccountDataBean(0, 0, new Date(), new Date(),
new BigDecimal("1000000"), new BigDecimal("1000000"), "uid:0");
assertThrows(EJBException.class, () -> account.login("secret"));
}

@Test
public void logoutIncrementsLogoutCount() {
AccountDataBean account = accountWithProfile("uid:0", "secret");
account.logout();
account.logout();
assertEquals(2, account.getLogoutCount());
}
}
Loading
Loading