|
Page Created :
WICKET :
Showing a remote image on Wicket site
Showing a remote image on Wicket site has been created by Martin Makundi (May 18, 2009). Content:If you integrate with, e.g., Google Charts, you will need to fetch the remote image in the background while using HTTPS. Because Google does not support HTTPS and you do not want that annoygin pop-up saying "Unsecure content". So you fetch the image on the background: public class RemoteImage extends Image { /** */ final IModel<String> urlModel; /** * @param id * @param urlModel */ public RemoteImage(String id, IModel<String> urlModel) { super(id); this.urlModel = urlModel; } /** * @see org.apache.wicket.markup.html.image.Image#getImageResource() */ @Override protected Resource getImageResource() { return new DynamicImageResource() { @Override protected byte[] getImageData() { try { URL url = "" class="code-keyword">new URL(urlModel.getObject()); HttpURLConnection uc = (HttpURLConnection) url.openConnection(); try { final int size = uc.getContentLength(); int filled = 0; byte[] imageData = new byte[size]; do { byte[] tmpData = new byte[size-filled]; int read = uc.getInputStream().read(tmpData); System.arraycopy(tmpData, 0, imageData, filled, read); filled += read; } while (filled < size); return imageData; } finally { uc.getInputStream().close(); uc.disconnect(); } } catch (IOException e) { Utils.errorLog(RemoteImage.class, "Failed to load remote image", e); } return new byte[] {}; } @Override protected void setHeaders(WebResponse response) { response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); } }; } } |
Powered by
Atlassian Confluence
(Version: 2.2.9 Build:#527 Sep 07, 2006)
-
Bug/feature request
Unsubscribe or edit your notifications preferences
Unsubscribe or edit your notifications preferences
