Skip to content

Commit

Permalink
SAK-29504 less aggressively cache the profile image and add message a…
Browse files Browse the repository at this point in the history
…bout refreshing browser
  • Loading branch information
steveswinsburg committed Jun 10, 2015
1 parent ae2927d commit 3912474
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ text.gallery.feed.num.none = 0 pictures
text.gallery.pictures.num.none = Your gallery doesn't contain any pictures yet.
text.gallery.upload.tooltip = Upload gallery images from your computer. The combined size of the images to upload should not exceed {0}MB.
text.image.url = Enter the URL of an image to use as your profile picture
text.image.refresh = Note: If the new image doesn't appear immediately, try refreshing your browser.
text.messages.none = No messages
text.no.fields = You haven't filled out any information yet
text.no.status = Say something
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ text.gallery.feed.num.none = 0 pictures
text.gallery.pictures.num.none = Your gallery doesn't contain any pictures yet.
text.gallery.upload.tooltip = Upload gallery images from your computer. The combined size of the images to upload should not exceed {0}MB.
text.image.url = Enter the URL of an image to use as your profile picture
text.image.refresh = Note: If the new image doesn't appear immediately, try refreshing your browser.
text.messages.none = No messages
text.no.fields = You haven't filled out any information yet
text.no.status = Say something
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ text.gallery.feed.num.none = 0 pictures
text.gallery.pictures.num.none = Your gallery doesn't contain any pictures yet.
text.gallery.upload.tooltip = Upload gallery images from your computer. The combined size of the images to upload should not exceed {0}MB.
text.image.url = Enter the URL of an image to use as your profile picture
text.image.refresh = Note: If the new image doesn't appear immediately, try refreshing your browser.
text.messages.none = No messages
text.no.fields = You haven't filled out any information yet
text.no.status = Say something
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ text.gallery.feed.num.none = ** text.gallery.feed.num.none**
text.gallery.pictures.num.none = ** text.gallery.pictures.num.none**
text.gallery.upload.tooltip = ** text.gallery.upload.tooltip**
text.image.url = ** text.image.url**
text.image.refresh = ** text.image.refresh**
text.messages.none = ** text.messages.none**
text.no.fields = ** text.no.fields**
text.no.status = ** text.no.status**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import lombok.Setter;
import lombok.extern.apachecommons.CommonsLog;

Expand All @@ -32,15 +35,12 @@
import org.sakaiproject.entitybroker.entityprovider.annotations.EntityURLRedirect;
import org.sakaiproject.entitybroker.entityprovider.capabilities.ActionsExecutable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.AutoRegisterEntityProvider;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Createable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Describeable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Inputable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Outputable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Redirectable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.RequestAware;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Resolvable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Sampleable;
import org.sakaiproject.entitybroker.entityprovider.capabilities.Updateable;
import org.sakaiproject.entitybroker.entityprovider.extension.ActionReturn;
import org.sakaiproject.entitybroker.entityprovider.extension.Formats;
import org.sakaiproject.entitybroker.entityprovider.extension.RequestGetter;
Expand Down Expand Up @@ -177,6 +177,14 @@ public Object getProfileImage(OutputStream out, EntityView view, Map<String,Obje
try {
out.write(bytes);
ActionReturn actionReturn = new ActionReturn("BASE64", image.getMimeType(), out);

Map<String,String> headers = new HashMap<>();
headers.put("Expires", "Mon, 01 Jan 2001 00:00:00 GMT");
headers.put("Cache-Control","no-cache, must-revalidate, max-age=0");
headers.put("Pragma", "no-cache");

actionReturn.setHeaders(headers);

return actionReturn;
} catch (IOException e) {
throw new EntityException("Error retrieving profile image for " + id + " : " + e.getMessage(), ref.getReference());
Expand All @@ -186,7 +194,11 @@ public Object getProfileImage(OutputStream out, EntityView view, Map<String,Obje
final String url = image.getUrl();
if(StringUtils.isNotBlank(url)) {
try {
requestGetter.getResponse().sendRedirect(url);
HttpServletResponse res = requestGetter.getResponse();
res.addHeader("Expires", "Mon, 01 Jan 2001 00:00:00 GMT");
res.addHeader("Cache-Control","no-cache, must-revalidate, max-age=0");
res.addHeader("Pragma", "no-cache");
res.sendRedirect(url);
} catch (IOException e) {
throw new EntityException("Error redirecting to external image for " + id + " : " + e.getMessage(), ref.getReference());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<p><input type="file" wicket:id="picture" size="15"/></p>

<div wicket:id="editWarning" class="edit-other-warning">[You are editing {other person}'s image]</div>


<p class="instruction"><wicket:message key="text.image.refresh">Note: If the new image doesn't appear immediately, try refreshing your browser.</wicket:message></p>

<p>
<input type="submit" wicket:id="submit" value="Upload" />

Expand Down

0 comments on commit 3912474

Please sign in to comment.