How to configure Weblogic application Sever for Angular application
If it should be more comfortable than creating your own filter you could use: org.tuckey.urlrewritefilter http://tuckey.org/urlrewrite/
Simple 3 steps:
- Add the dependency to your pom.xml
- Add the filter UrlRewriteFilter from tuckey to the web.xml
- Configure the filter in a urlrewrite.xml
From my experience it is very handy (especially compared to the supported patterns in web.xml).
An example rule could be:
<rule>
<from>^/webapp/*</from>
<to>/webapp/index.html</to>
</rule>
Use a servlet filter. If the request is a GET, and should be forwarded to index.html, then forward it to index.html. Otherwise, pass the request down the chain. Here's an example of such a filter. Of course, depending on the architecture of your application, the conditions could be different:
@WebFilter(value = "/*")
public class IndexFilter implements Filter {
@Override
public void doFilter(ServletRequest req,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
if (mustForward(request)) {
request.getRequestDispatcher("/index.html").forward(request, response);
return;
}
chain.doFilter(request, response);
}
private boolean mustForward(HttpServletRequest request) {
if (!request.getMethod().equals("GET")) {
return false;
}
String uri = request.getRequestURI();
return !(uri.startsWith("/api")
|| uri.endsWith(".js")
|| uri.endsWith(".css")
|| uri.startsWith("/index.html")
|| uri.endsWith(".ico")
|| uri.endsWith(".png")
|| uri.endsWith(".jpg")
|| uri.endsWith(".gif")
|| uri.endsWith(".eot")
|| uri.endsWith(".svg")
|| uri.endsWith(".woff2")
|| uri.endsWith(".ttf")
|| uri.endsWith(".woff");
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// nothing to do
}
@Override
public void destroy() {
// nothing to do
}
}