Author: christian.bauer(a)jboss.com
Date: 2009-08-25 04:16:50 -0400 (Tue, 25 Aug 2009)
New Revision: 11421
Modified:
branches/community/Seam_2_2/examples/wiki/build.xml
branches/community/Seam_2_2/examples/wiki/src/etc/META-INF/components-prod.xml
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiPluginThemeResource.java
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiSecurityEvents.java
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiUserPortraitResource.java
Log:
Optimized HTTP caching etc. for wiki production profile
Modified: branches/community/Seam_2_2/examples/wiki/build.xml
===================================================================
--- branches/community/Seam_2_2/examples/wiki/build.xml 2009-08-25 08:14:23 UTC (rev
11420)
+++ branches/community/Seam_2_2/examples/wiki/build.xml 2009-08-25 08:16:50 UTC (rev
11421)
@@ -165,7 +165,8 @@
destdir="${classes.dir}"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
- nowarn="${javac.nowarn}">
+ nowarn="${javac.nowarn}"
+ target="1.5">
<src path="${src.java.dir}"/>
<src path="${src.plugin.dir}"/>
</javac>
@@ -399,7 +400,8 @@
destdir="${testclasses.dir}"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
- nowarn="${javac.nowarn}">
+ nowarn="${javac.nowarn}"
+ target="1.5">
<classpath>
<path refid="test.classpath" />
<path refid="runtime.emma.path" />
Modified: branches/community/Seam_2_2/examples/wiki/src/etc/META-INF/components-prod.xml
===================================================================
---
branches/community/Seam_2_2/examples/wiki/src/etc/META-INF/components-prod.xml 2009-08-25
08:14:23 UTC (rev 11420)
+++
branches/community/Seam_2_2/examples/wiki/src/etc/META-INF/components-prod.xml 2009-08-25
08:16:50 UTC (rev 11421)
@@ -38,6 +38,15 @@
-->
<web:multipart-filter create-temp-files="true"
max-request-size="10000000" url-pattern="*.seam"/>
+ <web:cache-control-filter name="resourcesCacheControlFilter"
+
regex-url-pattern=".*(\.gif|\.png|\.jpg|\.jpeg|\.css|\.js)"
+ value="max-age=86400"/> <!-- 1 day -->
+
+ <web:cache-control-filter name="userPortraitCacheControlFilter"
+ url-pattern="/seam/resource/wikiUserPortrait/*"
+ value="max-age=432000"/> <!-- 5 days
-->
+
+
<!-- ############## END OF WIKI USER CONFIGURATION ############## -->
<!-- Running in regular JBoss AS, Seam starts the persistence unit -->
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiPluginThemeResource.java
===================================================================
---
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiPluginThemeResource.java 2009-08-25
08:14:23 UTC (rev 11420)
+++
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiPluginThemeResource.java 2009-08-25
08:16:50 UTC (rev 11421)
@@ -10,23 +10,22 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.core.Expressions;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
import org.jboss.seam.servlet.ContextualHttpServletRequest;
import org.jboss.seam.util.Resources;
-import org.jboss.seam.web.AbstractResource;
+import org.jboss.seam.web.ConditionalAbstractResource;
import org.jboss.seam.wiki.core.plugin.PluginRegistry;
import org.jboss.seam.wiki.core.plugin.metamodel.Plugin;
import org.jboss.seam.wiki.core.plugin.metamodel.PluginModule;
-import org.jboss.seam.core.Expressions;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.util.HashMap;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -49,7 +48,7 @@
@Scope(APPLICATION)
@Name("wikiPluginThemeResource")
@BypassInterceptors
-public class WikiPluginThemeResource extends AbstractResource {
+public class WikiPluginThemeResource extends ConditionalAbstractResource {
private Log log = Logging.getLog(WikiPluginThemeResource.class);
@@ -62,6 +61,18 @@
// Resources that are interpolated, i.e. which are text files that contain EL
expressions
private String[] interpolatedResourcesExtensions = new String[]{"css"};
+ private Map<String, String> mimeTypesExtensions = new HashMap() {{
+ put("css", "text/css");
+ put("txt", "text/plain");
+ put("js", "text/javascript");
+ put("png", "image/png");
+ put("jpg", "image/jpg");
+ put("jpeg", "image/jpeg");
+ put("gif", "image/gif");
+ put("swf", "application/x-shockwave-flash");
+ put("flv", "video/x-flv");
+ }};
+
@Override
public String getResourcePath() {
return Plugin.REGISTER_SEAM_RESOURCE_THEME;
@@ -146,24 +157,52 @@
boolean isInterpolated = false;
for (String interpolatedResourcesExtension : interpolatedResourcesExtensions)
{
- if (interpolatedResourcesExtension.equals(themeResourceExtension))
isInterpolated = true;
+ if (interpolatedResourcesExtension.equals(themeResourceExtension)) {
+ isInterpolated = true;
+ break;
+ }
}
+ String contentType = mimeTypesExtensions.get(themeResourceExtension);
+
if (isInterpolated) {
- log.debug("serving interpolated resource: " + resourcePath);
+
+ if (contentType == null) {
+ contentType = "text/plain";
+ }
+ response.setContentType(contentType);
+
CharSequence textFile = readFile(in);
textFile = parseEL(textFile);
- response.getWriter().write(textFile.toString());
- response.getWriter().flush();
+
+ String entityTag = createEntityTag(textFile.toString(), false);
+ Long lastModified = getLastModifiedTimestamp(resourcePath);
+
+ if (!sendConditional(request, response, entityTag, lastModified)) {
+ log.debug("serving interpolated resource: " +
resourcePath);
+ OutputStreamWriter outStream = new
OutputStreamWriter(selectOutputStream(request, response));
+ outStream.write(textFile.toString());
+ outStream.close();
+ }
} else {
log.debug("serving resource: " + resourcePath);
- byte[] buffer = new byte[1024];
- int read = in.read(buffer);
- while (read != -1) {
- response.getOutputStream().write(buffer, 0, read);
- read = in.read(buffer);
+
+ if (contentType == null) {
+ contentType = "application/octet-stream";
}
- response.getOutputStream().flush();
+ response.setContentType(contentType);
+
+ // We can't produce an entity tag because we stream the bytes through
(or not, through the gzip wrapper)
+ if (!sendConditional(request, response, null,
getLastModifiedTimestamp(resourcePath))) {
+ OutputStream outStream = selectOutputStream(request, response);
+ byte[] buffer = new byte[1024];
+ int read = in.read(buffer);
+ while (read != -1) {
+ outStream.write(buffer, 0, read);
+ read = in.read(buffer);
+ }
+ outStream.close();
+ }
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND, resourcePath);
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiSecurityEvents.java
===================================================================
---
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiSecurityEvents.java 2009-08-25
08:14:23 UTC (rev 11420)
+++
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiSecurityEvents.java 2009-08-25
08:16:50 UTC (rev 11421)
@@ -16,6 +16,8 @@
import org.jboss.seam.security.Identity;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.wiki.core.action.WikiRequestResolver;
+import org.jboss.seam.wiki.core.model.User;
+import org.jboss.seam.Component;
/**
* Overrides the "login failed" message and turns it into a WARN (we don't
want INFO here).
@@ -47,7 +49,7 @@
);
Contexts.getSessionContext().set(
- WikiRequestResolver.SESSION_MSG_DATA,
Identity.instance().getCredentials().getUsername()
+ WikiRequestResolver.SESSION_MSG_DATA,
((User)Component.getInstance("currentUser")).getFullname()
);
}
Modified:
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiUserPortraitResource.java
===================================================================
---
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiUserPortraitResource.java 2009-08-25
08:14:23 UTC (rev 11420)
+++
branches/community/Seam_2_2/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/WikiUserPortraitResource.java 2009-08-25
08:16:50 UTC (rev 11421)
@@ -90,8 +90,6 @@
return;
}
- response.addHeader("Cache-Control", "max-age=600"); // 10
minutes freshness in browser cache
-
byte[] image = imageSize.equals("l") ? user.getProfile().getImage() :
user.getProfile().getSmallImage();
response.setContentType(user.getProfile().getImageContentType());
response.setContentLength(image.length);