Search in sources :

Example 41 with Url

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

the class BookmarkableMapper method parseRequest.

@Override
protected UrlInfo parseRequest(Request request) {
    if (Application.exists()) {
        if (Application.get().getSecuritySettings().getEnforceMounts()) {
            return null;
        }
    }
    if (matches(request)) {
        Url url = request.getUrl();
        // try to extract page and component information from URL
        PageComponentInfo info = getPageComponentInfo(url);
        List<String> segments = url.getSegments();
        // load the page class
        String className;
        if (segments.size() >= 3) {
            className = segments.get(2);
        } else {
            className = segments.get(1);
        }
        if (Strings.isEmpty(className)) {
            return null;
        }
        Class<? extends IRequestablePage> pageClass = getPageClass(className);
        if (pageClass != null && IRequestablePage.class.isAssignableFrom(pageClass)) {
            // extract the PageParameters from URL if there are any
            PageParameters pageParameters = extractPageParameters(request, 3, pageParametersEncoder);
            if (pageParameters != null) {
                pageParameters.setLocale(resolveLocale());
            }
            return new UrlInfo(info, pageClass, pageParameters);
        }
    }
    return null;
}
Also used : IRequestablePage(org.apache.wicket.request.component.IRequestablePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 42 with Url

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

the class BasicResourceReferenceMapper method getCompatibilityScore.

@Override
public int getCompatibilityScore(Request request) {
    Url url = request.getUrl();
    int score = -1;
    if (canBeHandled(url)) {
        score = 1;
    }
    return score;
}
Also used : ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl) Url(org.apache.wicket.request.Url)

Example 43 with Url

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

the class BasicResourceReferenceMapper method mapRequest.

@Override
public IRequestHandler mapRequest(Request request) {
    Url url = request.getUrl();
    if (canBeHandled(url)) {
        final int segmentsSize = url.getSegments().size();
        // extract the PageParameters from URL if there are any
        PageParameters pageParameters = extractPageParameters(request, segmentsSize, pageParametersEncoder);
        if (pageParameters != null) {
            pageParameters.setLocale(resolveLocale());
        }
        String className = url.getSegments().get(2);
        StringBuilder name = new StringBuilder(segmentsSize * 2);
        for (int i = 3; i < segmentsSize; ++i) {
            String segment = url.getSegments().get(i);
            // ignore invalid segments
            if (segment.indexOf('/') > -1) {
                return null;
            }
            // remove caching information
            if (i + 1 == segmentsSize && Strings.isEmpty(segment) == false) {
                // The filename + parameters eventually contain caching
                // related information which needs to be removed
                ResourceUrl resourceUrl = new ResourceUrl(segment, pageParameters);
                getCachingStrategy().undecorateUrl(resourceUrl);
                segment = resourceUrl.getFileName();
                Checks.notEmpty(segment, "Caching strategy returned empty name for '%s'", resourceUrl);
            }
            if (name.length() > 0) {
                name.append('/');
            }
            name.append(segment);
        }
        ResourceReference.UrlAttributes attributes = ResourceUtil.decodeResourceReferenceAttributes(url);
        Class<?> scope = resolveClass(className);
        if (scope != null && scope.getPackage() != null) {
            ResourceReference res = getContext().getResourceReferenceRegistry().getResourceReference(scope, name.toString(), attributes.getLocale(), attributes.getStyle(), attributes.getVariation(), true, true);
            if (res != null) {
                return new ResourceReferenceRequestHandler(res, pageParameters);
            }
        }
    }
    return null;
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) MetaInfStaticResourceReference(org.apache.wicket.request.resource.MetaInfStaticResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl) Url(org.apache.wicket.request.Url) ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl)

Example 44 with Url

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

the class CryptoMapper method decryptUrl.

/**
 * Decrypts a {@link Url}. This method should return {@code null} if the URL is not decryptable, or if the
 * URL should have been encrypted but was not. Returning {@code null} results in a 404 error.
 *
 * @param request
 *		The {@link Request}.
 * @param encryptedUrl
 *		The encrypted {@link Url}.
 *
 * @return Returns a decrypted {@link Url}.
 */
protected Url decryptUrl(final Request request, final Url encryptedUrl) {
    Url url = decryptEntireUrl(request, encryptedUrl);
    if (url == null) {
        if (encryptedUrl.getSegments().size() > 0 && encryptedUrl.getSegments().get(0).equals(getContext().getNamespace())) {
            /*
				 * This URL should have been encrypted, but was not. We should refuse to handle this, except when
				 * there is more than one CryptoMapper installed, and the request was decrypted by some other
				 * CryptoMapper.
				 */
            if (request.getOriginalUrl().getSegments().size() > 0 && request.getOriginalUrl().getSegments().get(0).equals(getContext().getNamespace())) {
                return null;
            } else {
                return encryptedUrl;
            }
        }
    }
    if (url == null) {
        url = decryptRequestListenerParameter(request, encryptedUrl);
    }
    log.debug("Url '{}' has been decrypted to '{}'", encryptedUrl, url);
    return url;
}
Also used : Url(org.apache.wicket.request.Url)

Example 45 with Url

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

the class CryptoMapper method mapRequest.

@Override
public IRequestHandler mapRequest(final Request request) {
    Url url = decryptUrl(request, request.getUrl());
    if (url == null) {
        return null;
    }
    Request decryptedRequest = request.cloneWithUrl(url);
    IRequestHandler handler = wrappedMapper.mapRequest(decryptedRequest);
    if (handler != null) {
        handler = new RequestSettingRequestHandler(decryptedRequest, handler);
    }
    return handler;
}
Also used : RequestSettingRequestHandler(org.apache.wicket.core.request.handler.RequestSettingRequestHandler) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url)

Aggregations

Url (org.apache.wicket.request.Url)361 Test (org.junit.jupiter.api.Test)220 IRequestHandler (org.apache.wicket.request.IRequestHandler)145 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)58 MockWebRequest (org.apache.wicket.mock.MockWebRequest)57 UrlRenderer (org.apache.wicket.request.UrlRenderer)57 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)51 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)50 Test (org.junit.Test)46 PageProvider (org.apache.wicket.core.request.handler.PageProvider)40 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)35 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)34 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)33 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)27 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)26 Request (org.apache.wicket.request.Request)25 MockPage (org.apache.wicket.MockPage)22 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)18 BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)16 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)15