You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by am...@apache.org on 2015/12/17 18:53:23 UTC
struts git commit: WW-4545 - Setting status code in HttpHeaders will
be ignored
Repository: struts
Updated Branches:
refs/heads/support-2-3 8bbfb461c -> f29585248
WW-4545 - Setting status code in HttpHeaders will be ignored
(cherry picked from commit 4cd9a74cb8efa8dc0d3c57ac267a70b0538f3bf0)
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/f2958524
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/f2958524
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/f2958524
Branch: refs/heads/support-2-3
Commit: f2958524823a2b514aa5de239d264cf6a622297d
Parents: 8bbfb46
Author: Johannes Geppert <jo...@apache.org>
Authored: Thu Sep 10 19:11:12 2015 +0200
Committer: Aleksandr Mashchenko <am...@apache.org>
Committed: Thu Dec 17 19:45:59 2015 +0200
----------------------------------------------------------------------
.../rest/DefaultContentTypeHandlerManager.java | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/f2958524/plugins/rest/src/main/java/org/apache/struts2/rest/DefaultContentTypeHandlerManager.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/DefaultContentTypeHandlerManager.java b/plugins/rest/src/main/java/org/apache/struts2/rest/DefaultContentTypeHandlerManager.java
index b1bcffc..c55f319 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/DefaultContentTypeHandlerManager.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/DefaultContentTypeHandlerManager.java
@@ -126,8 +126,12 @@ public class DefaultContentTypeHandlerManager implements ContentTypeHandlerManag
*/
public String handleResult(ActionConfig actionConfig, Object methodResult, Object target) throws IOException {
String resultCode = readResultCode(methodResult);
+ Integer statusCode = readStatusCode(methodResult);
HttpServletRequest req = ServletActionContext.getRequest();
HttpServletResponse res = ServletActionContext.getResponse();
+ if(statusCode != null) {
+ res.setStatus(statusCode);
+ }
ContentTypeHandler handler = getHandlerForResponse(req, res);
if (handler != null) {
@@ -143,13 +147,22 @@ public class DefaultContentTypeHandlerManager implements ContentTypeHandlerManag
res.setContentLength(data.length);
res.setContentType(handler.getContentType());
res.getOutputStream().write(data);
- res.getOutputStream().close();
+ res.getOutputStream().flush();
}
}
}
return resultCode;
}
+
+ protected Integer readStatusCode(Object methodResult) {
+ if (methodResult instanceof HttpHeaders) {
+ return ((HttpHeaders) methodResult).getStatus();
+ } else {
+ return null;
+ }
+ }
+
protected String readResultCode(Object methodResult) {
if (methodResult == null) {
return null;