}
cookies = null;
}
if (isMimeResponse) {
MimeResponse mimeResponse = (MimeResponse) response;
ResourceResponse resourceResponse = isResourceResponse ? (ResourceResponse) response : null;
if (locale != null) {
try {
resourceResponse.setLocale(locale);
}
catch (UnsupportedOperationException usoe) {
// TODO: temporary "fix" for JBoss Portal which doesn't
// yet
// support this
// (although required by the Portlet API 2.0!)
}
}
if (contentType != null) {
if (characterEncoding != null) {
if (setContentTypeAfterEncoding) {
resourceResponse.setCharacterEncoding(characterEncoding);
resourceResponse.setContentType(contentType);
}
else {
resourceResponse.setContentType(contentType);
resourceResponse.setCharacterEncoding(characterEncoding);
}
}
else {
mimeResponse.setContentType(contentType);
}
}
else if (characterEncoding != null) {
resourceResponse.setCharacterEncoding(characterEncoding);
}
if (headers != null) {
for (Map.Entry<String, ArrayList<String>> entry : headers.entrySet()) {
for (String value : entry.getValue()) {
mimeResponse.addProperty(entry.getKey(), value);
}
}
headers = null;
}
if (isResourceResponse && hasStatus) {
resourceResponse.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(statusCode));
}
if (isResourceResponse && contentLength > -1) {
try {
resourceResponse.setContentLength(contentLength);
}
catch (UnsupportedOperationException usoe) {
// TODO: temporary "fix" for JBoss Portal which doesn't
// yet
// support this
// (although required by the Portlet API 2.0!)
}
}
}
if (!hasError && !closed && redirectLocation == null && isMimeResponse) {
MimeResponse mimeResponse = (MimeResponse) response;
if (outputStream != null) {
outputStream.flush();
byteOutputBuffer.writeToAndClose(mimeResponse.getPortletOutputStream());
}
else if (printWriter != null) {
printWriter.flush();
charOutputBuffer.writeToAndClose(mimeResponse.getWriter());
}
}
if (outputStream != null) {
outputStream.close();