List of usage examples for org.apache.wicket.request IRequestCycle setResponse
Response setResponse(Response response);
From source file:fiftyfive.wicket.resource.MergedResourceRequestHandler.java
License:Apache License
public void respond(IRequestCycle requestCycle) { WebRequest origRequest = (WebRequest) requestCycle.getRequest(); // Explicitly set the last modified header of the response based on the last modified // time of the aggregate. Do this on the original response because our wrapped response // ignores the last modified headers contributed by each individual resource. WebResponse origResponse = (WebResponse) requestCycle.getResponse(); if (this.lastModified != null) { origResponse.setLastModifiedTime(this.lastModified); }//from w ww. j a v a2 s . c om try { // Make a special response object that merges the contributions of each resource, // but maintains a single set of headers. MergedResponse merged = new MergedResponse(origResponse); requestCycle.setResponse(merged); // Make a special request object that tweaks the If-Modified-Since header to ensure // we don't end up in a situation where some resources respond 200 and others 304. // Yes, calling RequestCycle#setRequest() is frowned upon so this is a bit of a hack. ((RequestCycle) requestCycle).setRequest(new MergedRequest(origRequest)); for (ResourceReference ref : this.resources) { ResourceRequestHandler handler = new ResourceRequestHandler(ref.getResource(), this.pageParameters); handler.respond(requestCycle); // If first resource sent 304 Not Modified that means all will. // We can therefore skip the rest. if (304 == merged.status) { break; } } } finally { // Restore the original request once we're done. We don't need to restore the // original response because Wicket takes care of that automatically. ((RequestCycle) requestCycle).setRequest(origRequest); } }