Search in sources :

Example 6 with IRequestMapper

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

the class Application method getRootRequestMapperAsCompound.

/**
 * Converts the root mapper to a {@link ICompoundRequestMapper} if necessary and returns the
 * converted instance.
 *
 * @return compound instance of the root mapper
 */
public final ICompoundRequestMapper getRootRequestMapperAsCompound() {
    IRequestMapper root = getRootRequestMapper();
    if (!(root instanceof ICompoundRequestMapper)) {
        root = new SystemMapper(this).add(root);
        setRootRequestMapper(root);
    }
    return (ICompoundRequestMapper) root;
}
Also used : ICompoundRequestMapper(org.apache.wicket.request.mapper.ICompoundRequestMapper) IRequestMapper(org.apache.wicket.request.IRequestMapper)

Example 7 with IRequestMapper

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

the class RequestCycleUrlForTest method before.

@Before
public void before() {
    Request request = mock(Request.class);
    Url baseUrl = Url.parse("");
    when(request.getClientUrl()).thenReturn(baseUrl);
    Response response = new StringResponse() {

        @Override
        public String encodeURL(CharSequence url) {
            return url + JSESSIONID;
        }
    };
    IRequestMapper mapper = mock(IRequestMapper.class);
    Url bookmarkablePageUrl = Url.parse(BOOKMARKABLE_PAGE_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<BookmarkablePageRequestHandler>(BookmarkablePageRequestHandler.class)))).thenReturn(bookmarkablePageUrl);
    Url resourceUrl = Url.parse(RESOURCE_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceRequestHandler>(ResourceRequestHandler.class)))).thenReturn(resourceUrl);
    Url resourceReferenceUrl = Url.parse(RES_REF_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceReferenceRequestHandler>(ResourceReferenceRequestHandler.class)))).thenReturn(resourceReferenceUrl);
    IExceptionMapper exceptionMapper = mock(IExceptionMapper.class);
    RequestCycleContext context = new RequestCycleContext(request, response, mapper, exceptionMapper);
    requestCycle = new RequestCycle(context);
    requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) Request(org.apache.wicket.request.Request) StringResponse(org.apache.wicket.response.StringResponse) IExceptionMapper(org.apache.wicket.request.IExceptionMapper) IRequestMapper(org.apache.wicket.request.IRequestMapper) Url(org.apache.wicket.request.Url) Before(org.junit.Before)

Example 8 with IRequestMapper

use of org.apache.wicket.request.IRequestMapper in project webanno by webanno.

the class WicketApplicationBase method initDefaultPageMounts.

protected void initDefaultPageMounts() {
    mountPage("/login.html", getSignInPageClass());
    mountPage("/welcome.html", getHomePage());
    // Mount the other pages via @MountPath annotation on the page classes
    AnnotatedMountList mounts = new AnnotatedMountScanner().scanPackage("de.tudarmstadt.ukp");
    for (IRequestMapper mapper : mounts) {
        if (mapper instanceof HomePageMapper) {
            System.out.println(mapper);
        }
    }
    mounts.mount(this);
}
Also used : HomePageMapper(org.apache.wicket.core.request.mapper.HomePageMapper) AnnotatedMountScanner(org.wicketstuff.annotation.scan.AnnotatedMountScanner) AnnotatedMountList(org.wicketstuff.annotation.scan.AnnotatedMountList) IRequestMapper(org.apache.wicket.request.IRequestMapper)

Example 9 with IRequestMapper

use of org.apache.wicket.request.IRequestMapper 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 10 with IRequestMapper

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

the class CompoundRequestMapper method mapRequest.

/**
 * Searches the registered {@link IRequestMapper}s to find one that can map the {@link Request}.
 * Each registered {@link IRequestMapper} is asked to provide its compatibility score. Then the
 * mappers are asked to map the request in order depending on the provided compatibility
 * score.
 * <p>
 * The mapper with highest compatibility score which can map the request is returned.
 *
 * @param request
 * @return RequestHandler for the request or <code>null</code> if no mapper for the request is
 *         found.
 */
@Override
public IRequestHandler mapRequest(final Request request) {
    List<MapperWithScore> list = new ArrayList<>(mappers.size());
    for (IRequestMapper mapper : this) {
        int score = mapper.getCompatibilityScore(request);
        list.add(new MapperWithScore(mapper, score));
    }
    Collections.sort(list);
    if (LOG.isDebugEnabled()) {
        logMappers(list, request.getUrl().toString());
    }
    for (MapperWithScore mapperWithScore : list) {
        IRequestMapper mapper = mapperWithScore.getMapper();
        IRequestHandler handler = mapper.mapRequest(request);
        if (handler != null) {
            return handler;
        }
    }
    return null;
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IRequestMapper(org.apache.wicket.request.IRequestMapper)

Aggregations

IRequestMapper (org.apache.wicket.request.IRequestMapper)14 Test (org.junit.Test)8 IRequestHandler (org.apache.wicket.request.IRequestHandler)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)4 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)4 Request (org.apache.wicket.request.Request)3 Url (org.apache.wicket.request.Url)3 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)2 Response (org.apache.wicket.request.Response)2 ICompoundRequestMapper (org.apache.wicket.request.mapper.ICompoundRequestMapper)2 IRequestMapperDelegate (org.apache.wicket.request.mapper.IRequestMapperDelegate)2 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 HomePageMapper (org.apache.wicket.core.request.mapper.HomePageMapper)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1 ReplaceHandlerException (org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)1 WebRequest (org.apache.wicket.request.http.WebRequest)1