Search in sources :

Example 1 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class ImageButton method onComponentTag.

/**
 * Processes the component tag.
 *
 * @param tag
 *            Tag to modify
 * @see org.apache.wicket.Component#onComponentTag(ComponentTag)
 */
@Override
protected final void onComponentTag(final ComponentTag tag) {
    checkComponentTag(tag, "input");
    checkComponentTagAttribute(tag, "type", "image");
    final IResource resource = getImageResource();
    if (resource != null) {
        localizedImageResource.setResource(resource);
    }
    final ResourceReference resourceReference = getImageResourceReference();
    if (resourceReference != null) {
        localizedImageResource.setResourceReference(resourceReference);
    }
    localizedImageResource.setSrcAttribute(tag);
    super.onComponentTag(tag);
}
Also used : ResourceReference(org.apache.wicket.request.resource.ResourceReference) IResource(org.apache.wicket.request.resource.IResource)

Example 2 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class ResourceTest method bindToApplicationAsResourceAndRequestIt.

private void bindToApplicationAsResourceAndRequestIt(IResourceStream iResourceStream) {
    IResource resource = new ResourceStreamResource(iResourceStream);
    tester.getApplication().getSharedResources().add("resource", resource);
    tester.getRequest().setUrl(tester.getRequestCycle().mapUrlFor(tester.getApplication().getSharedResources().get(Application.class, "resource", null, null, null, true), null));
    tester.processRequest();
}
Also used : ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) IResource(org.apache.wicket.request.resource.IResource)

Example 3 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class WicketFilterTest method options.

@Test
public void options() throws IOException, ServletException, ParseException {
    try {
        application = new MockApplication();
        WicketFilter filter = new WicketFilter();
        filter.init(new FilterTestingConfig());
        ThreadContext.setApplication(application);
        final String failure = "Should never get here when an OPTIONS request is issued";
        IResource resource = new AbstractResource() {

            @Override
            protected ResourceResponse newResourceResponse(Attributes attributes) {
                fail(failure);
                return null;
            }
        };
        application.getSharedResources().add("foo.txt", resource);
        // check OPTIONS request is processed correctly
        MockHttpServletRequest request = new MockHttpServletRequest(application, null, null);
        request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.txt");
        // test that we do not care about case
        request.setMethod("OPtioNS");
        MockHttpServletResponse response = new MockHttpServletResponse(request);
        filter.doFilter(request, response, new FilterChain() {

            @Override
            public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
            }
        });
        assertEquals(HttpServletResponse.SC_OK, response.getStatus());
        assertEquals("0", response.getHeader("Content-Length"));
        assertFalse(Strings.isEmpty(response.getHeader("Allow")));
        assertTrue(response.getHeader("Allow").toUpperCase().contains("GET"));
        assertTrue(response.getHeader("Allow").toUpperCase().contains("POST"));
        // try with a GET request to make sure we fail correctly
        request = new MockHttpServletRequest(application, null, null);
        request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.txt");
        response = new MockHttpServletResponse(request);
        try {
            filter.doFilter(request, response, new FilterChain() {

                @Override
                public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
                }
            });
        } catch (AssertionError e) {
            assertTrue(failure.equals(e.getMessage()));
        }
    } finally {
        ThreadContext.detach();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) MockApplication(org.apache.wicket.mock.MockApplication) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) AbstractResource(org.apache.wicket.request.resource.AbstractResource) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) MockApplication(org.apache.wicket.mock.MockApplication) Application(org.apache.wicket.Application) IResource(org.apache.wicket.request.resource.IResource) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Test(org.junit.Test)

Example 4 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class AnnotationsRoleAuthorizationStrategyTest method deniesResourceWithoutRequiredRole.

@Test
public void deniesResourceWithoutRequiredRole() throws Exception {
    AnnotationsRoleAuthorizationStrategy strategy = new AnnotationsRoleAuthorizationStrategy(roles("role2"));
    IResource resource = Mockito.mock(RestrictedResource.class);
    assertFalse(strategy.isResourceAuthorized(resource, null));
}
Also used : IResource(org.apache.wicket.request.resource.IResource) Test(org.junit.Test)

Example 5 with IResource

use of org.apache.wicket.request.resource.IResource in project wicket by apache.

the class HeaderResponseTest method before.

/**
 * Prepare
 */
@Before
public void before() {
    final Response realResponse = new StringResponse();
    headerResponse = new HeaderResponse() {

        @Override
        protected Response getRealResponse() {
            return realResponse;
        }
    };
    reference = new ResourceReference("testReference") {

        private static final long serialVersionUID = 1L;

        @Override
        public IResource getResource() {
            return null;
        }
    };
    RequestCycle requestCycle = mock(RequestCycle.class);
    when(requestCycle.urlFor(any(IRequestHandler.class))).thenReturn(RESOURCE_NAME);
    when(requestCycle.find(any())).thenReturn(Optional.empty());
    Request request = mock(Request.class);
    when(request.getCharset()).thenReturn(Charset.defaultCharset());
    when(requestCycle.getRequest()).thenReturn(request);
    UrlRenderer urlRenderer = mock(UrlRenderer.class);
    when(urlRenderer.renderContextRelativeUrl((any(String.class)))).thenReturn(RESOURCE_NAME);
    when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
    ThreadContext.setRequestCycle(requestCycle);
}
Also used : HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Request(org.apache.wicket.request.Request) StringResponse(org.apache.wicket.response.StringResponse) ResourceReference(org.apache.wicket.request.resource.ResourceReference) UrlRenderer(org.apache.wicket.request.UrlRenderer) IResource(org.apache.wicket.request.resource.IResource) Before(org.junit.Before)

Aggregations

IResource (org.apache.wicket.request.resource.IResource)24 ResourceReference (org.apache.wicket.request.resource.ResourceReference)10 Test (org.junit.Test)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 AjaxDownloadBehavior (org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)4 Application (org.apache.wicket.Application)3 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)3 IStaticCacheableResource (org.apache.wicket.request.resource.caching.IStaticCacheableResource)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)2 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)2 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BootstrapSettings (de.agilecoders.wicket.core.settings.BootstrapSettings)1 IBootstrapSettings (de.agilecoders.wicket.core.settings.IBootstrapSettings)1 SingleThemeProvider (de.agilecoders.wicket.core.settings.SingleThemeProvider)1