We happened to found that Tomcat doesn’t do blazeds streaming after version 7.0.27. This impacted one of our applications which still runs on Flex front end. Alternative was to use polling instead of streaming though it compromised on the performance. Out of curiosity I started hacking into this problem. Symptom was flex application just hangs without any error or anything. I checked tomcat release notes (http://tomcat.apache.org/tomcat-7.0-doc/changelog.html) and isolated problem up to Coyote jar file. When Coyote jar replaced on the later version this starts to work again. Out of Coyote release notes we found that one change was done to enforce developers not to have connection: close header when you have chunking in place.
53169: Allow developers to avoid chunked encoding for a response of unknown length by setting the Connection: close header. Based on a patch suggested by Philippe Marschall. (markt)
When we observe Blaze code that’s exactly what was happening. https://github.com/apache/flex-blazeds/blob/c7487aa0504d7561276f106c83ff63c7ff66d67c/modules/core/src/flex/messaging/endpoints/BaseStreamingHTTPEndpoint.java
// Open and commit response headers and get output stream.
if (addNoCacheHeaders)
addNoCacheHeaders(req, res);
res.setContentType(getResponseContentType());
res.setHeader("Connection", "close");
res.setHeader("Transfer-Encoding", "chunked");
ServletOutputStream os = res.getOutputStream();
res.flushBuffer();
There are couple of possible solutions to avoid this problem. 1. Remove close header from chunck-encoding response. While this could be achieved by multiple ways, one clear way would be to make use of a servlet filter. Kudos to vivimice who suggested this hack!
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, new HttpServletResponseWrapper(
(HttpServletResponse) response) {
public void setHeader(String name, String value) {
if (!("Connection".equalsIgnoreCase(name) && "Close"
.equalsIgnoreCase(value))) {
super.setHeader(name, value);
}
}
});
}
With configurations in web.xml:
<filter>
<filter-name>MessageBrokerHack</filter-name>
<filter-class>
chades.flex.MessageBrokerHack
</filter-class>
</filter>
<filter-mapping>
<filter-name>MessageBrokerHack</filter-name>
<url-pattern>/messagebroker/*</url-pattern>
</filter-mapping>
2. Recompile BaseStreamingHTTPEndpoint.java to remove connection-close header of the chunk-encoded response. You can download the modified version from https://github.com/charithdesilva/flex-blazeds/blob/master/modules/core/src/flex/messaging/endpoints/BaseStreamingHTTPEndpoint.java You can build the whole flex-messaging-core.jar file and replace it with what’s on your application.