Search in sources :

Example 1 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class HtmlFileLoader method loadResource.

@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
    String pathInfo = cacheKey.getResourcePath();
    BinaryResource content = loadResource(pathInfo);
    if (content == null) {
        return null;
    }
    // no cache-control, only E-Tag checks to make sure that a session with timeout is correctly
    // forwarded to the login using a GET request BEFORE the first json POST request
    HttpCacheObject httpCacheObject = new HttpCacheObject(cacheKey, content);
    // Suppress automatic "compatibility mode" in IE in intranet zone
    httpCacheObject.addHttpResponseInterceptor(new HttpResponseHeaderContributor("X-UA-Compatible", "IE=edge") {

        private static final long serialVersionUID = 1L;

        @Override
        public void intercept(HttpServletRequest req, HttpServletResponse resp) {
            HttpClientInfo httpClientInfo = HttpClientInfo.get(req);
            if (httpClientInfo.isMshtml()) {
                // Send headers only for IE
                super.intercept(req, resp);
            }
        }
    });
    return httpCacheObject;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpResponseHeaderContributor(org.eclipse.scout.rt.server.commons.servlet.cache.HttpResponseHeaderContributor) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject) HttpClientInfo(org.eclipse.scout.rt.server.commons.servlet.HttpClientInfo)

Example 2 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class JsonBrowserField method getLocation.

protected String getLocation() {
    String location = getModel().getLocation();
    BinaryResource binaryResource = getModel().getBinaryResource();
    if (location == null && binaryResource != null) {
        location = BinaryResourceUrlUtility.createDynamicAdapterResourceUrl(this, binaryResource);
    }
    return location;
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource)

Example 3 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class JsonImageField method extractBinaryResource.

protected BinaryResource extractBinaryResource(Object raw) {
    if (raw instanceof BinaryResource) {
        return (BinaryResource) raw;
    }
    if (raw instanceof byte[]) {
        Adler32 crc = new Adler32();
        crc.update((byte[]) raw);
        return new BinaryResource("image-" + (crc.getValue()) + "-" + (((byte[]) raw).length) + ".jpg", (byte[]) raw);
    }
    return null;
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) Adler32(java.util.zip.Adler32)

Example 4 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class AbstractResourceLoader method loadResource.

@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
    String pathInfo = cacheKey.getResourcePath();
    BinaryResource content = loadResource(pathInfo);
    if (content == null) {
        return null;
    }
    return new HttpCacheObject(cacheKey, content);
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)

Example 5 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class DownloadHandlerStorageTest method testGet.

@Test
public void testGet() {
    final CountDownLatch secondGet = new CountDownLatch(1);
    final CountDownLatch elementRemoved = new CountDownLatch(1);
    DownloadHandlerStorage storage = new DownloadHandlerStorage() {

        @Override
        protected long getTTLForResource(BinaryResource res) {
            return 50L;
        }

        @Override
        protected void removeOnTimeout(String key) {
            waitFor(secondGet);
            super.removeOnTimeout(key);
            elementRemoved.countDown();
        }
    };
    BinaryResource res = new BinaryResource("bar.txt", null);
    BinaryResourceHolder holder = new BinaryResourceHolder(res);
    storage.put(KEY, holder, OpenUriAction.NEW_WINDOW);
    assertEquals(1, storage.futureMap().size());
    BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
    assertEquals(OpenUriAction.NEW_WINDOW, holderWithAction.getOpenUriAction());
    assertEquals(res, holderWithAction.getHolder().get());
    assertFalse("Must not contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
    holderWithAction = storage.get(KEY);
    assertEquals(res, holderWithAction.getHolder().get());
    assertTrue("Must contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
    secondGet.countDown();
    waitFor(elementRemoved);
    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) CountDownLatch(java.util.concurrent.CountDownLatch) BinaryResourceHolderWithAction(org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction) BinaryResourceHolder(org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder) 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