use of org.apache.wicket.request.IRequestCycle in project wicket by apache.
the class RequestCycleListenerTest method newRequestCycle.
private RequestCycle newRequestCycle(final RuntimeException exception) {
final Response originalResponse = newResponse();
Request request = new MockWebRequest(Url.parse("http://wicket.apache.org"));
handler = new IRequestHandler() {
@Override
public void respond(IRequestCycle requestCycle) {
if (exception != null) {
throw exception;
}
responses++;
}
@Override
public void detach(IRequestCycle requestCycle) {
detaches++;
}
};
IRequestMapper requestMapper = new IRequestMapper() {
@Override
public IRequestHandler mapRequest(Request request) {
return handler;
}
@Override
public Url mapHandler(IRequestHandler requestHandler) {
throw new UnsupportedOperationException();
}
@Override
public int getCompatibilityScore(Request request) {
throw new UnsupportedOperationException();
}
};
IExceptionMapper exceptionMapper = new IExceptionMapper() {
@Override
public IRequestHandler map(Exception e) {
exceptionsMapped++;
return null;
}
};
RequestCycleContext context = new RequestCycleContext(request, originalResponse, requestMapper, exceptionMapper);
RequestCycle cycle = new RequestCycle(context);
if (Application.exists()) {
cycle.getListeners().add(Application.get().getRequestCycleListeners());
}
return cycle;
}
use of org.apache.wicket.request.IRequestCycle in project midpoint by Evolveum.
the class AbstractAjaxDownloadBehavior method onRequest.
public void onRequest() {
IResourceStream resourceStream = getResourceStream();
if (resourceStream == null) {
// We hope the error was already processed and will be shown.
return;
}
ResourceStreamRequestHandler reqHandler = new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
super.respond(requestCycle);
}
}.setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ofSeconds(1));
if (StringUtils.isNotEmpty(getFileName())) {
reqHandler.setFileName(getFileName());
}
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(reqHandler);
}
use of org.apache.wicket.request.IRequestCycle in project midpoint by Evolveum.
the class AjaxDownloadBehaviorFromFile method onRequest.
public void onRequest() {
final File file = initFile();
IResourceStream resourceStream = new FileResourceStream(new File(file));
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
try {
super.respond(requestCycle);
} finally {
if (removeFile) {
LOGGER.debug("Removing file '{}'.", file.getAbsolutePath());
Files.remove(file);
}
}
}
}.setFileName(file.getName()).setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ofSeconds(1)));
}
Aggregations