throw cancelled;
}
int status = response.statusCode();
- var message = what + " answered " + status;
- // X-Request-Id is what MONETA's support asks for about one call. Never the token, never the body.
- log(
- what,
- status,
- millisSince(started),
- response.headers().firstValue("X-Request-Id").orElse(null),
- null);
+ // X-Request-Id is what MONETA's support asks for about one call, so a failure names it too, for an
+ // application that logs the exception with DEBUG off. Never the token, never the body.
+ var requestId = response.headers().firstValue("X-Request-Id").orElse(null);
+ var call = requestId == null || !REQUEST_ID.matcher(requestId).matches()
+ ? what
+ : what + " (X-Request-Id " + requestId + ")";
+ var message = call + " answered " + status;
+ log(what, status, millisSince(started), requestId, null);
return switch (status / 100) {
- case 2 -> parse(what, () -> JSON.readValue(response.body(), type));
+ case 2 -> new Answer<>(parse(call, () -> JSON.readValue(response.body(), type)), call);
default ->
throw switch (status) {
case 401, 403 -> new MonetaException.InvalidToken(message, status, excerpt(response));
diff --git a/modules/moneta-api/src/main/java/cz/insuit/moneta/MonetaException.java b/modules/moneta-api/src/main/java/cz/insuit/moneta/MonetaException.java
index a228e1f..96e93b8 100644
--- a/modules/moneta-api/src/main/java/cz/insuit/moneta/MonetaException.java
+++ b/modules/moneta-api/src/main/java/cz/insuit/moneta/MonetaException.java
@@ -5,7 +5,8 @@
/**
* A call to MONETA that did not return what was asked for, one subtype per thing a caller does about it, so
- * a {@code switch} over them is exhaustive. The message never carries the token, nor MONETA's response body.
+ * a {@code switch} over them is exhaustive. The message names the request and, when MONETA sent one, its
+ * {@code X-Request-Id}, which its support asks for; never the token, nor MONETA's response body.
*
* The subtypes' constructors are public so a caller's own tests can throw them from a fake; the hierarchy
* stays closed.
diff --git a/modules/moneta-api/src/test/java/cz/insuit/moneta/MonetaClientTest.java b/modules/moneta-api/src/test/java/cz/insuit/moneta/MonetaClientTest.java
index 7a5146e..aead004 100644
--- a/modules/moneta-api/src/test/java/cz/insuit/moneta/MonetaClientTest.java
+++ b/modules/moneta-api/src/test/java/cz/insuit/moneta/MonetaClientTest.java
@@ -455,10 +455,14 @@ void aBalanceWithoutTheAvailableOneIsRefused() {
{"amount": {"currency": "CZK", "value": 1}, "creditDebitIndicator": "CRDT",
"date": {"dateTime": "2026-11-07T15:32:12Z"}, "type": {"codeOrProprietary": {"code": "CLBD"}}}
]}""";
- answer(BALANCE, 200, bookedOnly);
+ server.createContext(BALANCE, exchange -> {
+ exchange.getResponseHeaders().add("X-Request-Id", "req-7");
+ respond(exchange, 200, bookedOnly);
+ });
var refused = assertThrows(MonetaException.InvalidResponse.class, () -> client.balance(TOKEN, "acc-1"));
assertTrue(String.valueOf(refused.getMessage()).contains("CLAV"), refused.getMessage());
+ assertTrue(String.valueOf(refused.getMessage()).contains("X-Request-Id req-7"), refused.getMessage());
}
@Test
@@ -821,6 +825,7 @@ void anAccountWithoutACurrencyIsAnInvalidResponse() {
void aBrokenItemNamesTheRequestThePageAndTheMovement() {
server.createContext(TRANSACTIONS, exchange -> {
var first = exchange.getRequestURI().getQuery().endsWith("page=0");
+ exchange.getResponseHeaders().add("X-Request-Id", first ? "req-0" : "req-1");
respond(exchange, 200, first ? fixture("transactions-page-0.json") : movement("BOOK", "XXXX"));
});
@@ -828,6 +833,7 @@ void aBrokenItemNamesTheRequestThePageAndTheMovement() {
MonetaException.InvalidResponse.class, () -> client.transactions(TOKEN, "acc-1", FROM, TO));
var message = Objects.requireNonNull(failed.getMessage());
assertTrue(message.contains("page=1"), message);
+ assertTrue(message.contains("X-Request-Id req-1"), message);
assertTrue(message.contains("entryReference=t"), message);
assertTrue(message.contains("'XXXX'"), message);
}
@@ -872,6 +878,8 @@ void reportsAnyOtherFailureWithItsStatus() {
answer(ACCOUNTS, 503, "{}");
var failed = assertThrows(MonetaException.HttpError.class, () -> client.accounts(TOKEN));
assertEquals(503, failed.status());
+ // MONETA sent no X-Request-Id here, so the message has no empty or "null" one.
+ assertFalse(String.valueOf(failed.getMessage()).contains("X-Request-Id"), failed.getMessage());
}
@Test
@@ -900,6 +908,38 @@ void aMaintenanceAnswerSaysWhenToComeBack() {
assertEquals(Duration.ofMinutes(2), failed.retryAfter());
}
+ @Test
+ void aFailureNamesTheRequestIdMonetasSupportAsksFor() {
+ server.createContext(ACCOUNTS, exchange -> {
+ exchange.getResponseHeaders().add("X-Request-Id", "req-42");
+ respond(exchange, 503, "{}");
+ });
+ var failed = assertThrows(MonetaException.HttpError.class, () -> client.accounts(TOKEN));
+ assertTrue(String.valueOf(failed.getMessage()).contains("X-Request-Id req-42"), failed.getMessage());
+
+ server.removeContext(ACCOUNTS);
+ server.createContext(ACCOUNTS, exchange -> {
+ exchange.getResponseHeaders().add("X-Request-Id", "req-43");
+ respond(exchange, 200, "not json");
+ });
+ var unreadable = assertThrows(MonetaException.InvalidResponse.class, () -> client.accounts(TOKEN));
+ assertTrue(
+ String.valueOf(unreadable.getMessage()).contains("X-Request-Id req-43"), unreadable.getMessage());
+ }
+
+ @Test
+ void aRequestIdThatIsNotShortPrintableAsciiStaysOutOfTheMessage() {
+ for (var requestId : List.of("", "a b", "x".repeat(129))) {
+ server.createContext(ACCOUNTS, exchange -> {
+ exchange.getResponseHeaders().add("X-Request-Id", requestId);
+ respond(exchange, 503, "{}");
+ });
+ var failed = assertThrows(MonetaException.HttpError.class, () -> client.accounts(TOKEN));
+ assertFalse(String.valueOf(failed.getMessage()).contains("X-Request-Id"), failed.getMessage());
+ server.removeContext(ACCOUNTS);
+ }
+ }
+
@Test
void logsEachCallWithItsRequestIdButNeverTheToken() {
server.createContext(ACCOUNTS, exchange -> {
diff --git a/testing/README.md b/testing/README.md
index d072651..679be9e 100644
--- a/testing/README.md
+++ b/testing/README.md
@@ -35,3 +35,7 @@ Both also log the client at DEBUG, since writing that line is the one place it s
reaches Logback through `logger.levels` alone; without the provider it does not, Micronaut leaves
`java.util.logging` alone.
+The other frameworks' projects check the same line against the one setting their module README gives, and fail
+without it: `logging.level` in Spring Boot, a logger in `logback.xml` in Play, `quarkus.log.category` in Quarkus.
+The Play projects carry `play-logback` for that, as every Play application does.
+
diff --git a/testing/micronaut/shared/src/test/java/example/micronaut/MonetaInMicronautTest.java b/testing/micronaut/shared/src/test/java/example/micronaut/MonetaInMicronautTest.java
index a77f46d..289c29f 100644
--- a/testing/micronaut/shared/src/test/java/example/micronaut/MonetaInMicronautTest.java
+++ b/testing/micronaut/shared/src/test/java/example/micronaut/MonetaInMicronautTest.java
@@ -89,15 +89,21 @@ void theClientsDebugLineReachesLogbackThroughLoggerLevels() throws IOException {
// After the start: Micronaut resets Logback from logback.xml while applying logger.levels.
var lines = new ListAppender();
lines.start();
- logback.getLogger("cz.insuit.moneta").addAppender(lines);
+ var logger = logback.getLogger("cz.insuit.moneta");
+ logger.addAppender(lines);
- context.getBean(MonetaClient.class).accounts(new AccessToken("t"));
+ try {
+ context.getBean(MonetaClient.class).accounts(new AccessToken("t"));
- assertTrue(
- lines.list.stream()
- .anyMatch(line -> line.getLoggerName().equals(MonetaClient.class.getName())
- && line.getLevel() == Level.DEBUG),
- "no DEBUG line from the client reached Logback");
+ assertTrue(
+ lines.list.stream()
+ .anyMatch(line -> line.getLoggerName().equals(MonetaClient.class.getName())
+ && line.getLevel() == Level.DEBUG),
+ "no DEBUG line from the client reached Logback");
+ } finally {
+ logger.detachAppender(lines);
+ lines.stop();
+ }
} finally {
server.stop(0);
}
diff --git a/testing/play/2.9/build.gradle.kts b/testing/play/2.9/build.gradle.kts
index 8d2f4f7..96fac4e 100644
--- a/testing/play/2.9/build.gradle.kts
+++ b/testing/play/2.9/build.gradle.kts
@@ -1,2 +1,7 @@
// The rest is shared, in ../build.gradle.kts.
-dependencies { testImplementation("com.typesafe.play:play-guice_2.13:2.9.12") }
+dependencies {
+ testImplementation("com.typesafe.play:play-guice_2.13:2.9.12")
+ // What every Play application has: the sbt plugin adds it, and it configures Logback from logback.xml. On the
+ // compile classpath too, for the test to read what reached Logback.
+ testImplementation("com.typesafe.play:play-logback_2.13:2.9.12")
+}
diff --git a/testing/play/3.0-scala-2.13/build.gradle.kts b/testing/play/3.0-scala-2.13/build.gradle.kts
index 951880c..ebc8222 100644
--- a/testing/play/3.0-scala-2.13/build.gradle.kts
+++ b/testing/play/3.0-scala-2.13/build.gradle.kts
@@ -1,2 +1,7 @@
// The rest is shared, in ../build.gradle.kts.
-dependencies { testImplementation("org.playframework:play-guice_2.13:3.0.12") }
+dependencies {
+ testImplementation("org.playframework:play-guice_2.13:3.0.12")
+ // What every Play application has: the sbt plugin adds it, and it configures Logback from logback.xml. On the
+ // compile classpath too, for the test to read what reached Logback.
+ testImplementation("org.playframework:play-logback_2.13:3.0.12")
+}
diff --git a/testing/play/3.0-scala-3/build.gradle.kts b/testing/play/3.0-scala-3/build.gradle.kts
index bbb7b5b..10e8495 100644
--- a/testing/play/3.0-scala-3/build.gradle.kts
+++ b/testing/play/3.0-scala-3/build.gradle.kts
@@ -1,2 +1,7 @@
// The rest is shared, in ../build.gradle.kts.
-dependencies { testImplementation("org.playframework:play-guice_3:3.0.12") }
+dependencies {
+ testImplementation("org.playframework:play-guice_3:3.0.12")
+ // What every Play application has: the sbt plugin adds it, and it configures Logback from logback.xml. On the
+ // compile classpath too, for the test to read what reached Logback.
+ testImplementation("org.playframework:play-logback_3:3.0.12")
+}
diff --git a/testing/play/build.gradle.kts b/testing/play/build.gradle.kts
index 973bf42..4d3249a 100644
--- a/testing/play/build.gradle.kts
+++ b/testing/play/build.gradle.kts
@@ -13,6 +13,7 @@ subprojects {
named("test") {
java.srcDir("../shared/src/test/java")
resources.srcDir("../../resources") // one MONETA answer for every testing project
+ resources.srcDir("../shared/src/test/resources")
}
}
}
diff --git a/testing/play/shared/src/test/java/example/play/MonetaInPlayTest.java b/testing/play/shared/src/test/java/example/play/MonetaInPlayTest.java
index d56af01..9bec6a8 100644
--- a/testing/play/shared/src/test/java/example/play/MonetaInPlayTest.java
+++ b/testing/play/shared/src/test/java/example/play/MonetaInPlayTest.java
@@ -5,6 +5,10 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import com.google.inject.ConfigurationException;
import com.sun.net.httpserver.HttpServer;
import cz.insuit.moneta.AccessToken;
@@ -24,6 +28,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
+import org.slf4j.LoggerFactory;
import play.Application;
import play.inject.guice.GuiceApplicationBuilder;
import play.libs.Json;
@@ -82,6 +87,43 @@ void aClientTheModuleBuiltReadsTransactions() throws Exception {
}
}
+ /** What the module README promises: a logger in logback.xml switches the client's DEBUG line on. */
+ @Test
+ void theClientsDebugLineReachesLogbackThroughLogbackXml() throws Exception {
+ var app = new GuiceApplicationBuilder()
+ .configure("moneta.base-uri", base)
+ .configure("moneta.token", "t")
+ .build();
+ try {
+ // After the build: Play configures Logback from logback.xml while it builds the application.
+ var lines = new ListAppender();
+ lines.start();
+ var logger = ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("cz.insuit.moneta");
+ logger.addAppender(lines);
+
+ try {
+ app.injector()
+ .instanceOf(MonetaClient.class)
+ .transactions(
+ app.injector().instanceOf(AccessToken.class),
+ "acc-1",
+ LocalDate.of(2026, 8, 1),
+ LocalDate.of(2026, 8, 31));
+
+ assertTrue(
+ lines.list.stream()
+ .anyMatch(line -> line.getLoggerName().equals(MonetaClient.class.getName())
+ && line.getLevel() == Level.DEBUG),
+ "no DEBUG line from the client reached Logback");
+ } finally {
+ logger.detachAppender(lines);
+ lines.stop();
+ }
+ } finally {
+ stop(app);
+ }
+ }
+
@Test
void noTokenNoAccessToken() throws Exception {
var app = new GuiceApplicationBuilder().build();
diff --git a/testing/play/shared/src/test/resources/logback.xml b/testing/play/shared/src/test/resources/logback.xml
new file mode 100644
index 0000000..0a323e9
--- /dev/null
+++ b/testing/play/shared/src/test/resources/logback.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
diff --git a/testing/quarkus/shared/src/test/java/example/quarkus/FakeMoneta.java b/testing/quarkus/shared/src/test/java/example/quarkus/FakeMoneta.java
index 0474483..757dbee 100644
--- a/testing/quarkus/shared/src/test/java/example/quarkus/FakeMoneta.java
+++ b/testing/quarkus/shared/src/test/java/example/quarkus/FakeMoneta.java
@@ -37,7 +37,10 @@ public Map start() {
"quarkus.moneta.base-uri",
"http://" + address.getHostString() + ":" + address.getPort() + "/",
"quarkus.moneta.token",
- "t");
+ "t",
+ // What the extension README tells an application to set for the client's DEBUG line.
+ "quarkus.log.category.\"cz.insuit.moneta\".level",
+ "DEBUG");
}
@Override
diff --git a/testing/quarkus/shared/src/test/java/example/quarkus/MonetaInQuarkusTest.java b/testing/quarkus/shared/src/test/java/example/quarkus/MonetaInQuarkusTest.java
index b0e2e0c..87d91f3 100644
--- a/testing/quarkus/shared/src/test/java/example/quarkus/MonetaInQuarkusTest.java
+++ b/testing/quarkus/shared/src/test/java/example/quarkus/MonetaInQuarkusTest.java
@@ -1,6 +1,7 @@
package example.quarkus;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import cz.insuit.moneta.AccessToken;
import cz.insuit.moneta.MonetaClient;
@@ -11,6 +12,11 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Currency;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
import org.junit.jupiter.api.Test;
/**
@@ -35,4 +41,36 @@ void aClientTheExtensionBuiltReadsTransactions() {
new Money(new BigDecimal("-12.50"), Currency.getInstance("CZK")),
transactions.get(0).amount());
}
+
+ /**
+ * What the extension README promises: quarkus.log.category switches the client's DEBUG line on. Quarkus is the
+ * java.util.logging implementation, so System.Logger lands in its log without a bridge.
+ */
+ @Test
+ void theClientsDebugLineReachesTheLogThroughALogCategory() {
+ var lines = new CopyOnWriteArrayList();
+ var handler = new Handler() {
+ @Override
+ public void publish(LogRecord record) {
+ lines.add(record);
+ }
+
+ @Override
+ public void flush() {}
+
+ @Override
+ public void close() {}
+ };
+ var logger = Logger.getLogger(MonetaClient.class.getName());
+ logger.addHandler(handler);
+ try {
+ moneta.transactions(token, "acc-1", LocalDate.of(2026, 8, 1), LocalDate.of(2026, 8, 31));
+ } finally {
+ logger.removeHandler(handler);
+ }
+
+ assertTrue(
+ lines.stream().anyMatch(line -> line.getLevel().intValue() <= Level.FINE.intValue()),
+ "no DEBUG line from the client reached the log");
+ }
}
diff --git a/testing/spring-boot/shared/src/test/java/example/boot/MonetaInSpringBootTest.java b/testing/spring-boot/shared/src/test/java/example/boot/MonetaInSpringBootTest.java
index 4d51971..221ccb8 100644
--- a/testing/spring-boot/shared/src/test/java/example/boot/MonetaInSpringBootTest.java
+++ b/testing/spring-boot/shared/src/test/java/example/boot/MonetaInSpringBootTest.java
@@ -1,7 +1,12 @@
package example.boot;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import com.sun.net.httpserver.HttpServer;
import cz.insuit.moneta.AccessToken;
import cz.insuit.moneta.MonetaClient;
@@ -14,6 +19,7 @@
import java.util.Currency;
import java.util.Objects;
import org.junit.jupiter.api.Test;
+import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -51,19 +57,35 @@ void aClientTheContextBuiltReadsTransactions() throws IOException {
.properties(
"moneta.base-uri=" + base,
"moneta.token=t",
- // Spring Boot routes the client's System.Logger into Logback, so this writes its DEBUG line,
- // with
- // whatever jackson-annotations the BOM pins.
+ // What the starter README tells an application to set. The line it switches on is the one
+ // place the client serialises, with whatever jackson-annotations the BOM pins.
"logging.level.cz.insuit.moneta=DEBUG")
.run()) {
- var moneta = context.getBean(MonetaClient.class);
- var token = context.getBean(AccessToken.class);
+ // After the start: Spring Boot resets Logback while it starts.
+ var lines = new ListAppender();
+ lines.start();
+ var logger = ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("cz.insuit.moneta");
+ logger.addAppender(lines);
+ try {
+ var moneta = context.getBean(MonetaClient.class);
+ var token = context.getBean(AccessToken.class);
- var transactions = moneta.transactions(token, "acc-1", LocalDate.of(2026, 8, 1), LocalDate.of(2026, 8, 31));
+ var transactions =
+ moneta.transactions(token, "acc-1", LocalDate.of(2026, 8, 1), LocalDate.of(2026, 8, 31));
- assertEquals(
- new Money(new BigDecimal("-12.50"), Currency.getInstance("CZK")),
- transactions.get(0).amount());
+ assertEquals(
+ new Money(new BigDecimal("-12.50"), Currency.getInstance("CZK")),
+ transactions.get(0).amount());
+ // Spring Boot bridges java.util.logging, where System.Logger goes, and passes its levels on to it.
+ assertTrue(
+ lines.list.stream()
+ .anyMatch(line -> line.getLoggerName().equals(MonetaClient.class.getName())
+ && line.getLevel() == Level.DEBUG),
+ "no DEBUG line from the client reached Logback");
+ } finally {
+ logger.detachAppender(lines);
+ lines.stop();
+ }
} finally {
server.stop(0);
}