Skip to content

Commit 65c492b

Browse files
committed
[UNDERTOW-2303] Improvements based on PR feedback. Changed copyright notices from 2024 to 2025, fixed typos and javadoc links, mark unused methods as deprecated, remove new unused methods, replaced exception messages with exceptions from UndertowMessages
1 parent c341cf2 commit 65c492b

File tree

10 files changed

+124
-170
lines changed

10 files changed

+124
-170
lines changed

core/src/main/java/io/undertow/UndertowMessages.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,18 @@ public interface UndertowMessages {
661661
@Message(id = 212, value = "Failed to encode query string '%s' with '%s' encoding.")
662662
IllegalArgumentException failedToEncodeQueryString(String q, String e);
663663

664+
@Message(id = 213, value = "Wild cards are only supported at the end of a template path")
665+
IllegalArgumentException wildCardsOnlyAtEndOfTemplate();
666+
667+
@Message(id = 214, value = "Illegal character '%s' is contained in the URL path segment '%s' at position %s")
668+
IllegalArgumentException illegalCharacterInPathSegment(char character, String segment, int position);
669+
670+
@Message(id = 215, value = "updateDefaultTargetFactory cannot be called after having added templates")
671+
IllegalStateException defaultTargetUpdatedAfterTemplatesAdded();
672+
673+
@Message(id = 216, value = "The builder already contains a template with the same pattern for '%s'")
674+
IllegalArgumentException duplicateUrlPathTemplate(String template);
675+
676+
@Message(id = 217, value = "The 'defaultTargetFactory' must be set before calling 'build'")
677+
IllegalStateException defaultTargetFactoryMustBeSetBeforeBuild();
664678
}

core/src/main/java/io/undertow/server/RoutingHandler.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JBoss, Home of Professional Open Source.
3-
* Copyright 2024 Red Hat, Inc., and individual contributors
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
44
* as indicated by the @author tags.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -230,7 +230,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
230230
* @param method The HTTP method.
231231
* @return The builder.
232232
*/
233-
private PathTemplateRouterFactory.Builder<RoutingMatchBuilder, RoutingMatch> getOrAddMethodRouterBuiler(
233+
private PathTemplateRouterFactory.Builder<RoutingMatchBuilder, RoutingMatch> getOrAddMethodRouterBuilder(
234234
final HttpString method
235235
) {
236236
Objects.requireNonNull(method);
@@ -259,7 +259,7 @@ private RoutingMatchBuilder getOrAddMethodRoutingMatchBuilder(
259259
Objects.requireNonNull(template);
260260

261261
final PathTemplateRouterFactory.Builder<RoutingMatchBuilder, RoutingMatch> routeBuilder
262-
= getOrAddMethodRouterBuiler(method);
262+
= getOrAddMethodRouterBuilder(method);
263263
final PathTemplateParser.PathTemplate<RoutingMatchBuilder> parsedTemplate = PathTemplateParser.parseTemplate(
264264
template, new RoutingMatchBuilder()
265265
);
@@ -425,12 +425,12 @@ public synchronized RoutingHandler addAll(RoutingHandler routingHandler) {
425425
its configuration (templates etc) are mutated. Mutating via the original RoutingHandler would - after
426426
having called this method - also result in the router being out of sync with the router builder.
427427
For these reasons, this has been changed to a deep copy. Arguably, developers won't expect to end up with
428-
two RoutingHandlers that are implicitely linked after having called this method anyway. */
428+
two RoutingHandlers that are implicitly linked after having called this method anyway. */
429429
synchronized (routingHandler) {
430430
for (final Entry<HttpString, PathTemplateRouterFactory.Builder<RoutingMatchBuilder, RoutingMatch>> outer
431431
: routingHandler.methodRouterBuilders.entrySet()) {
432432
final PathTemplateRouterFactory.Builder<RoutingMatchBuilder, RoutingMatch> builder
433-
= getOrAddMethodRouterBuiler(outer.getKey());
433+
= getOrAddMethodRouterBuilder(outer.getKey());
434434
for (final Entry<PathTemplateParser.PathTemplatePatternEqualsAdapter<PathTemplateParser.PathTemplate<RoutingMatchBuilder>>, RoutingMatchBuilder> inner
435435
: outer.getValue().getTemplates().entrySet()) {
436436
builder.addTemplate(
@@ -490,7 +490,10 @@ public synchronized RoutingHandler remove(final HttpString method, final String
490490
* @param path the path template to remove
491491
*
492492
* @return this handler
493+
*
494+
* @deprecated Not used. Will be removed in future releases.
493495
*/
496+
@Deprecated(forRemoval = true)
494497
public synchronized RoutingHandler remove(final String path) {
495498
Objects.requireNonNull(path);
496499

@@ -505,7 +508,10 @@ public synchronized RoutingHandler remove(final String path) {
505508

506509
/**
507510
* @return Handler called when no match was found and invalid method handler can't be invoked.
511+
*
512+
* @deprecated Not used. Will be removed in future releases.
508513
*/
514+
@Deprecated(forRemoval = true)
509515
public HttpHandler getFallbackHandler() {
510516
return fallbackHandler;
511517
}
@@ -514,15 +520,21 @@ public HttpHandler getFallbackHandler() {
514520
* @param fallbackHandler Handler that will be called when no match was found and invalid method handler can't be invoked.
515521
*
516522
* @return This instance.
523+
*
524+
* @deprecated Not used. Will be removed in future releases.
517525
*/
526+
@Deprecated(forRemoval = true)
518527
public RoutingHandler setFallbackHandler(HttpHandler fallbackHandler) {
519528
this.fallbackHandler = fallbackHandler;
520529
return this;
521530
}
522531

523532
/**
524533
* @return Handler called when this instance can not match the http method but can match another http method.
534+
*
535+
* @deprecated Not used. Will be removed in future releases.
525536
*/
537+
@Deprecated(forRemoval = true)
526538
public HttpHandler getInvalidMethodHandler() {
527539
return invalidMethodHandler;
528540
}
@@ -536,7 +548,10 @@ public HttpHandler getInvalidMethodHandler() {
536548
* another http method.
537549
*
538550
* @return This instance.
551+
*
552+
* @deprecated Not used. Will be removed in future releases.
539553
*/
554+
@Deprecated(forRemoval = true)
540555
public RoutingHandler setInvalidMethodHandler(HttpHandler invalidMethodHandler) {
541556
this.invalidMethodHandler = invalidMethodHandler;
542557
return this;

core/src/main/java/io/undertow/server/handlers/PathTemplateHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JBoss, Home of Professional Open Source.
3-
* Copyright 2024 Red Hat, Inc., and individual contributors
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
44
* as indicated by the @author tags.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");

core/src/main/java/io/undertow/server/handlers/PathTemplateRouterHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JBoss, Home of Professional Open Source.
3-
* Copyright 2024 Red Hat, Inc., and individual contributors
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
44
* as indicated by the @author tags.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");

core/src/main/java/io/undertow/util/PathTemplateParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JBoss, Home of Professional Open Source.
3-
* Copyright 2024 Red Hat, Inc., and individual contributors
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
44
* as indicated by the @author tags.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,7 @@
1717
*/
1818
package io.undertow.util;
1919

20+
import io.undertow.UndertowMessages;
2021
import static io.undertow.util.PathTemplateUtil.pathWithForwardSlash;
2122
import java.util.ArrayList;
2223
import java.util.Iterator;
@@ -126,7 +127,7 @@ public class PathTemplateParser {
126127
* <p>
127128
* In the above mentioned example the {@link #hashCode() } method may return different values for the two templates and
128129
* {@link #equals(java.lang.Object) } will return 'false'. The {@link #patternHashCode() } will return the same values for
129-
* the two templates and {@link #patternEquals(io.undertow.util.PathTemplatePattern) } will return 'true'.</p>
130+
* the two templates and {@link #patternEquals(io.undertow.util.PathTemplateParser.PathTemplatePattern) } will return 'true'.</p>
130131
*/
131132
public abstract static class PathTemplatePattern {
132133

@@ -611,7 +612,7 @@ private static void validWildCardOrNotAWildCard(final String pathTemplate) {
611612
}
612613

613614
if (idx != (pathTemplate.length() - 1)) {
614-
throw new IllegalArgumentException("Wild cards are only supported at the end of a template path");
615+
throw UndertowMessages.MESSAGES.wildCardsOnlyAtEndOfTemplate();
615616
}
616617
}
617618

@@ -659,8 +660,7 @@ private static String validSegment(
659660
valid = valid || c == '_' || c == '-';
660661

661662
if (!valid) {
662-
throw new IllegalArgumentException("Illegal character '"
663-
+ c + "' is contained in the segment '" + value + "' at position " + i);
663+
throw UndertowMessages.MESSAGES.illegalCharacterInPathSegment(c, value, i);
664664
}
665665
}
666666

core/src/main/java/io/undertow/util/PathTemplateRouteResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JBoss, Home of Professional Open Source.
3-
* Copyright 2024 Red Hat, Inc., and individual contributors
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
44
* as indicated by the @author tags.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");

core/src/main/java/io/undertow/util/PathTemplateRouter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JBoss, Home of Professional Open Source.
3-
* Copyright 2024 Red Hat, Inc., and individual contributors
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
44
* as indicated by the @author tags.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -99,11 +99,6 @@
9999
*/
100100
public interface PathTemplateRouter<T> {
101101

102-
/**
103-
* @return The default target for requests that do not match any specific routes.
104-
*/
105-
T getDefaultTarget();
106-
107102
/**
108103
* Routes the requested URL path to the best available target from the set of underlying URL path templates.
109104
*

0 commit comments

Comments
 (0)