I just started working with Wicket on my own, but I just mounted the resource as a shared resource with my own URL. You simply override init() in your Application and register the resource with
getSharedResources().add(resourceKey, dynamicImageResource);
Then you mount it as a share using
mountSharedResource(path, resourceKey);
For some reason that I still don't fully understand, you have to add the name of the application class to the resource key that you pass to mountSharedResource() .
Add a fully working example for some bonus voices! First create an empty Wicket template with
mvn archetype:create -DarchetypeGroupId=org.apache.wicket \ -DarchetypeArtifactId=wicket-archetype-quickstart \ -DarchetypeVersion=1.4.0 -DgroupId=com.mycompany \ -DartifactId=myproject
Then override the init() method in WicketApplication by adding:
@Override protected void init() { final String resourceKey = "DYN_IMG_KEY"; final String queryParm = "id"; getSharedResources().add(resourceKey, new Resource() { @Override public IResourceStream getResourceStream() { final String query = getParameters().getString(queryParm);
The small dynamic PNG resource simply records the query parameter on a black background. Of course, you can access your database or do whatever you want to get image data.
Finally, run mvn jetty:run , and you can access the resource in this URL .
janko
source share