Author: thomas.heute(a)jboss.com
Date: 2008-01-15 06:46:05 -0500 (Tue, 15 Jan 2008)
New Revision: 9508
Modified:
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
Log:
[JBPORTAL-1867] Fail to set `Last-Modified' HTTP header - content not cached, bad for
reverse proxy
Contribution from Mike Millson
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-01-15
11:34:57 UTC (rev 9507)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-01-15
11:46:05 UTC (rev 9508)
@@ -126,7 +126,7 @@
else if (controllerResponse instanceof StreamContentResponse)
{
StreamContentResponse scr = (StreamContentResponse)controllerResponse;
- return HTTPResponse.sendBinary(scr.getContentType(), scr.getInputStream());
+ return HTTPResponse.sendBinary(scr.getContentType(), scr.getLastModified(),
scr.getInputStream());
}
else if (controllerResponse instanceof SecurityErrorResponse)
{
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java 2008-01-15
11:34:57 UTC (rev 9507)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java 2008-01-15
11:46:05 UTC (rev 9508)
@@ -35,11 +35,17 @@
/** . */
private String contentType;
+
+ /**
+ * The time the content was last modified, measured in milliseconds since
+ * the epoch (00:00:00 GMT, January 1, 1970).
+ */
+ private long lastModified;
/** . */
private InputStream inputStream;
- public StreamContentResponse(String contentType, InputStream inputStream)
+ public StreamContentResponse(String contentType, long lastModified, InputStream
inputStream)
{
if (contentType == null)
{
@@ -50,6 +56,7 @@
throw new IllegalArgumentException();
}
this.contentType = contentType;
+ this.lastModified = lastModified;
this.inputStream = inputStream;
}
@@ -57,6 +64,11 @@
{
return contentType;
}
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
public InputStream getInputStream()
{
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-01-15
11:34:57 UTC (rev 9507)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-01-15
11:46:05 UTC (rev 9508)
@@ -54,7 +54,7 @@
};
}
- public static HTTPResponse sendBinary(final String contentType, final InputStream in)
+ public static HTTPResponse sendBinary(final String contentType, final long
lastModified, final InputStream in)
{
return new HTTPResponse()
{
@@ -62,6 +62,7 @@
{
HttpServletResponse resp = ctx.getClientResponse();
resp.setContentType(contentType);
+ resp.addDateHeader("Last-Modified", lastModified);
ServletOutputStream sout = null;
try
{
Modified:
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java 2008-01-15
11:34:57 UTC (rev 9507)
+++
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java 2008-01-15
11:46:05 UTC (rev 9508)
@@ -86,8 +86,18 @@
}
Content content = file.getContent();
String mimeType = content.getMimeType();
+ long lastModified;
+ if(content.getLastModified() != null)
+ {
+ lastModified = content.getLastModified().getTime();
+ }
+ else
+ {
+ // Use current time in none available
+ lastModified = System.currentTimeMillis();
+ }
InputStream inputStream = content.getStream();
- return new StreamContentResponse(mimeType, inputStream);
+ return new StreamContentResponse(mimeType, lastModified, inputStream);
}
catch (Exception e)
{
Show replies by date