Hi,
I define two template paths with the following implementation:
public class UndertowTwoPathVariablesApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(UndertowTwoPathVariablesApplication.class);
public static void main(final String[] args) {
Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(
Handlers.routing()
.get("/api/v1/orders/{orderId}/items/", (exchange) -> {
LOGGER.info("The path template defined is '/api/v1/orders/{orderId}/items/'");
LOGGER.info("The request URI '{}'", exchange.getRequestURI());
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.setStatusCode(StatusCodes.OK)
.getResponseSender().send("Retrieve all Items of the Order '"
+ exchange.getQueryParameters().get("orderId").getLast() + "'");
})
.get("/api/v1/orders/{orderId}/items/{itemId}", (exchange) -> {
LOGGER.info("The path template defined is '/api/v1/orders/{orderId}/items/{itemId}'");
LOGGER.info("The request URI '{}'", exchange.getRequestURI());
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.setStatusCode(StatusCodes.OK)
.getResponseSender().send(
"Retrieve the Item '" + exchange.getQueryParameters().get("itemId").getLast()
+ "' of the Order '" + exchange.getQueryParameters().get("orderId").getLast() + "'");
}))
.build()
.start();
}
}
And using the version 2.0.0.Beta1 of undertow-core I can not enter to the first Handler defined.
boggard@xiuhcoatl:~$ curl -v 'http://localhost:8080/api/v1/orders/12345/items'
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api/v1/orders/12345/items HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Connection: keep-alive
< Content-Length: 0
< Date: Fri, 02 Feb 2018 08:08:48 GMT
<
* Connection #0 to host localhost left intact
boggard@xiuhcoatl:~$ curl -v 'http://localhost:8080/api/v1/orders/12345/items/'
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api/v1/orders/12345/items/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Type: text/plain
< Content-Length: 41
< Date: Fri, 02 Feb 2018 08:09:15 GMT
<
* Connection #0 to host localhost left intact
Retrieve the Item '' of the Order '12345'
boggard@xiuhcoatl:~$ curl -v 'http://localhost:8080/api/v1/orders/12345/items/'
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api/v1/orders/12345/items/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Connection: keep-alive
< Content-Type: text/plain
< Content-Length: 41
< Date: Fri, 02 Feb 2018 08:09:15 GMT
<
* Connection #0 to host localhost left intact
Retrieve the Item '' of the Order '12345'
This not happen when the path have just one path variable. I create the repo https://github.com/b0gg4rd/undertow-path-variable with
the two implementations.
Best Regards
Fernando Cruz