use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class JsonBrowserField method provideBinaryResource.
@Override
public BinaryResourceHolder provideBinaryResource(String filenameWithFingerprint) {
Pair<String, Long> filenameAndFingerprint = BinaryResourceUrlUtility.extractFilenameWithFingerprint(filenameWithFingerprint);
String filename = filenameAndFingerprint.getLeft();
BinaryResource binaryResource = getModel().getUIFacade().requestBinaryResourceFromUI(filename);
BinaryResourceHolder holder = new BinaryResourceHolder(binaryResource);
holder.addHttpResponseInterceptor(new BrowserFieldContentHttpResponseInterceptor(getUiSession()));
return holder;
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class DownloadHandlerStorageTest method testRemove.
@Test
public void testRemove() {
DownloadHandlerStorage storage = new DownloadHandlerStorage() {
@Override
protected long getRemovalTimeoutAfterFirstRequest() {
return 100L;
}
};
BinaryResource res = new BinaryResource("bar.txt", null);
BinaryResourceHolder holder = new BinaryResourceHolder(res);
storage.put(KEY, holder, OpenUriAction.DOWNLOAD);
assertEquals(1, storage.futureMap().size());
BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
assertEquals(OpenUriAction.DOWNLOAD, holderWithAction.getOpenUriAction());
assertEquals(res, holderWithAction.getHolder().get());
assertEquals("future should still be in futureMap", 1, storage.futureMap().size());
assertEquals(res, holderWithAction.getHolder().get());
SleepUtil.sleepElseLog(150, TimeUnit.MILLISECONDS);
assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
assertNull(storage.get(KEY));
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class DownloadHandlerStorageTest method testRemove_AfterTimeout.
@Test
public void testRemove_AfterTimeout() {
DownloadHandlerStorage storage = new DownloadHandlerStorage() {
@Override
protected long getTTLForResource(BinaryResource res) {
return 10L;
}
};
BinaryResource res = new BinaryResource("bar.txt", null);
BinaryResourceHolder holder = new BinaryResourceHolder(res);
storage.put(KEY, holder, OpenUriAction.NEW_WINDOW);
SleepUtil.sleepElseLog(100, TimeUnit.MILLISECONDS);
assertNull(storage.get(KEY));
assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class JsonDesktopTest method testHandleModelDownloadResource.
@Test
public void testHandleModelDownloadResource() throws Exception {
IDesktop desktop = new DesktopWithNonDisplayableOutline();
desktop.initDesktop();
JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
jsonDesktop.handleModelOpenUri(new BinaryResource("foo.txt", null), OpenUriAction.DOWNLOAD);
jsonDesktop.handleModelOpenUri(new BinaryResource("TP6 ARL ; Zulassung (UVV) - Bearbeitung elektr. Fax-Eingang [-8874 , ABC-Prüfbericht] (1).pdf", null), OpenUriAction.DOWNLOAD);
List<JsonEvent> events = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "openUri");
JSONObject[] data = new JSONObject[2];
data[0] = events.get(0).getData();
data[1] = events.get(1).getData();
// counter = 0 first for test run
assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/0/foo.txt", data[0].getString("uri"));
assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/1/TP6%2520ARL%2520%253B%2520Zulassung%2520%2528UVV%2529%2520-%2520Bearbeitung%2520elektr.%2520Fax-Eingang%2520%255B-8874%2520%252C%2520ABC-Pr%25C3%25BCfbericht%255D%2520%25281%2529.pdf", // counter = 1 second for test run
data[1].getString("uri"));
assertEquals("download", data[0].getString("action"));
assertEquals("download", data[1].getString("action"));
// cleanup
Jobs.getJobManager().cancel(Jobs.newFutureFilterBuilder().andMatchExecutionHint(DownloadHandlerStorage.RESOURCE_CLEANUP_JOB_MARKER).toFilter(), true);
}
use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.
the class HttpCacheControlTest method testCheckAndSet_EnableCaching_IfNoneMatch_true.
@Test
public void testCheckAndSet_EnableCaching_IfNoneMatch_true() throws Exception {
Mockito.when(req.getPathInfo()).thenReturn("/");
Mockito.when(req.getHeader(HttpCacheControl.ETAG)).thenReturn(null);
// matching E-Tag
Mockito.when(req.getHeader(HttpCacheControl.IF_NONE_MATCH)).thenReturn("W/\"FooBar\", W/\"13-535168142\"");
Mockito.when(req.getDateHeader(HttpCacheControl.IF_MODIFIED_SINCE)).thenReturn(0L);
BinaryResource res = BinaryResources.create().withFilename("a.html").withContent("<html></html>".getBytes("UTF-8")).withCachingAllowed(true).withLastModifiedNow().build();
HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey("/"), res);
boolean b = cc.checkAndSetCacheHeaders(req, resp, obj);
Assert.assertTrue(b);
Mockito.verify(req, ANY_TIMES).getPathInfo();
Mockito.verify(req, ANY_TIMES).getAttribute("javax.servlet.forward.path_info");
Mockito.verify(req, ANY_TIMES).getHeader(HttpCacheControl.ETAG);
Mockito.verify(req, ANY_TIMES).getHeader(HttpCacheControl.IF_NONE_MATCH);
Mockito.verify(req, ANY_TIMES).getDateHeader(HttpCacheControl.IF_MODIFIED_SINCE);
Mockito.verify(resp, ONCE).setHeader(HttpCacheControl.CACHE_CONTROL, "private, max-age=0, must-revalidate");
Mockito.verify(resp, ONCE).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
Aggregations