randomly the Http Response has been committed
oliver.yao Apr 24, 2014 1:39 AMIn our project, using the jboss version
boss-eap-6.1.0. And in some case, the response is committed when we send a request and want a reponse. This will cause other unexpectly result. I want to know the reason. Is it jboss bug?
This is a test java source.
package test;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
* test for response encoding issue.
* add following to the top of the web.xml file.
<filter>
<filter-name>TestFilter</filter-name>
<display-name>TestFilter</display-name>
<description>Test Filter</description>
<filter-class>test.TestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TestFilter</filter-name>
<servlet-name>/*</servlet-name>
</filter-mapping>
*
*
*/
public class TestFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
System.out.println("******* investigationFilterIn: Response Committed (" + String.valueOf(response.isCommitted()) + "), CharEncoding (" + response.getCharacterEncoding() + ")");
//response.setCharacterEncoding(pageCharEncoding);
response.setContentType("text/html; charset=UTF-8"); // default response contentType. It could be changed later
String resStatus = "";
try {
java.lang.reflect.Method method = response.getClass().getMethod("getStatus", null); // servlet 3.0 and above
resStatus = method.invoke(response, null).toString();
} catch (Exception e) {
resStatus = "unknown";
}
System.out.println("******* investigationFilterOut: URL (" + ((HttpServletRequest)request).getRequestURI() + "), Response Class (" + response.getClass().getName() + "), Status (" + resStatus + "), Committed (" + String.valueOf(response.isCommitted()) + "), CharEncoding (" + response.getCharacterEncoding() + "), Buffer size (" + String.valueOf(response.getBufferSize()) + ")");
if (!"UTF-8".equalsIgnoreCase(response.getCharacterEncoding())) System.out.println("+++++++++ investigationFilter Response CharEncoding Error. URL is " + ((HttpServletRequest)request).getRequestURI());
chain.doFilter(request, response);
}
public void init(FilterConfig cfg) throws ServletException {
}
}
This is the unexpected result after run the application.
10:02:42,307 INFO [stdout] (http-/0.0.0.0:8980-8) ******* investigationFilterIn: Response Committed (true), CharEncoding (ISO-8859-1)
10:02:42,307 INFO [stdout] (http-/0.0.0.0:8980-8) ******* investigationFilterOut: URL (/scf/cda/portalPanel.do), Response Class (org.apache.catalina.connector.ResponseFacade), Status (200), Committed (true), CharEncoding (ISO-8859-1), Buffer size (8192)
10:02:42,308 INFO [stdout] (http-/0.0.0.0:8980-8) +++++++++ investigationFilter Response CharEncoding Error. URL is /scf/cda/portalPanel.do
10:02:42,308 INFO [stdout] (http-/0.0.0.0:8980-8) ******* investigationInit: URL (/scf/cda/portalPanel.do), Response Class (org.apache.catalina.connector.ResponseFacade), Status (200), Committed (true), CharEncoding (ISO-8859-1), Buffer size (8192)
10:02:42,308 INFO [stdout] (http-/0.0.0.0:8980-8) +++++++++ investigationInit Response CharEncoding Error. URL is /scf/cda/portalPanel.do
This is normal result after run the application.
10:02:43,968 INFO [stdout] (http-/0.0.0.0:8980-10) ******* investigationFilterIn: Response Committed (false), CharEncoding (ISO-8859-1)
10:02:43,968 INFO [stdout] (http-/0.0.0.0:8980-10) ******* investigationFilterOut: URL (/scf/cda/bankList.do), Response Class (org.apache.catalina.connector.ResponseFacade), Status (200), Committed (false), CharEncoding (UTF-8), Buffer size (8192)
10:02:43,969 INFO [stdout] (http-/0.0.0.0:8980-10) ******* investigationInit: URL (/scf/cda/bankList.do), Response Class (org.apache.catalina.connector.ResponseFacade), Status (200), Committed (false), CharEncoding (UTF-8), Buffer size (8192)
10:02:43,993 INFO [stdout] (http-/0.0.0.0:8980-10) ******* investigationTop: Response committed (false). CharEncoding is UTF-8
We test 518 time. And the unexpected result have 6 time, the other is normal.