Search in sources :

Example 11 with IRequestCycle

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;
}
Also used : Response(org.apache.wicket.request.Response) IRequestHandler(org.apache.wicket.request.IRequestHandler) IRequestCycle(org.apache.wicket.request.IRequestCycle) MockWebRequest(org.apache.wicket.mock.MockWebRequest) Request(org.apache.wicket.request.Request) MockWebRequest(org.apache.wicket.mock.MockWebRequest) IExceptionMapper(org.apache.wicket.request.IExceptionMapper) IRequestMapper(org.apache.wicket.request.IRequestMapper) IRequestCycle(org.apache.wicket.request.IRequestCycle) ReplaceHandlerException(org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)

Example 12 with IRequestCycle

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);
}
Also used : IResourceStream(org.apache.wicket.util.resource.IResourceStream) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) IRequestCycle(org.apache.wicket.request.IRequestCycle)

Example 13 with IRequestCycle

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)));
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) IResourceStream(org.apache.wicket.util.resource.IResourceStream) File(org.apache.wicket.util.file.File) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) IRequestCycle(org.apache.wicket.request.IRequestCycle)

Aggregations

IRequestCycle (org.apache.wicket.request.IRequestCycle)13 WebResponse (org.apache.wicket.request.http.WebResponse)5 IRequestHandler (org.apache.wicket.request.IRequestHandler)4 ResourceStreamRequestHandler (org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler)4 IResourceStream (org.apache.wicket.util.resource.IResourceStream)4 Test (org.junit.Test)4 Request (org.apache.wicket.request.Request)2 ReplaceHandlerException (org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)2 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)2 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Application (org.apache.wicket.Application)1 Session (org.apache.wicket.Session)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)1 IRequestMapper (org.apache.wicket.request.IRequestMapper)1 Response (org.apache.wicket.request.Response)1