<div dir="ltr">Are you looking for path parameters?<div><pre style="white-space:pre-wrap;color:rgb(0,0,0);font-family:Monaco;font-size:10.5pt"><pre style="white-space:pre-wrap;font-family:Monaco;font-size:10.5pt">rh0 = <span style="color:rgb(0,0,128);font-weight:bold">new </span>RoutingHandler().post(<span style="color:rgb(0,128,0);font-weight:bold">"/xd/{cohort}/healthevents/examdata"</span>, <span style="color:rgb(0,0,128);font-weight:bold">new </span>UndertowEventHttpHandler(config, posthandlers));</pre></pre></div><div><a href="https://www.stubbornjava.com/posts/query-parameters-and-path-parameters-in-undertow#path-parameter-and-query-parameter-routinghandler">https://www.stubbornjava.com/posts/query-parameters-and-path-parameters-in-undertow#path-parameter-and-query-parameter-routinghandler</a><br></div><div><br></div><div>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.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 23, 2020 at 9:24 AM David Robinson <<a href="mailto:drobin1437@gmail.com">drobin1437@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">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).<div><br></div><div>First topic: a portion of the URI for my app is "dynamic" and changes as my program runs.</div><div>For example, with this URI:</div><div> /xd/cohort1/healthevents/examdata</div><div>the "cohort1" portion "appears" after my program starts.</div><div>Each cohort may have distinct processing - so this URI:</div><div> /xd/cohort0/healthevents/examdata</div><div>needs to be handled by code that may be entirely different from the first URI.</div><div><br></div><div>In a first approach, a single custom handler for the path /sd/* was configured:</div><div><pre style="color:rgb(0,0,0);font-family:Monaco;font-size:10.5pt"><pre style="font-family:Monaco;font-size:10.5pt">rh0 = <span style="color:rgb(0,0,128);font-weight:bold">new </span>RoutingHandler().post(<span style="color:rgb(0,128,0);font-weight:bold">"/xd/*"</span>, <span style="color:rgb(0,0,128);font-weight:bold">new </span>UndertowEventHttpHandler(config, posthandlers));</pre></pre><pre style="color:rgb(0,0,0);font-family:Monaco;font-size:10.5pt">Undertow server = Undertow.<span style="font-style:italic">builder</span>().addHttpListener(ipPort, ipAddress).setHandler(rh0).build();</pre></div><div>That examined the URI, validated the "cohort" piece, and then called a separate helper class directly (no dispatch, or async) to process the request. </div><div><br></div><div>Is this the best approach or is there a better way to handle this with Undertow?</div><div>(The out-of-the-box Path Template handler, for example, did not seem dynamic enough to handle this sort of URI.)<br></div><div><br></div><div>Second topic: the application can receive "GETS" and "POSTS" to the same URI. </div><div><br></div><div>A "GET" to <span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium"> /xd/cohort1/healthevents/examdata would return data where a </span></div><div><span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium">POST to </span><span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium"> /xd/cohort1/healthevents/examdata would expect the body of the message to have JSON to be stored.</span></div><div><span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium"><br></span></div><div><span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium">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 </span></div><div><pre style="color:rgb(0,0,0);font-family:Monaco;font-size:10.5pt">HttpString hString = exchange.getRequestMethod();</pre></div><div>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?</div><div><br></div><div>Thank you,</div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div></div></div></div>
_______________________________________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a></blockquote></div>