Search in sources :

Example 1 with Attributes

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

the class ResourceStreamRequestHandler method respond.

/**
 * Responds by sending the contents of the resource stream.
 *
 * @see org.apache.wicket.request.IRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
 */
@Override
public void respond(IRequestCycle requestCycle) {
    Attributes attributes = new Attributes(requestCycle.getRequest(), requestCycle.getResponse());
    ResourceStreamResource resource = new ResourceStreamResource(resourceStream);
    configure(resource);
    resource.respond(attributes);
}
Also used : ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) Attributes(org.apache.wicket.request.resource.IResource.Attributes)

Example 2 with Attributes

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

the class LocalizedImageResource method onResourceRequested.

/**
 * @param parameters
 *            page parameters
 */
public final void onResourceRequested(PageParameters parameters) {
    bind();
    RequestCycle requestCycle = RequestCycle.get();
    Attributes attributes = new Attributes(requestCycle.getRequest(), requestCycle.getResponse(), parameters);
    resource.respond(attributes);
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Attributes(org.apache.wicket.request.resource.IResource.Attributes)

Example 3 with Attributes

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

the class ResourceLink method onRequest.

@Override
public final void onRequest() {
    Attributes a = new Attributes(RequestCycle.get().getRequest(), RequestCycle.get().getResponse(), null);
    resource.respond(a);
    super.onRequest();
}
Also used : Attributes(org.apache.wicket.request.resource.IResource.Attributes)

Example 4 with Attributes

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

the class ByteArrayResourceTest method staticResource.

/**
 * Unit test for {@link ByteArrayResource} with static byte array.
 */
@Test
public void staticResource() {
    String contentType = "application/octet-stream";
    byte[] array = new byte[] { 1, 2, 3 };
    ByteArrayResource resource = new ByteArrayResource(contentType, array) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void configureCache(ResourceResponse data, Attributes attributes) {
        // no caching is needed
        }
    };
    WebRequest request = mock(WebRequest.class);
    WebResponse response = mock(WebResponse.class);
    Attributes attributes = new Attributes(request, response);
    resource.respond(attributes);
    verify(response).write(same(array));
    verify(response).setContentLength(eq(3L));
    verify(response).setContentType(eq(contentType));
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) WebRequest(org.apache.wicket.request.http.WebRequest) Attributes(org.apache.wicket.request.resource.IResource.Attributes) Test(org.junit.Test)

Example 5 with Attributes

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

the class ByteArrayResourceTest method dynamicResource.

/**
 * Unit test for {@link ByteArrayResource} with dynamically generated byte array.
 */
@Test
public void dynamicResource() {
    String contentType = "application/octet-stream";
    final byte[] array = new byte[] { 1, 2, 3 };
    ByteArrayResource resource = new ByteArrayResource(contentType) {

        private static final long serialVersionUID = 1L;

        @Override
        protected byte[] getData(Attributes attributes) {
            return array;
        }

        @Override
        protected void configureCache(ResourceResponse data, Attributes attributes) {
        // no caching is needed
        }
    };
    WebRequest request = mock(WebRequest.class);
    WebResponse response = mock(WebResponse.class);
    Attributes attributes = new Attributes(request, response);
    resource.respond(attributes);
    verify(response).write(same(array));
    verify(response).setContentLength(eq(3L));
    verify(response).setContentType(eq(contentType));
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) WebRequest(org.apache.wicket.request.http.WebRequest) Attributes(org.apache.wicket.request.resource.IResource.Attributes) Test(org.junit.Test)

Aggregations

Attributes (org.apache.wicket.request.resource.IResource.Attributes)12 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)7 Test (org.junit.Test)6 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)5 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)3 Request (org.apache.wicket.request.Request)3 Locale (java.util.Locale)2 WebRequest (org.apache.wicket.request.http.WebRequest)2 WebResponse (org.apache.wicket.request.http.WebResponse)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 MockHttpServletResponse (org.apache.wicket.protocol.http.mock.MockHttpServletResponse)1 Response (org.apache.wicket.request.Response)1 Url (org.apache.wicket.request.Url)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 WriteCallback (org.apache.wicket.request.resource.AbstractResource.WriteCallback)1 ResourceStreamResource (org.apache.wicket.request.resource.ResourceStreamResource)1