Search in sources :

Example 56 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class WebApplication method unmount.

/**
 * Unregisters all {@link IRequestMapper}s which would match on a this path.
 * <p>
 * Useful in OSGi environments where a bundle may want to update the mount point.
 * </p>
 *
 * @param path
 *            the path to unmount
 */
public void unmount(String path) {
    Args.notNull(path, "path");
    if (path.charAt(0) == '/') {
        path = path.substring(1);
    }
    IRequestMapper mapper = getRootRequestMapper();
    while (mapper instanceof IRequestMapperDelegate) {
        mapper = ((IRequestMapperDelegate) mapper).getDelegateMapper();
    }
    /*
		 * Only attempt to unmount if root request mapper is either a compound, or wraps a compound to avoid leaving the
		 * application with no mappers installed.
		 */
    if (mapper instanceof ICompoundRequestMapper) {
        final Url url = Url.parse(path);
        Request request = new Request() {

            @Override
            public Url getUrl() {
                return url;
            }

            @Override
            public Url getClientUrl() {
                return url;
            }

            @Override
            public Locale getLocale() {
                return null;
            }

            @Override
            public Charset getCharset() {
                return null;
            }

            @Override
            public Object getContainerRequest() {
                return null;
            }
        };
        unmountFromCompound((ICompoundRequestMapper) mapper, request);
    }
}
Also used : ICompoundRequestMapper(org.apache.wicket.request.mapper.ICompoundRequestMapper) IRequestMapperDelegate(org.apache.wicket.request.mapper.IRequestMapperDelegate) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) IRequestMapper(org.apache.wicket.request.IRequestMapper) Url(org.apache.wicket.request.Url)

Example 57 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class DefaultExceptionMapper method isProcessingAjaxRequest.

/**
 * @return true if current request is an AJAX request, false otherwise.
 */
protected boolean isProcessingAjaxRequest() {
    RequestCycle rc = RequestCycle.get();
    Request request = rc.getRequest();
    if (request instanceof WebRequest) {
        return ((WebRequest) request).isAjax();
    }
    return false;
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request)

Example 58 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class Session method internalDetach.

/**
 * NOT PART OF PUBLIC API, DO NOT CALL
 *
 * Detaches internal state of {@link Session}
 */
public void internalDetach() {
    if (dirty) {
        Request request = RequestCycle.get().getRequest();
        getSessionStore().flushSession(request, this);
    }
    dirty = false;
}
Also used : Request(org.apache.wicket.request.Request)

Example 59 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class Session method bind.

/**
 * Force binding this session to the application's {@link ISessionStore session store} if not
 * already done so.
 * <p>
 * A Wicket application can operate in a session-less mode as long as stateless pages are used.
 * Session objects will be then created for each request, but they will only live for that
 * request. You can recognize temporary sessions by calling {@link #isTemporary()} which
 * basically checks whether the session's id is null. Hence, temporary sessions have no session
 * id.
 * </p>
 * <p>
 * By calling this method, the session will be bound (made not-temporary) if it was not bound
 * yet. It is useful for cases where you want to be absolutely sure this session object will be
 * available in next requests. If the session was already bound (
 * {@link ISessionStore#lookup(Request) returns a session}), this call will be a noop.
 * </p>
 */
public final void bind() {
    // modified call.
    if (RequestCycle.get() == null) {
        return;
    }
    ISessionStore store = getSessionStore();
    Request request = RequestCycle.get().getRequest();
    if (store.lookup(request) == null) {
        // explicitly create a session
        id = store.getSessionId(request, true);
        // bind it
        store.bind(request, this);
        if (temporarySessionAttributes != null) {
            for (Map.Entry<String, Serializable> entry : temporarySessionAttributes.entrySet()) {
                store.setAttribute(request, entry.getKey(), entry.getValue());
            }
            temporarySessionAttributes = null;
        }
    }
}
Also used : Serializable(java.io.Serializable) ISessionStore(org.apache.wicket.session.ISessionStore) Request(org.apache.wicket.request.Request) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with Request

use of org.apache.wicket.request.Request 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)

Aggregations

Request (org.apache.wicket.request.Request)63 Test (org.junit.Test)28 IRequestHandler (org.apache.wicket.request.IRequestHandler)26 Url (org.apache.wicket.request.Url)23 WebRequest (org.apache.wicket.request.http.WebRequest)9 Response (org.apache.wicket.request.Response)8 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)5 MockApplication (org.apache.wicket.mock.MockApplication)4 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)4 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 Attributes (org.apache.wicket.request.resource.IResource.Attributes)3 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)3 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)3 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)3