You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Roy van Rijn (JIRA)" <de...@myfaces.apache.org> on 2009/08/20 13:05:14 UTC

[jira] Created: (TOMAHAWK-1442) ExtensionsResponseWrapper breaks Liskov substitution principle

ExtensionsResponseWrapper breaks Liskov substitution principle
--------------------------------------------------------------

                 Key: TOMAHAWK-1442
                 URL: https://issues.apache.org/jira/browse/TOMAHAWK-1442
             Project: MyFaces Tomahawk
          Issue Type: Bug
          Components: ExtensionsFilter
    Affects Versions: 1.1.8
            Reporter: Roy van Rijn


I've been working on a project which mixes JSF and Servlets. And in a particulair Servlet I'm writing to the response (in some cases). Later on I check if the response has been committed, but this doesn't work with the ExtensionsResponseWrapper.

The problem is this:
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getNativeResponse();

//Write the response:
response.getWriter().append(responseText.toString());

//Make sure its flushed (and thus closed/committed)
response.getWriter().flush();
response.flushBuffer();

log.debug(response.isCommitted);
----

This will print out: "false"

But it should be 'true' since we've written to the response and flushed the writer and the buffer.

The reason is the internal delegate of the ExtensionsResponseWrapper. This is used to write and read against, but the method isCommitted() is coupled to the state of the internal delegate (in the ServletResponseWrapper). 

My current work-around is:

/** For Tomahawk's ExtensionsFilter we need this: */
if(response instanceof ExtensionsResponseWrapper) {
	((ExtensionsResponseWrapper)response).getDelegate().getWriter().append(responseText.toString());
	((ExtensionsResponseWrapper)response).getDelegate().getWriter().flush();
	((ExtensionsResponseWrapper)response).finishResponse();
} else {
	response.getWriter().append(responseText.toString());
	response.getWriter().flush();
	response.flushBuffer();
}

This adds a new dependency to my framework which wasn't coupled to Tomahawk.. which I really don't want. But I can't seem to get it working otherwise. 

The problem is that the flush should set the isCommitted() to true... and this doesn't happen, breaking the Liskov substitution principle.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.