<div dir="ltr">So what is our solution here?  It seems I&#39;m darned if I do and darned if I don&#39;t.  <div><br></div><div>If I move the predicates until after the servlet then I can call sendError() on the servlet response to trigger the error pages, however I lose the ability to rewrite the request (a deal breaker)  <div><br></div><div>But if I leave the predicates before the servlet, I can perform rewrites, but I can no longer call sendError() since, as you said, there is no servlet response yet!</div><div><br></div><div>I understand the separation between the servlet and core, but it&#39;s killing me here.  This seems like such a simple concept.  </div><div><ul><li>I have a servlet deployment with error page configured</li><li>I want to have a predicated handler that uses the configured error pages</li></ul></div><div>Can I accomplish this with a default response listener that accesses the error page configuration and dispatches the appropriate location?  Even that feels dirty. It seems there should be a handler invoked directly from the predicates that can dispatch the error pages configured in the servlet.  Even if all it did was look up the corresponding location for the given status code and forward the request there. But I can&#39;t even figure out how to access the deployment from the exchange.</div><div><br clear="all"><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div></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><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 2, 2020 at 9:22 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, 3 Jul 2020 at 10:34, 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">Before I give that workaround a try, a couple existential questions...<div><ul><li>Should the <b>response-code</b> handler also set the <b>errorCode</b> as well in the servlet request context so it triggers the doErrorDispatch() action?</li><li>Or should there be another built-in handler called &quot;send-error&quot; or similar that does this.</li></ul><div>Ex: </div></div><div><font face="monospace" color="#0000ff">path( /secret.json ) -&gt; 

send-error

( 404 )</font></div><div><font face="monospace" color="#0000ff">path( /admin/ ) -&gt; 

send-error( 503 )</font></div><div><br></div><div>I&#39;m sort of questioning what the usefulness is of the <b>response-code</b> handler however (at least in the context of the predicate language) if it&#39;s default behavior is NOT to trigger the error code and therefore the error page.  </div></div></blockquote><div><br></div><div>These error pages are part of Servlet, while the predicate language is part of core. The response-code handler does not really know anything about the Servlet deployment.<br></div><div><br></div><div>Generally the predicate language is run before Servlet (e.g. in WildFly), so the HttpServletRequest/Response has not been created yet. This gives a lot of flexibility in that you can make changes to route the request to different contexts and potentially skip servlet altogether, but the down side is that it is not tightly integrated with Servlet. <br></div><div><br></div><div>Stuart<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><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div></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><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 2, 2020 at 7:01 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>Hmm, this is because the servlet status code is only triggered by a sendError method, not by just setting the code.</div><div><br></div><div>You probably need to write a custom one that looks like this (plus the relevant predicate languge bits):</div><div><br></div><div>public class SendErrorHandler implements HttpHandler {<br>    <br>    private final int code;<br><br>    public SendErrorHandler(int code) {<br>        this.code = code;<br>    }<br><br>    @Override<br>    public void handleRequest(HttpServerExchange exchange) throws Exception {<br>        ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);<br>        ((HttpServletResponse)src.getServletResponse()).sendError(code);<br>    }<br>}</div><div><br></div><div>Stuart<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 3 Jul 2020 at 09:40, 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">Thanks for the reply Stuart.  I&#39;ve tried this with no success, but perhaps I&#39;m doing it wrong.<div><br><font face="monospace" color="#0000ff">List&lt;PredicatedHandler&gt; ph = PredicatedHandlersParser.parse(predicatesLines, _classLoader);<br>servletBuilder.addOuterHandlerChainWrapper(next -&gt; Handlers.predicates(ph,next));</font><br></div><div><br></div><div>When the response-code handler fires, I still get no response body.</div><div><br></div><div>On a related note, when I move the predicates into an outer handler chain wrapper, my default response listener also doesn&#39;t fire at all.  </div><div><br></div><div>On an unrelated train of thought, I&#39;ve been trying to see if I can get the default response listener to automatically dispatch the correct error page, but that hasn&#39;t been going well either.  If I don&#39;t use the outer handler chain idea, but try to capture the empty response in a default response listener, I can return a static message using the Sender class</div><div><br></div><div><font face="monospace" color="#0000ff">Sender sender = exchange.getResponseSender();<br>sender.send(errorHTMLString);</font><br></div><div><br></div><div>But if I try to run something this in my default response listener to invoke my error pages</div><div><br></div><div><font face="monospace" color="#0000ff">ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);<br>HttpServletResponseImpl response = src.getOriginalResponse();<br>response.doErrorDispatch( exchange.getStatusCode(), exchange.getReasonPhrase() );</font><br></div><div><br></div><div>Then it&#39;s as though nothing happens and I still get an empty response.</div><div><br clear="all"><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div></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><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 2, 2020 at 6:17 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>The predicate languages are executed before the Servler handlers, so they won&#39;t be handled by Servlet error pages.</div><div><br></div><div>If you are setting this all up programmatically you could use io.undertow.servlet.api.DeploymentInfo#addOuterHandlerChainWrapper to setup the predicate handler after the initial servlet one, which should mean that the servlet error handling will handle the response code.</div><div><br></div><div>Stuart<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 3 Jul 2020 at 08:25, 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">When I configure an error page similar to this:<div><br></div><div><font face="monospace" color="#0000ff">servletBuilder.addErrorPage( new ErrorPage( &quot;404.html&quot;, 404));</font><br></div><div><br></div><div>This works great when I hit a path in my browser that doesn&#39;t exist.  The contents of the <b>404.html</b> file is served with a response code of <b>404</b>.</div><div><br></div><div>However, if I also use the predicate language to define something like:</div><div><br></div><div><font face="monospace" color="#0000ff">path(/box.json)-&gt;response-code(404)</font><br></div><div><br></div><div>and then I hit <b>localhost/box.json</b> in my browser, I get a <b>404</b> status code but with no response body. </div><div><ul><li>The docs say the response-code handler ends the exchange, but should it still respect the error pages?<br></li><li>How can I modify my use of Undertow to respect the error pages when using the response-code handler?</li><li>I&#39;ve seen in the docs the ability to have a <b>addDefaultResponseListener()</b> but I&#39;m not sure if it is the correct solution for this, nor how I would access the error page configuration dynamically as to not need to duplicate my work.</li></ul></div><div><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><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>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>