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>");
}
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;
}
Aggregations