0

My question is How to hide the zul extension shown in the URL?

For security reasons, we don't want to show the technology used in our application.

Url:

http://localhost:8080/warname/index.zul 

and I want the url to look like this instead:

http://localhost:8080/warname/index

or

http://localhost:8080/warname/

means index.zul or .zul need to hide from url.

ZK Version: 8.0.0
Server: wildfly-8.2.1.Final
jdk: jdk1.8.0_51
Eclipse Version: Neon.2 Release (4.6.2)

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
  <display-name>test4</display-name>
  <listener>
    <description>
        Used to cleanup when a session is destroyed</description>
    <display-name>ZK Session cleaner</display-name>
    <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
  </listener>
  <servlet>
    <description>
        The ZK loader for ZUML pages</description>
    <servlet-name>zkLoader</servlet-name>
    <servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
    <init-param>
      <param-name>update-uri</param-name>
      <param-value>/zkau</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <description>
        The asynchronous update engine for ZK</description>
    <servlet-name>auEngine</servlet-name>
    <servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zul</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zhtml</url-pattern>
  </servlet-mapping>
   <servlet-mapping>
    <servlet-name>auEngine</servlet-name>
    <url-pattern>/zkau/*</url-pattern>
  </servlet-mapping>

 <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>index.zul</welcome-file>
  </welcome-file-list>
</web-app>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MANOJ
  • 41
  • 7

1 Answers1

2

I can only follow Bilbo Baggins recommendation:

change the url pattern

There are many ways to do that, here just a few...

  1. specify a welcome file list in your web.xml (here an example)

This will display the index.zul of any folder if no filename is given in the URL.

  1. Using an HTTP server e.g. using Apache httpd in combination with mod_rewrite

  2. If you want to keep things within your application server the Servlet Spec provides a method RequestDispatcher.forward() which you can use in a servlet filter or servlet

Similar to this question/answer you can do the same for zul files.

package your.package;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class NoZulForwardingFilter implements Filter {
    private static final String ZUL_VIEW_ROOT_PATH = "/pages";
    private static final String ZUL_VIEW_SUFFIX = ".zul";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {}

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
        String servletPath = httpServletRequest.getServletPath();
        //Only process the paths starting with /pages, so as other requests get unprocessed.
        //You can register the filter itself for /pages/* only, too
        if (servletPath.startsWith(ZUL_VIEW_ROOT_PATH)
                && !servletPath.contains(ZUL_VIEW_SUFFIX)) {
            request.getRequestDispatcher(servletPath.concat(ZUL_VIEW_SUFFIX))
                    .forward(request, response);
        } else {
            chain.doFilter(httpServletRequest, response);
        }
    }

    @Override
    public void destroy() { }
}

and configure it in your web.xml

<filter>
    <filter-name>nozulforwarding</filter-name>
    <filter-class>your.package.NoZulForwardingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>nozulforwarding</filter-name>
    <url-pattern>/pages/*</url-pattern>
</filter-mapping>
  1. Finally if you don't want any zul files in your ZK application you can use a java only approach called Richlets.

NOTE: NONE of these techniques will hide that your application was written in ZK, as it always downloads specific JavaScript files containing ZK's client API. This will make it obvious to anyone that you are using ZK even if hiding parts of your URL.

cor3000
  • 936
  • 1
  • 6
  • 16