Search code examples
spring-securityspring-bootzk

DHtmlUpdateServlet - Error found at client: [Receive] Unexpected token < (SyntaxError)


I'm upgrading an application (JDK 6, ZK 6.5, Spring Framework 3.2, Spring Security 3.1) to JDK 8 with ZK 8 + Spring Security 4 + Spring Boot 1.3 but I'm seeing the following error on successful sign-in (i.e., if the username or password are bad, I don't see this error):

10:13:39.139 [http-nio-8080-exec-220] DEBUG o.z.zk.au.http.DHtmlUpdateServlet - Error found at client:
    [Receive]Unexpected token < (SyntaxError)     
    sid: 9524     
    user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
    content-length: 309
    content-type: application/x-www-form-urlencoded;charset=UTF-8
    ip: 0:0:0:0:0:0:0:1

which causes an ugly ZK framework-based pop-up on the client. The page rendered when this error happens is /secure/login.zul but tidy reports no errors in the page:

tidy -xml ./src/main/webapp/secure/login.zul
No warnings or errors were found.

/secure/login.zul:

<?xml version="1.0" encoding="UTF-8"?>
<?page title="Login"?>
<?init class="com.xxxxxx.web.OnlyAnonymousInitiator"?>
<zk xmlns="http://www.zkoss.org/2005/zul" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd" xmlns:n="native" xmlns:h="http://www.w3.org/1999/xhtml"
    xmlns:w="client">
  <n:div class="container_16">
    <n:div class="grid_12">
      <idspace>
    <panel border="normal">
      <caption label="Login" />
      <panelchildren apply="com.xxxx.web.pages.login.LoginMainComposer">
        <n:div class="xxxxxx-panel-contents">
          <n:table class="xxxxxx-table-plain">
        <n:tr>
          <n:td>
            <label value="Username:" />
          </n:td>
          <n:td>
            <textbox id="username" />
          </n:td>
        </n:tr>
        <n:tr>
          <n:td>
            <label value="Password:" />
          </n:td>
          <n:td>
            <textbox id="password" type="password" />
          </n:td>
        </n:tr>
        <n:tr>
          <n:td />
          <n:td>
            <button id="login" label="Log in" image="/images/icons/door_in.png" />
          </n:td>
        </n:tr>
          </n:table>
          <button href="/" label="Cancel" image="/images/icons/cross.png" />
        </n:div>
      </panelchildren>
    </panel>
      </idspace>
    </n:div>
  </n:div>
</zk>

and this page works fine in the original application. The zk.xml file is very simple:

<?xml version="1.0" encoding="UTF-8"?>
<zk>
  <desktop-config>
    <theme-uri>/css/960.css</theme-uri>
    <theme-uri>/css/xxxxxx.css</theme-uri>
  </desktop-config>
  <system-config>
    <ui-factory-class>
      com.xxxxxx.web.XxxxxxUiFactory
    </ui-factory-class>
  </system-config>
  <device-config>
    <device-type>ajax</device-type>
    <server-push-class>
      fi.gekkio.splake.atmosphere.AtmosphereServerPush
    </server-push-class>
  </device-config>
  <library-property>
    <name>org.zkoss.theme.preferred</name>
    <value>atlantic</value>
  </library-property>
  <library-property>
    <name>org.zkoss.bind.DebuggerFactory.enable</name>
    <value>true</value>
  </library-property>
</zk>

Any idea what the root of this error is? Or how to get more information from ZK to debug it? Or how to solve it?

Reviewing code ZK framework code, I see:

final String errClient = request.getHeader("ZK-Error-Report");
        if (errClient != null)
            if (log.isDebugEnabled()) 
                log.debug(
                    "Error found at client:
                        "+errClient+"\n"+Servlets.getDetail(request));

and reviewing the response headers, I do see:

Referer:http://localhost:8080/xxxxxx/secure/login.zul
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
ZK-Error-Report:[Receive] Unexpected token < (SyntaxError)
ZK-SID:1111

and the following response headers:

ZK-Error:410
ZK-SID:1111

(The SID is different from the original but it's the same error...) In Chrome, I see two requests when the error is triggered:

Request URL:http://localhost:8080/xxxxxx/zkau
Request Method:POST
Status Code:302 Found
Remote Address:[::1]:8080
Response Headers
view source

followed by:

Request URL:http://localhost:8080/xxxxxx/
Request Method:GET
Status Code:200 OK
Remote Address:[::1]:8080

so it seems likely, the (mis-)handling of the 302 above triggers this error message somehow.


Solution

  • Ugh - very frustrating.

    After spending many hours trying to track down this issue within ZK without finding a workable solution, I gave up; I've replaced ZK with Spring Boot, Spring Security, and Angular 2 and I'm now making progress.