Search in sources :

Example 1 with ResourceRequestHandler

use of org.apache.wicket.request.handler.resource.ResourceRequestHandler in project wicket by apache.

the class RequestCycleUrlForTest method urlForStaticResource.

/**
 * IStaticCacheableResource should not have the jsessionid encoded in the url
 *
 * @throws Exception
 */
@Test
public void urlForStaticResource() throws Exception {
    IStaticCacheableResource resource = mock(IStaticCacheableResource.class);
    ResourceRequestHandler handler = new ResourceRequestHandler(resource, new PageParameters());
    CharSequence url = requestCycle.urlFor(handler);
    assertEquals("./" + RESOURCE_URL, url);
}
Also used : IStaticCacheableResource(org.apache.wicket.request.resource.caching.IStaticCacheableResource) ResourceRequestHandler(org.apache.wicket.request.handler.resource.ResourceRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.Test)

Example 2 with ResourceRequestHandler

use of org.apache.wicket.request.handler.resource.ResourceRequestHandler in project wicket by apache.

the class RequestCycle method renderUrl.

private String renderUrl(Url url, IRequestHandler handler) {
    if (url != null) {
        boolean shouldEncodeStaticResource = Application.exists() && Application.get().getResourceSettings().isEncodeJSessionId();
        String renderedUrl = getUrlRenderer().renderUrl(url);
        if (handler instanceof ResourceReferenceRequestHandler) {
            ResourceReferenceRequestHandler rrrh = (ResourceReferenceRequestHandler) handler;
            IResource resource = rrrh.getResource();
            if (resource != null && !(resource instanceof IStaticCacheableResource) || shouldEncodeStaticResource) {
                renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
            }
        } else if (handler instanceof ResourceRequestHandler) {
            ResourceRequestHandler rrh = (ResourceRequestHandler) handler;
            IResource resource = rrh.getResource();
            if (resource != null && !(resource instanceof IStaticCacheableResource) || shouldEncodeStaticResource) {
                renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
            }
        } else {
            renderedUrl = getOriginalResponse().encodeURL(renderedUrl);
        }
        return renderedUrl;
    } else {
        return null;
    }
}
Also used : IStaticCacheableResource(org.apache.wicket.request.resource.caching.IStaticCacheableResource) ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) ResourceRequestHandler(org.apache.wicket.request.handler.resource.ResourceRequestHandler) IResource(org.apache.wicket.request.resource.IResource)

Example 3 with ResourceRequestHandler

use of org.apache.wicket.request.handler.resource.ResourceRequestHandler in project wicket by apache.

the class RequestCycleUrlForTest method urlForDynamicResource.

/**
 * Non-IStaticCacheableResource should have the jsessionid encoded in the url
 *
 * @throws Exception
 */
@Test
public void urlForDynamicResource() throws Exception {
    ByteArrayResource resource = new ByteArrayResource(null, new byte[] { 1, 2 }, "test.bin");
    ResourceRequestHandler handler = new ResourceRequestHandler(resource, new PageParameters());
    CharSequence url = requestCycle.urlFor(handler);
    assertEquals("./" + RESOURCE_URL + JSESSIONID, url);
}
Also used : ResourceRequestHandler(org.apache.wicket.request.handler.resource.ResourceRequestHandler) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.Test)

Aggregations

ResourceRequestHandler (org.apache.wicket.request.handler.resource.ResourceRequestHandler)3 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)2 IStaticCacheableResource (org.apache.wicket.request.resource.caching.IStaticCacheableResource)2 Test (org.junit.Test)2 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)1 ByteArrayResource (org.apache.wicket.request.resource.ByteArrayResource)1 IResource (org.apache.wicket.request.resource.IResource)1