feat: jpa, messaging, notification, mongo, graphql 어댑터터 구현체 추가
This commit is contained in:
+13
-2
@@ -11,6 +11,13 @@ public record ContentType(String value) {
|
||||
|
||||
private static final int MAX_LENGTH = 160;
|
||||
|
||||
/** {@code type/subtype} with the optional parameters RFC 9110 allows. */
|
||||
private static final java.util.regex.Pattern MEDIA_TYPE =
|
||||
java.util.regex.Pattern.compile(
|
||||
"[A-Za-z0-9][A-Za-z0-9!#$%&'*+.^_`|~-]*"
|
||||
+ "/[A-Za-z0-9][A-Za-z0-9!#$%&'*+.^_`|~-]*"
|
||||
+ "(;\\s*[A-Za-z0-9!#$%&'*+.^_`|~-]+=[^;\\s]+)*");
|
||||
|
||||
/** The Stable default codec's content type. */
|
||||
public static final ContentType JSON = new ContentType("application/json");
|
||||
|
||||
@@ -27,8 +34,12 @@ public record ContentType(String value) {
|
||||
if (value == null || value.isBlank() || value.length() > MAX_LENGTH) {
|
||||
throw new IllegalArgumentException("contentType must contain 1 to 160 characters");
|
||||
}
|
||||
if (value.indexOf('/') < 0) {
|
||||
throw new IllegalArgumentException("contentType must be a media type: " + value);
|
||||
// A media type, not merely a string containing a slash. `a/b/c`, `/json` and `text/` all
|
||||
// passed the old check and are all rejected by a broker or a codec registry later, with an
|
||||
// error that names the message rather than the configuration that produced it.
|
||||
if (!MEDIA_TYPE.matcher(value).matches()) {
|
||||
throw new IllegalArgumentException(
|
||||
"contentType must be a type/subtype media type: '" + value + '\'');
|
||||
}
|
||||
value = value.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
+13
@@ -14,8 +14,21 @@ import java.util.UUID;
|
||||
*/
|
||||
public record MessageId(UUID value) {
|
||||
|
||||
/** The UUID version this identity is documented to carry. */
|
||||
private static final int VERSION_7 = 7;
|
||||
|
||||
public MessageId {
|
||||
Objects.requireNonNull(value, "messageId value must not be null");
|
||||
// The type says UUIDv7 and the constructor accepted any UUID, including v4 and the nil UUID.
|
||||
// Version 7 is what makes the identity time-ordered, which is what the outbox index and every
|
||||
// "oldest first" claim depend on; a v4 stored in the same column silently defeats both.
|
||||
if (value.version() != VERSION_7) {
|
||||
throw new IllegalArgumentException(
|
||||
"a message identity is UUIDv7 (time-ordered); this is version " + value.version());
|
||||
}
|
||||
if (value.variant() != 2) {
|
||||
throw new IllegalArgumentException("a message identity must use the RFC 4122 variant");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+24
@@ -16,5 +16,29 @@ public record MessageType(String value) {
|
||||
if (value == null || value.isBlank() || value.length() > MAX_LENGTH) {
|
||||
throw new IllegalArgumentException("messageType must contain 1 to 240 characters");
|
||||
}
|
||||
requireWireSafe(value, "a message type", MAX_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Characters that must never reach a broker.
|
||||
*
|
||||
* <p>Length in Java {@code char}s bounded nothing useful: a 240-character string can be 960 UTF-8
|
||||
* bytes, and a control character passes a length check untouched. CR and LF split records on
|
||||
* line-oriented protocols, NUL truncates them in C string handling, and both survive right up to
|
||||
* the broker that mishandles them.
|
||||
*/
|
||||
private static void requireWireSafe(String value, String what, int maxBytes) {
|
||||
for (int index = 0; index < value.length(); index++) {
|
||||
char character = value.charAt(index);
|
||||
if (character < 0x20 || character == 0x7F) {
|
||||
throw new IllegalArgumentException(
|
||||
what
|
||||
+ " must not contain control characters (found U+%04X)".formatted((int) character));
|
||||
}
|
||||
}
|
||||
int bytes = value.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
||||
if (bytes > maxBytes) {
|
||||
throw new IllegalArgumentException(what + " exceeds " + maxBytes + " UTF-8 bytes: " + bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -16,5 +16,29 @@ public record ProducerId(String value) {
|
||||
if (value == null || value.isBlank() || value.length() > MAX_LENGTH) {
|
||||
throw new IllegalArgumentException("producerId must contain 1 to 120 characters");
|
||||
}
|
||||
requireWireSafe(value, "a producer id", MAX_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Characters that must never reach a broker.
|
||||
*
|
||||
* <p>Length in Java {@code char}s bounded nothing useful: a 240-character string can be 960 UTF-8
|
||||
* bytes, and a control character passes a length check untouched. CR and LF split records on
|
||||
* line-oriented protocols, NUL truncates them in C string handling, and both survive right up to
|
||||
* the broker that mishandles them.
|
||||
*/
|
||||
private static void requireWireSafe(String value, String what, int maxBytes) {
|
||||
for (int index = 0; index < value.length(); index++) {
|
||||
char character = value.charAt(index);
|
||||
if (character < 0x20 || character == 0x7F) {
|
||||
throw new IllegalArgumentException(
|
||||
what
|
||||
+ " must not contain control characters (found U+%04X)".formatted((int) character));
|
||||
}
|
||||
}
|
||||
int bytes = value.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
|
||||
if (bytes > maxBytes) {
|
||||
throw new IllegalArgumentException(what + " exceeds " + maxBytes + " UTF-8 bytes: " + bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -15,10 +15,36 @@ public record HeaderName(String value) {
|
||||
|
||||
private static final int MAX_BYTES = 128;
|
||||
|
||||
/**
|
||||
* The one grammar a header name may use.
|
||||
*
|
||||
* <p>The previous check was "not blank, at most 128 bytes", which accepted a name containing CR,
|
||||
* LF, NUL, a colon or leading whitespace. Those are not cosmetic: a newline in a header name is a
|
||||
* header-injection primitive on any line-oriented protocol, a NUL truncates the name in C string
|
||||
* handling inside a broker, and a colon is the field separator in several wire formats. A name
|
||||
* that survives one broker and corrupts the next is worse than a rejected one.
|
||||
*
|
||||
* <p>The character set is the HTTP token set, which every broker this platform targets accepts
|
||||
* verbatim.
|
||||
*/
|
||||
private static final java.util.regex.Pattern TOKEN =
|
||||
java.util.regex.Pattern.compile("[a-zA-Z0-9!#$%&'*+._|~-]+");
|
||||
|
||||
public HeaderName {
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new IllegalArgumentException("header name must not be blank");
|
||||
}
|
||||
if (!value.equals(value.strip())) {
|
||||
// Trimming would mean `Authorization ` and `Authorization` are the same name to the
|
||||
// denylist and different names on the wire, which is precisely how the check was bypassed.
|
||||
throw new IllegalArgumentException(
|
||||
"header name must not have leading or trailing whitespace: '" + value + '\'');
|
||||
}
|
||||
if (!TOKEN.matcher(value).matches()) {
|
||||
throw new IllegalArgumentException(
|
||||
"header name must be an ASCII token; control characters, spaces, colons and non-ASCII"
|
||||
+ " are refused because a broker that accepts one may truncate or split on it");
|
||||
}
|
||||
int bytes = value.getBytes(StandardCharsets.UTF_8).length;
|
||||
if (bytes > MAX_BYTES) {
|
||||
throw new IllegalArgumentException("header name exceeds 128 bytes: " + bytes);
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user