Search in sources :

Example 36 with Request

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

the class PackageMapper method parseRequest.

@Override
protected UrlInfo parseRequest(Request request) {
    Url url = request.getUrl();
    if (urlStartsWithMountedSegments(url)) {
        // try to extract page and component information from URL
        PageComponentInfo info = getPageComponentInfo(url);
        final List<String> segments = url.getSegments();
        if (segments.size() <= mountSegments.length) {
            return null;
        }
        // load the page class
        String name = segments.get(mountSegments.length);
        if (Strings.isEmpty(name)) {
            return null;
        }
        String className = cleanClassName(name);
        if (isValidClassName(className) == false) {
            return null;
        }
        className = transformFromUrl(className);
        String fullyQualifiedClassName = packageName.getName() + '.' + className;
        Class<? extends IRequestablePage> pageClass = getPageClass(fullyQualifiedClassName);
        if (pageClass != null && Modifier.isAbstract(pageClass.getModifiers()) == false && IRequestablePage.class.isAssignableFrom(pageClass)) {
            // extract the PageParameters from URL if there are any
            Url urlWithoutPageSegment = new Url(url);
            urlWithoutPageSegment.getSegments().remove(mountSegments.length);
            Request requestWithoutPageSegment = request.cloneWithUrl(urlWithoutPageSegment);
            PageParameters pageParameters = extractPageParameters(requestWithoutPageSegment, urlWithoutPageSegment);
            return new UrlInfo(info, pageClass, pageParameters);
        }
    }
    return null;
}
Also used : IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 37 with Request

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

the class WebPage method dirty.

/**
 * Prevents page from get dirty inside an AJAX request.
 */
@Override
public final void dirty(boolean isInitialization) {
    Request request = getRequest();
    if (isInitialization == false && request instanceof WebRequest && ((WebRequest) request).isAjax()) {
        return;
    }
    super.dirty(isInitialization);
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request)

Example 38 with Request

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

the class BaseWicketTester method applyRequest.

/**
 * Rebuilds {@link ServletWebRequest} used by wicket from the mock request used to build
 * requests. Sometimes this method is useful when changes need to be checked without processing
 * a request.
 */
public void applyRequest() {
    Request req = newServletWebRequest();
    requestCycle.setRequest(req);
    if (useRequestUrlAsBase) {
        requestCycle.getUrlRenderer().setBaseUrl(req.getUrl());
    }
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest)

Example 39 with Request

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

the class BookmarkableMapperTest method decode12.

/**
 * WICKET-5071
 *
 * Decodes a request to
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()}
 * /com.example.MyPage when the current base url is
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()} /
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
 */
@Test
public void decode12() {
    final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME);
    Request request = new Request() {

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

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

        @Override
        public Charset getCharset() {
            return Charset.forName("UTF-8");
        }

        @Override
        public Url getClientUrl() {
            StringBuilder url = new StringBuilder();
            url.append(context.getNamespace()).append('/').append(context.getPageIdentifier()).append("?3");
            return Url.parse(url.toString());
        }

        @Override
        public Object getContainerRequest() {
            return null;
        }
    };
    IRequestHandler handler = encoder.mapRequest(request);
    assertNotNull("A handler should be resolved for relative url to a page instance url!", handler);
    IRequestablePage page = ((IPageRequestHandler) handler).getPage();
    assertEquals(page.getClass().getName(), PAGE_CLASS_NAME);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 40 with Request

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

the class BookmarkableMapperTest method decode11.

/**
 * WICKET-5071
 *
 * Decodes a request to
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()}
 * /com.example.MyPage when the current base url is
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()} /
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()}
 */
@Test
public void decode11() {
    final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME);
    Request request = new Request() {

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

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

        @Override
        public Charset getCharset() {
            return Charset.forName("UTF-8");
        }

        @Override
        public Url getClientUrl() {
            StringBuilder url = new StringBuilder();
            url.append(context.getNamespace()).append('/').append(context.getBookmarkableIdentifier()).append('/').append("com.example.MyPage");
            return Url.parse(url.toString());
        }

        @Override
        public Object getContainerRequest() {
            return null;
        }
    };
    IRequestHandler handler = encoder.mapRequest(request);
    assertNotNull("A handler should be resolved for relative url to a bookmarkable page!", handler);
    IRequestablePage page = ((IPageRequestHandler) handler).getPage();
    assertEquals(page.getClass().getName(), PAGE_CLASS_NAME);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

Request (org.apache.wicket.request.Request)61 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 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)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 Session (org.apache.wicket.Session)3 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