Search in sources :

Example 1 with WebExternalResourceStream

use of org.apache.wicket.core.util.resource.WebExternalResourceStream in project wicket by apache.

the class WebExternalResourceTest method webExternalResource.

/**
 * @throws Exception
 */
// FIXME WebExternalResourceStream does not implement length()
@Test
public void webExternalResource() throws Exception {
    WebExternalResourceStream resource = new WebExternalResourceStream("/index.html");
    ResourceStreamRequestHandler rt = new ResourceStreamRequestHandler(resource);
    tester.processRequest(rt);
    assertTrue(tester.getContentTypeFromResponseHeader().startsWith("text/html"));
    tester.assertContains("<h1>Hello, World!</h1>");
}
Also used : WebExternalResourceStream(org.apache.wicket.core.util.resource.WebExternalResourceStream) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) Test(org.junit.Test)

Example 2 with WebExternalResourceStream

use of org.apache.wicket.core.util.resource.WebExternalResourceStream in project wicket by apache.

the class ContextRelativeResource method newResourceResponse.

@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
    final ResourceResponse resourceResponse = new ResourceResponse();
    final WebExternalResourceStream webExternalResourceStream = new WebExternalResourceStream(path);
    resourceResponse.setContentType(webExternalResourceStream.getContentType());
    resourceResponse.setLastModified(webExternalResourceStream.lastModifiedTime());
    resourceResponse.setFileName(path);
    resourceResponse.setWriteCallback(new WriteCallback() {

        @Override
        public void writeData(final Attributes attributes) throws IOException {
            try {
                InputStream inputStream = webExternalResourceStream.getInputStream();
                try {
                    Streams.copy(inputStream, attributes.getResponse().getOutputStream());
                } finally {
                    IOUtils.closeQuietly(inputStream);
                }
            } catch (ResourceStreamNotFoundException rsnfx) {
                throw new WicketRuntimeException(rsnfx);
            }
        }
    });
    return resourceResponse;
}
Also used : WebExternalResourceStream(org.apache.wicket.core.util.resource.WebExternalResourceStream) InputStream(java.io.InputStream) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException)

Aggregations

WebExternalResourceStream (org.apache.wicket.core.util.resource.WebExternalResourceStream)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 ResourceStreamRequestHandler (org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler)1 ResourceStreamNotFoundException (org.apache.wicket.util.resource.ResourceStreamNotFoundException)1 Test (org.junit.Test)1