<div dir="ltr"><div style="text-align:left">Thanks for the reply, this is helpful.  I was thinking through this today and came to some of the same conclusions-- the issue of potentially more than one deployment and using a static variable for a custom predicate to &quot;find&quot; the servlet information.  </div><div style="text-align:left"><br></div><div style="text-align:left">Here&#39;s a few brainstorms-- </div><div style="text-align:left"><br></div><div style="text-align:left">Is there a programmatic way to access all of the servlet deployments that have been created?  What if, in the event that there is no servlet context in the exchange, the file and directory predicates could check and see if only one servlet context existed, and if so, just grab that one?  That doesn&#39;t solve the scenario where two or more deployments exist, but it would at least allow it to make a decent guess for single deployments.  </div><div style="text-align:left"><br></div><div style="text-align:left">Being able to specify a given deployment when creating a predicate handler chain is an interesting idea as well, but I&#39;m not entirely sure how many things in the API would need to change to get it all the way down to the predicatebuilder&#39;s build() call.  In my particular case, I&#39;m using the PredicatedHandlersParser.</div><div style="text-align:left"><br></div><div style="text-align:left">And on the topic of using the dispatcher-- what if instead of writing a new handler, the existing handler detected if it was inside the servlet, and if so, it used the dispatcher, and if there was no servlet, it just fell back to its current behavior of using the SetAttribtueHandler to override the relative path?  From an architectural standpoint, I don&#39;t know if it would be against &quot;the rules&quot; to have a handler in the core package touching stuff in the servlet package. </div><div><div style="text-align:left"><br></div><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div></div><div style="text-align:left">Thanks!</div><div style="text-align:left"><br></div><div style="text-align:left">~Brad</div><div style="text-align:left"><br></div><div style="text-align:left"><b>Developer Advocate</b></div><div style="text-align:left"><i>Ortus Solutions, Corp </i></div><div style="text-align:left"><b><br></b></div><div style="text-align:left">E-mail: <a href="mailto:brad@coldbox.org" target="_blank">brad@coldbox.org</a></div><div style="text-align:right">ColdBox Platform: <a href="http://www.coldbox.org" target="_blank">http://www.coldbox.org</a> </div><div style="text-align:right">Blog: <a href="http://www.codersrevolution.com" target="_blank">http://www.codersrevolution.com</a></div><div style="text-align:right"><br></div></div></div></div></div></div><div style="text-align:right"><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 9, 2020 at 7:05 PM Stuart Douglas &lt;<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>&gt; 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"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 10 Jul 2020 at 02:44, Brad Wood &lt;<a href="mailto:bdw429s@gmail.com" target="_blank">bdw429s@gmail.com</a>&gt; 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">So, in my bid to put the predicate language through the paces, I&#39;ve been testing out all the rewrite rules I&#39;ve ever used with mod_rewrite or Tuckey Rewrite to see if Undertow&#39;s handlers are up to the task.  <div><br></div><div>I&#39;ve run into an issue again with probably the most common rewrite rule of any CFML app using an MVC framework, which is a rule that creates so-called &quot;SES&quot; URLs and force all requests through a front controller design pattern.  </div><div><br></div><div>Basically</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace"><a href="http://site.com/home/about" target="_blank">site.com/home/about</a></font></blockquote><div><br></div><div>gets rewritten to</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace"><a href="http://site.com/index.cfm/home/about" target="_blank">site.com/index.cfm/home/about</a></font></blockquote><div><br></div><div>Here you can see how this rule is typically accomplished in Apache httpd, Nginx, IIS, and Tuckey:</div><div><br></div><div><a href="https://coldbox.ortusbooks.com/the-basics/routing/requirements/rewrite-rules" target="_blank">https://coldbox.ortusbooks.com/the-basics/routing/requirements/rewrite-rules</a> </div><div> <br></div><div>The hang up is that<i> any incoming path that maps to an actual file</i> skips the rewrite rule.  That way<b> /images/logo.jpg</b> doesn&#39;t get rewritten. </div><div><br></div><div>So here was my first stab at it with Undertow&#39;s predicate language-- it seemed simple enough:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font face="monospace">not file and not directory -&gt; rewrite(&#39;/index.cfm/%{RELATIVE_PATH}&#39;)</font></blockquote><div><br></div><div>But our old friend the servlet of course is nowhere to be found since my &quot;file&quot; and &quot;directory&quot; predicates were executing in the root handler chain so there is no concept of a servlet&#39;s context root with which to resolve file system paths. </div><div><br></div><div>So basically, I understand exactly why this doesn&#39;t work, but I feel that we need to find a way to make this work.  This is a feature that pretty much every rewrite engine I&#39;ve ever used has-- the ability to test the file system to see if a file or directory exists.  Can we discuss the following options?</div><div><ul><li>Find a way for the root handler chain to access the deployment&#39;s resource manager </li></ul></div></div></blockquote><div><br></div><div>The big conceptual problem here is that there can be multiple Servlet deployments, and the rewrite could change which deployment actually gets served by the request. You could write a custom predicate to handle this, but you would need to stick the Servlet deployment in a static variable so the PredicateBuilder has access to it. We could do it with some API changes I guess, have the PredicateBuilder accept a Map&lt;String, Object&gt;, so you could pass in the ServletContext as you are building the predicates.<br></div><div> </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><ul><li>Find a way for the rewrite handler to correctly affect not only the exchange but also (optionally) the HttpServletRequest so it&#39;s possible to rewrite the URL inside of the servlet&#39;s handler chain. I know for certain this is possible because the Tuckey Rewrite engine is implemented as a servlet filter.</li></ul></div></div></blockquote><div>This would be done using RequestDispatcher.forward(), you could write a handler that uses this, or you could write one that uses the Undertow specific io.undertow.servlet.api.Deployment#getServletDispatcher() to re-dispatch without calling forward. <br></div><div><br></div><div>Stuart<br></div><div><br></div><div> </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><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div>I would prefer the first option since I do like having the predicates in the root handler chain so it can run as early as possible.</div><div><br></div><div>Thanks!</div><div><br></div><div>~Brad</div><div><br></div><div><b>Developer Advocate</b></div><div><i>Ortus Solutions, Corp </i></div><div><b><br></b></div><div>E-mail: <a href="mailto:brad@coldbox.org" target="_blank">brad@coldbox.org</a></div><div>ColdBox Platform: <a href="http://www.coldbox.org" target="_blank">http://www.coldbox.org</a> </div><div>Blog: <a href="http://www.codersrevolution.com" target="_blank">http://www.codersrevolution.com</a></div><div><br></div></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></div>
</blockquote></div>