@Override
  public String getResponseCharacterEncoding() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      String characterEncoding = mimeResponse.getCharacterEncoding();

      if (manageIncongruities) {
        incongruityContext.setResponseCharacterEncoding(characterEncoding);
      }

      return characterEncoding;
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseCharacterEncoding();
      } else {

        if (portletResponse instanceof StateAwareResponse) {

          // TCK TestPage169: getResponseCharacterEncodingActionTest
          // TCK TestPage180: getResponseCharacterEncodingEventTest
          throw new IllegalStateException();
        } else {
          return null;
        }
      }
    }
  }
  @Override
  public String getCharacterEncoding() {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.getCharacterEncoding();
    } else {
      return null;
    }
  }
  @Override
  public String getResponseCharacterEncoding() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      String characterEncoding = mimeResponse.getCharacterEncoding();

      if (manageIncongruities) {
        incongruityContext.setResponseCharacterEncoding(characterEncoding);
      }

      return characterEncoding;
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseCharacterEncoding();
      } else {

        if (portletResponse instanceof StateAwareResponse) {

          String characterEncoding =
              (String)
                  bridgeContext.getAttributes().get(ViewHandlerImpl.RESPONSE_CHARACTER_ENCODING);

          if (characterEncoding != null) {

            // Workaround for patch applied to Mojarra in JAVASERVERFACES-3023
            return characterEncoding;
          } else {

            // TCK TestPage169: getResponseCharacterEncodingActionTest
            // TCK TestPage180: getResponseCharacterEncodingEventTest
            throw new IllegalStateException();
          }
        } else {
          return null;
        }
      }
    }
  }