Are you looking for path parameters?
rh0 = new RoutingHandler().post("/xd/{cohort}/healthevents/examdata", new UndertowEventHttpHandler(config, posthandlers));
https://www.stubbornjava.com/posts/query-parameters-and-path-parameters-in-undertow#path-parameter-and-query-parameter-routinghandler

Once you have path parameters working properly you should be able to have one route for GET and one for POST and it should work fine.

On Mon, Mar 23, 2020 at 9:24 AM David Robinson <drobin1437@gmail.com> wrote:
I believe these two questions are very basic based on the posts I've read so far on the mailing list.  I appreciate your insights into how to handle these correctly using undertow handlers (was thinking custom handlers).

First topic: a portion of the URI for my app is "dynamic" and changes as my program runs.
For example, with this URI:
     /xd/cohort1/healthevents/examdata
the "cohort1"  portion "appears" after my program starts.
Each cohort may have distinct processing - so this URI:
    /xd/cohort0/healthevents/examdata
needs to be handled by code that may be entirely different from the first URI.

In a first approach, a single custom handler for the path /sd/* was configured:
rh0 = new RoutingHandler().post("/xd/*", new UndertowEventHttpHandler(config, posthandlers));
Undertow server = Undertow.builder().addHttpListener(ipPort, ipAddress).setHandler(rh0).build();
That examined the URI, validated the "cohort" piece, and then called a separate helper class directly (no dispatch, or async) to process the request.  

Is this the best approach or is there a better way to handle this with Undertow?
(The out-of-the-box Path Template handler, for example, did not seem dynamic enough to handle this sort of URI.)

Second topic: the application can receive "GETS" and "POSTS" to the same URI. 

A "GET" to  /xd/cohort1/healthevents/examdata  would return data where a 
POST to  /xd/cohort1/healthevents/examdata  would expect the body of the message to have JSON to be stored.

How to best handle both GET and POST messages coming to the same URI with Undertow?  I started to add an extra layer of abstraction - a generic handler that looked at the request method 
HttpString hString = exchange.getRequestMethod();
but was not sure where to go from there...do I then call the specialized POST and GET handlers with .dispatch (deprecated except if I provide an Executor?) or is there a way to register two handlers for the same path...just different request methods?

Thank you,




_______________________________________________
undertow-dev mailing list
undertow-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev