Skip to content
Merged
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
5 changes: 3 additions & 2 deletions .docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Kotlin caller, in [testing/](../testing/README.md).

The client sends through a JDK `java.net.http.HttpClient` it builds itself: no redirects followed, no cookies
(one client serves many merchants' tokens), a 10-second connect timeout. Two hooks change it and keep that,
including that `close()` closes it:
including that `close()` closes it (on Java 21 and newer; Java 17's `HttpClient` has no `close()` and stops its
threads once nothing references it):

```java
MonetaClient.builder()
Expand Down Expand Up @@ -112,7 +113,7 @@ balance and transactions exactly as the JVM does; CI runs it on every pull reque
## Micronaut

[`moneta-api-micronaut`](../modules/moneta-api-micronaut/README.md) is compiled against Micronaut 4.10 for
Java 21 and runs on 5 too; Micronaut 5 itself needs Java 25. Its BOMs pull the client's Jackson to 3.2.3 (5.2.5),
Java 17 and runs on 5 too; Micronaut 5 itself needs Java 25. Its BOMs pull the client's Jackson to 3.2.3 (5.2.5),
or leave Jackson 3 alone beside their Jackson 2 with `jackson-annotations` 2.21 (4.10.14), and both work.
`make build` checks both in [testing/](../testing/README.md).

Expand Down
2 changes: 1 addition & 1 deletion .docs/plan/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ behaves, as far as it is known, is [moneta-api.md](../moneta-api.md).
- **The client reads** accounts and transactions, pending and booked, with symbols, message, counterparty and
`incoming()`, and tells a card payment from a transfer with `method()`. Checked against a live business account
on 2026-11-06 and 2026-11-07, a card payment pending on 2026-11-07 and booked on 2026-11-10.
- **Tested** on Java 21 and 25, Spring Boot 3.5.12, 3.5.16, 4.0.0 and 4.1.2, a Kotlin caller, and Jackson 3.0.4.
- **Tested** on Java 17, 21 and 25, Spring Boot 3.5.12, 3.5.16, 4.0.0 and 4.1.2, a Kotlin caller, and Jackson 3.0.4.
- **The developer portal registration** (MONETA API – TPP) was approved. It gives the specification and a
sandbox; production stays the merchant's token, as without a PSD2 licence the portal offers no more
([access](../access.md)).
Expand Down
3 changes: 2 additions & 1 deletion .docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ An interrupted thread throws `CancellationException` instead, interrupt flag kep

`MonetaClient.builder()`: `baseUri(…)`, `requestTimeout(…)`, `partner(…)` (headers MONETA does not ask for yet),
`configureHttpClient(…)` for a proxy or mTLS, `decorateHttpClient(…)` for tracing or metrics
([examples](compatibility.md#your-own-http-stack)). `close()` releases the HTTP client it made.
([examples](compatibility.md#your-own-http-stack)). `close()` releases the HTTP client it made (from Java 21; on 17
it is released once nothing references it).
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
# Every JDK the jar promises to run on. It is compiled once per job on 25, for release 21; only the tests
# move. 17 is not here: release 21 classes do not load on it.
# Every LTS the jar promises to run on. It is compiled once per job on 25, for release 17; only the tests
# move. 11 is not here: Jackson 3, Spring Boot 3, Quarkus and Micronaut 4 all start at 17.
matrix:
jdk: [21, 25]
jdk: [17, 21, 25]
steps:
- uses: actions/checkout@v7
# The last one listed becomes JAVA_HOME, which Gradle runs on; the matrix JDK is found as a toolchain.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Czech bank MONETA Money Bank lets its business clients, sole traders include
[its API](https://www.moneta.cz/zivnostnici-a-firmy/api) for free: an application reads their accounts and
transactions, and can enter payments, with a token they issue in Internet Banka. No PSD2 licence is needed.

This is a client for that API, **MONETA API**, for Java 21+ and Kotlin projects, with a Spring Boot starter, a
This is a client for that API, **MONETA API**, for Java 17+ and Kotlin projects, with a Spring Boot starter, a
Play Framework module, a Micronaut module and a Quarkus extension. It reads accounts and transactions so far; payments are not covered
yet. Its only dependencies are Jackson and JSpecify.

Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
kotlin("jvm") version "2.4.21" apply false
}

// Compiled once, for release 21, on whatever JDK runs Gradle; the tests run on the JDK -PtestsJdk names, so CI's
// Compiled once, for release 17, on whatever JDK runs Gradle; the tests run on the JDK -PtestsJdk names, so CI's
// matrix checks the jars on each JDK they support. Without it they run on Gradle's own.
val testsJdk = providers.gradleProperty("testsJdk")

Expand All @@ -24,15 +24,17 @@ allprojects {
repositories {
mavenCentral()
}
// The café and peek are applications, never published: they keep Java 21 and test on Gradle's own JDK.
val app = path.startsWith(":examples:") || path.startsWith(":tools:")
tasks.withType<JavaCompile>().configureEach {
// Built on any current JDK, usable from Java 21.
options.release = 21
// Built on any current JDK, usable from Java 17: the oldest LTS Jackson 3 and every supported framework run on.
options.release = if (app) 21 else 17
}
plugins.withType<JavaPlugin> {
val toolchains = extensions.getByType<JavaToolchainService>()
tasks.withType<Test>().configureEach {
useJUnitPlatform()
if (testsJdk.isPresent) {
if (testsJdk.isPresent && !app) {
javaLauncher = toolchains.launcherFor { languageVersion = JavaLanguageVersion.of(testsJdk.get()) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion llms.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# moneta-api-java

> A Java 21+ and Kotlin client for MONETA API, the free API of the Czech bank MONETA Money Bank for business
> A Java 17+ and Kotlin client for MONETA API, the free API of the Czech bank MONETA Money Bank for business
> accounts: it reads accounts, balances and transactions with a token the account holder issues in Internet Banka.
> Modules for Spring Boot, Play, Micronaut and Quarkus. Published on GitHub Packages (group `cz.insuit`), not Maven
> Central. Pre-1.0: read records by accessor, never by record pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

class MonetaFactoryTest {

Expand Down Expand Up @@ -129,17 +131,18 @@ void customizesThenDecoratesTheHttpClientByOrderNotByDefinition() {
app.getBean(MonetaClient.class);
var hooks = app.getBean(HttpHooks.class);
assertEquals(List.of("customize 1", "customize 2", "decorate 1", "decorate 2"), hooks.calls);
assertEquals(HttpClient.Redirect.ALWAYS, hooks.decorated.getFirst().followRedirects());
assertEquals(HttpClient.Redirect.ALWAYS, hooks.decorated.get(0).followRedirects());
}
}

@Test
@EnabledForJreRange(min = JRE.JAVA_21, disabledReason = "HttpClient has no close() before Java 21")
void closesTheClientWithTheContext() {
var app = ApplicationContext.run(Map.of("spec.name", "http-hooks"));
app.getBean(MonetaClient.class);
var http = app.getBean(HttpHooks.class).decorated.getFirst();
var http = app.getBean(HttpHooks.class).decorated.get(0);
app.close();
assertTrue(http.isTerminated());
assertTrue(terminated(http));
}

@Test
Expand Down Expand Up @@ -275,4 +278,13 @@ HttpClientDecorator innerDecorator(HttpHooks hooks) {
};
}
}

/** HttpClient.isTerminated() came with its close() in Java 21, and these tests are compiled for 17. */
private static boolean terminated(HttpClient http) {
try {
return (boolean) HttpClient.class.getMethod("isTerminated").invoke(http);
} catch (ReflectiveOperationException e) {
throw new LinkageError("HttpClient.isTerminated()", e);
}
}
}
3 changes: 3 additions & 0 deletions modules/moneta-api-play/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public class PaymentsController extends Controller {
}
```

On Java 17, which has neither virtual threads nor `ExecutorService.close()`, a fixed pool does it:
`Executors.newFixedThreadPool(32)`, and `threads.shutdown()` in the stop hook.

A dispatcher of Play's own does the same: a `CustomExecutionContext` subclass naming a `thread-pool-executor` block
in `application.conf`, as in Play's [thread pools](https://playframework.com/documentation/latest/ThreadPools)
guide. The module ships neither, because that class takes a Pekko `ActorSystem` in Play 3.0 and an Akka one in 2.9.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ class ClientTest {
// Off, so the decorators see the JDK client itself, whose isTerminated() the check below reads;
// Micrometer's wrapper does not pass it on.
.overrideConfigKey("quarkus.moneta.metrics.enabled", "false")
.setAfterAllCustomizer(() -> assertTrue(
((HttpClient) System.getProperties().remove(HTTP)).isTerminated(), "the HTTP client is closed"));
.setAfterAllCustomizer(() -> {
var http = (HttpClient) System.getProperties().remove(HTTP);
if (Runtime.version().feature() >= 21) {
assertTrue(terminated(http), "the HTTP client is closed");
}
});

@Inject
MonetaClient moneta;
Expand All @@ -50,7 +54,7 @@ class ClientTest {
@Test
void readsMonetaWithTheConfiguredTokenAndPartner() {
// FakeMoneta answers 401 to any other token or partner.
assertEquals("acc-1", moneta.accounts(token).getFirst().id());
assertEquals("acc-1", moneta.accounts(token).get(0).id());
}

@Test
Expand Down Expand Up @@ -87,4 +91,13 @@ HttpClientDecorator high() {
};
}
}

/** HttpClient.isTerminated() came with its close() in Java 21, and these tests are compiled for 17. */
private static boolean terminated(HttpClient http) {
try {
return (boolean) HttpClient.class.getMethod("isTerminated").invoke(http);
} catch (ReflectiveOperationException e) {
throw new LinkageError("HttpClient.isTerminated()", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void customizesThenDecoratesTheHttpClientByOrderNotByDefinition() {
app.getBean(MonetaClient.class);
var hooks = app.getBean(HttpHooks.class);
assertEquals(List.of("customize 1", "customize 2", "decorate 1", "decorate 2"), hooks.calls);
assertEquals(HttpClient.Redirect.ALWAYS, hooks.decorated.getFirst().followRedirects());
assertEquals(HttpClient.Redirect.ALWAYS, hooks.decorated.get(0).followRedirects());
});
}

Expand Down Expand Up @@ -162,7 +162,7 @@ void sendsThroughTheSslBundleItIsNamedAndLetsACustomizerChangeIt() {
.withPropertyValues("moneta.ssl.bundle=moneta")
.run(app -> {
app.getBean(MonetaClient.class);
var http = app.getBean(HttpHooks.class).decorated.getFirst();
var http = app.getBean(HttpHooks.class).decorated.get(0);
assertEquals(
List.of("TLSv1.3"), List.of(http.sslParameters().getProtocols()));
assertEquals(
Expand Down
2 changes: 1 addition & 1 deletion modules/moneta-api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# moneta-api

The MONETA API client for Java 21+ and Kotlin, without a framework. With Spring Boot, Play, Micronaut or Quarkus,
The MONETA API client for Java 17+ and Kotlin, without a framework. With Spring Boot, Play, Micronaut or Quarkus,
take that module instead; it brings this one.

## Install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public record Account(
@Nullable String name) {

static Account from(AccountJson json) {
var iban = json.identification() instanceof IdentificationJson(var value) ? value : null;
var identification = json.identification();
var iban = identification == null ? null : identification.iban();
return new Account(json.id(), iban, json.currency(), json.nameI18N());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
* with each call and never kept, so it cannot end up in a {@code toString()} or a heap dump of the client.
*
* <p>Thread-safe; one per application is enough. {@link #close()} releases the HTTP client it made itself, not
* one passed to {@link Builder#httpClient}.
* one passed to {@link Builder#httpClient}. On Java 17, whose {@code HttpClient} has no {@code close()}, that client
* stops its threads once nothing references it instead.
*/
public final class MonetaClient implements AutoCloseable {

Expand Down Expand Up @@ -119,9 +120,16 @@ public static Builder builder() {

@Override
public void close() {
// The inner client, not the decorated one: a tracing or metrics wrapper does not pass close() on.
if (ownsHttp) {
inner.close();
// The inner client, not the decorated one: a tracing or metrics wrapper does not pass close() on. HttpClient
// has close() from Java 21; on 17 it has none and stops its threads once nothing references it.
if (ownsHttp && inner instanceof AutoCloseable closeable) {
try {
closeable.close();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}

Expand Down Expand Up @@ -171,7 +179,7 @@ public List<Account> accounts(AccessToken token) {
throw new IllegalStateException("the token opens " + matches.size() + " accounts with that IBAN ("
+ matches.stream().map(Account::id).toList() + "), so name one by its id");
}
return matches.isEmpty() ? null : matches.getFirst();
return matches.isEmpty() ? null : matches.get(0);
}

/** ISO 13616: two letters, two check digits, up to 30 more; moved to the end, the number is 1 modulo 97. */
Expand Down Expand Up @@ -269,7 +277,7 @@ String onlyAccount(AccessToken token) {
throw new IllegalStateException(
"the token opens " + accounts.size() + " accounts, so name one: transactions(accountId)");
}
return accounts.getFirst().id();
return accounts.get(0).id();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ static Transaction from(TransactionJson json, String raw) {
}

private static @Nullable LocalDate date(@Nullable DateValueJson value) {
return value instanceof DateValueJson(var date) ? date : null;
return value == null ? null : value.date();
}
}
Loading