use of org.apache.wicket.request.IRequestCycle in project midpoint by Evolveum.
the class AjaxDownloadBehaviorFromStream method onRequest.
public void onRequest() {
final InputStream byteStream = initStream();
if (byteStream == null) {
return;
}
IResourceStream resourceStream = new AbstractResourceStream() {
@Override
public String getContentType() {
return contentType;
}
@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
return byteStream;
}
@Override
public void close() throws IOException {
byteStream.close();
}
};
ResourceStreamRequestHandler reqHandler = new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
super.respond(requestCycle);
}
}.setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ONE_SECOND);
if (StringUtils.isNotEmpty(getFileName())) {
reqHandler.setFileName(getFileName());
}
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(reqHandler);
}
use of org.apache.wicket.request.IRequestCycle in project wicket by apache.
the class DownloadLink method onClick.
@Override
public void onClick() {
final File file = getModelObject();
if (file == null) {
throw new IllegalStateException(getClass().getName() + " failed to retrieve a File object from model");
}
String fileName = fileNameModel != null ? fileNameModel.getObject() : null;
if (Strings.isEmpty(fileName)) {
fileName = file.getName();
}
IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file));
getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
super.respond(requestCycle);
if (deleteAfter) {
Files.remove(file);
}
}
}.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(cacheDuration));
}
use of org.apache.wicket.request.IRequestCycle in project wicket by apache.
the class RequestSettingRequestHandler method respond.
@Override
public void respond(IRequestCycle requestCycle) {
RequestCycle cycle = (RequestCycle) requestCycle;
Request originalRequest = cycle.getRequest();
try {
cycle.setRequest(request);
delegate.respond(requestCycle);
} finally {
cycle.setRequest(originalRequest);
}
}
use of org.apache.wicket.request.IRequestCycle in project wicket by apache.
the class AjaxRequestHandler method respond.
/**
* @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
*/
@Override
public final void respond(final IRequestCycle requestCycle) {
final RequestCycle rc = (RequestCycle) requestCycle;
final WebResponse response = (WebResponse) requestCycle.getResponse();
if (shouldRedirectToPage(requestCycle)) {
// the page itself has been added to the request target, we simply issue a redirect
// back to the page
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
final String url = rc.urlFor(handler).toString();
response.sendRedirect(url);
return;
}
respondersFrozen = true;
for (ITargetRespondListener listener : respondListeners) {
listener.onTargetRespond(this);
}
final Application app = page.getApplication();
page.send(app, Broadcast.BREADTH, this);
// Determine encoding
final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();
// Set content type based on markup type for page
update.setContentType(response, encoding);
// Make sure it is not cached by a client
response.disableCaching();
final StringResponse bodyResponse = new StringResponse();
update.writeTo(bodyResponse, encoding);
CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
response.write(filteredResponse);
}
use of org.apache.wicket.request.IRequestCycle in project wicket by apache.
the class RedirectRequestHandlerTest method tempMovedShouldRedirect.
/**
* tempMovedShouldRedirect()
*/
@Test
public void tempMovedShouldRedirect() {
RedirectRequestHandler handler = new RedirectRequestHandler(REDIRECT_URL, HttpServletResponse.SC_MOVED_TEMPORARILY);
IRequestCycle requestCycle = Mockito.mock(IRequestCycle.class);
WebResponse webResponse = Mockito.mock(WebResponse.class);
Mockito.when(requestCycle.getResponse()).thenReturn(webResponse);
handler.respond(requestCycle);
Mockito.verify(webResponse).sendRedirect(REDIRECT_URL);
}
Aggregations