Search in sources :

Example 36 with BinaryResource

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;
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) BinaryResourceHolder(org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)

Example 37 with BinaryResource

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));
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) BinaryResourceHolderWithAction(org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction) BinaryResourceHolder(org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder) Test(org.junit.Test)

Example 38 with BinaryResource

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());
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) BinaryResourceHolder(org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder) Test(org.junit.Test)

Example 39 with BinaryResource

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);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) JSONObject(org.json.JSONObject) DesktopWithNonDisplayableOutline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithNonDisplayableOutline) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test) JsonAdapterRegistryTest(org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)

Example 40 with BinaryResource

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);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject) Test(org.junit.Test)

Aggregations

BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)46 Test (org.junit.Test)26 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)19 HttpCacheKey (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey)15 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 BinaryResourceHolder (org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)4 InputStream (java.io.InputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JSONObject (org.json.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Field (java.lang.reflect.Field)1