Thursday, October 26, 2006

BLOG: Jetty redirect the root to target application

If you are using Jetty, you will find that there is not very convenient not to have the default context. Therefore, you have to overcome the root context in jetty to use your own target context.

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Make https://server/ redirect to https://server/targetApp/ -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<Call name="addContext">
<Arg>
<New class="org.mortbay.http.HttpContext">
<Set name="ContextPath">/</Set>
<Call name="addHandler">
<Arg>
<New class="org.mortbay.http.handler.ForwardHandler">
<Set name="RootForward">/targetApp</Set>
<Call name="addForward">
<Arg>/favicon.ico</Arg>
<Arg>/targetApp/images/favicon.ico</Arg>
</Call>
</New>
</Arg>
</Call>
<Call name="addHandler">
<Arg>
<New class="targetApp.server.util.jetty.RedirectHandler" />
</Arg>
</Call>
</New>
</Arg>
</Call>

public class RedirectHandler implements org.mortbay.http.HttpHandler
{
public void handle(String pathInContext, String pathParams, HttpRequest httpRequest, HttpResponse httpResponse) throws HttpException, IOException
{
httpResponse.sendRedirect( "/targetApp" );
httpRequest.setHandled( true );
}
}

No comments:

Thumbs Up to GitHub Copilot and JetBrains Resharper

Having used AI tool GitHub Copilot since 08/16/2023, I’ve realized that learning GitHub Copilot is like learning a new framework or library ...