Search in sources :

Example 21 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class WebSocketTesterRequestCycleListenerTest method before.

@Before
public void before() {
    tester = new WicketTester();
    tester.getApplication().getRequestCycleListeners().add(new IRequestCycleListener() {

        @Override
        public void onBeginRequest(RequestCycle cycle) {
            beginRequestCalled.set(true);
        }

        @Override
        public void onEndRequest(RequestCycle cycle) {
            endRequestCalled.set(true);
        }

        @Override
        public void onDetach(RequestCycle cycle) {
            detachCalled.set(true);
        }
    });
}
Also used : IRequestCycleListener(org.apache.wicket.request.cycle.IRequestCycleListener) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WicketTester(org.apache.wicket.util.tester.WicketTester) Before(org.junit.Before)

Example 22 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class ComponentEventSender method bubble.

/**
 * Bubbles the event
 *
 * @param event
 *            event
 */
private void bubble(ComponentEvent<?> event) {
    IEventSink sink = event.getSink();
    boolean targetsComponent = sink instanceof Component;
    boolean targetsCycle = targetsComponent || sink instanceof RequestCycle;
    boolean targetsSession = targetsCycle || sink instanceof Session;
    boolean targetsApplication = targetsSession || sink instanceof Application;
    if (!targetsApplication && !targetsComponent) {
        dispatcher.dispatchEvent(sink, event, null);
        return;
    }
    if (targetsComponent) {
        Component cursor = (Component) sink;
        dispatchToComponent(dispatcher, cursor, event);
        if (event.isStop()) {
            return;
        }
        cursor.visitParents(MarkupContainer.class, new ComponentEventVisitor(event, dispatcher));
    }
    if (event.isStop()) {
        return;
    }
    if (targetsCycle) {
        dispatcher.dispatchEvent(source.getRequestCycle(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsSession) {
        dispatcher.dispatchEvent(source.getSession(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsApplication) {
        dispatcher.dispatchEvent(source.getApplication(), event, null);
    }
}
Also used : IEventSink(org.apache.wicket.event.IEventSink) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 23 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class ComponentEventSender method depth.

/**
 * Depth broadcast
 *
 * @param event
 *            event
 */
private void depth(final ComponentEvent<?> event) {
    IEventSink sink = event.getSink();
    boolean targetsApplication = sink instanceof Application;
    boolean targetsSession = targetsApplication || sink instanceof Session;
    boolean targetsCycle = targetsSession || sink instanceof RequestCycle;
    boolean targetsComponent = sink instanceof Component;
    if (!targetsComponent && !targetsCycle) {
        dispatcher.dispatchEvent(sink, event, null);
        return;
    }
    Component cursor = (targetsCycle) ? source.getPage() : (Component) sink;
    if (cursor instanceof MarkupContainer) {
        Visits.visitPostOrder(cursor, new ComponentEventVisitor(event, dispatcher));
    } else {
        dispatchToComponent(dispatcher, cursor, event);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsCycle) {
        dispatcher.dispatchEvent(source.getRequestCycle(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsSession) {
        dispatcher.dispatchEvent(source.getSession(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsApplication) {
        dispatcher.dispatchEvent(source.getApplication(), event, null);
    }
}
Also used : IEventSink(org.apache.wicket.event.IEventSink) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 24 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class NonResettingRestartException method transferResponseMetaData.

private void transferResponseMetaData() {
    RequestCycle cycle = RequestCycle.get();
    Response response = cycle.getResponse();
    if (response instanceof IMetaDataBufferingWebResponse) {
        WebResponse originalResponse = (WebResponse) cycle.getOriginalResponse();
        if (originalResponse != response) {
            IMetaDataBufferingWebResponse bufferingWebResponse = (IMetaDataBufferingWebResponse) response;
            bufferingWebResponse.writeMetaData(originalResponse);
        }
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) WebResponse(org.apache.wicket.request.http.WebResponse) IMetaDataBufferingWebResponse(org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse) Response(org.apache.wicket.request.Response) IMetaDataBufferingWebResponse(org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse) WebResponse(org.apache.wicket.request.http.WebResponse) IMetaDataBufferingWebResponse(org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 25 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class Session method setAttribute.

/**
 * Adds or replaces the attribute with the given name and value.
 *
 * @param name
 *            The name of the attribute
 * @param value
 *            The value of the attribute
 */
public final Session setAttribute(String name, Serializable value) {
    if (!isTemporary()) {
        RequestCycle cycle = RequestCycle.get();
        if (cycle == null) {
            throw new IllegalStateException("Cannot set the attribute: no RequestCycle available.  If you get this error when using WicketTester.startPage(Page), make sure to call WicketTester.createRequestCycle() beforehand.");
        }
        ISessionStore store = getSessionStore();
        Request request = cycle.getRequest();
        // extra check on session binding event
        if (value == this) {
            Object current = store.getAttribute(request, name);
            if (current == null) {
                String id = store.getSessionId(request, false);
                if (id != null) {
                    // this is a new instance. wherever it came from, bind
                    // the session now
                    store.bind(request, (Session) value);
                }
            }
        }
        // Set the actual attribute
        store.setAttribute(request, name, value);
    } else {
        // session instance gets shared across threads
        if (temporarySessionAttributes == null) {
            temporarySessionAttributes = new HashMap<>(3);
        }
        temporarySessionAttributes.put(name, value);
    }
    return this;
}
Also used : ISessionStore(org.apache.wicket.session.ISessionStore) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Request(org.apache.wicket.request.Request)

Aggregations

RequestCycle (org.apache.wicket.request.cycle.RequestCycle)69 WebResponse (org.apache.wicket.request.http.WebResponse)14 IRequestHandler (org.apache.wicket.request.IRequestHandler)9 Url (org.apache.wicket.request.Url)9 Response (org.apache.wicket.request.Response)8 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)7 BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)7 Page (org.apache.wicket.Page)6 Request (org.apache.wicket.request.Request)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)5 IRequestCycle (org.apache.wicket.request.IRequestCycle)5 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)5 Test (org.junit.Test)5 Application (org.apache.wicket.Application)4 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)4 WebClientInfo (org.apache.wicket.protocol.http.request.WebClientInfo)4 WebRequest (org.apache.wicket.request.http.WebRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 WebApplication (org.apache.wicket.protocol.http.WebApplication)3 UrlRenderer (org.apache.wicket.request.UrlRenderer)3