[Laszlo-checkins] r11696 - in openlaszlo/trunk/WEB-INF/lps: lfc/kernel/swf server/src/org/openlaszlo/servlets/responders

hqm@openlaszlo.org hqm at openlaszlo.org
Wed Nov 5 12:53:50 PST 2008


Author: hqm
Date: 2008-11-05 12:53:20 -0800 (Wed, 05 Nov 2008)
New Revision: 11696

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCACHEINFO.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCLEARCACHE.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderMEDIA.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSETCACHESIZE.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSTAT.java
Log:
Change 20081103-hqm-g by hqm at badtzmaru.home on 2008-11-03 20:45:35 EST
    in /Users/hqm/openlaszlo/trunk4
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: make LPS server pass media verbatim (no longer transcode to swf)

New Features:

Bugs Fixed: LPP-7294

Technical Reviewer: max
QA Reviewer: pbr
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    

Tests:

amazon in swf8 proxied and solo


demos/lzpix/app.lzx in swf8, swf9, [solo and proxied] Note, the lzpix app 
is hardcoded right now to make all image loads as SOLO requests.

 Testing for proxied image
loading in the lzpix app mode can be done by commenting out this line
at the start of the file 
   <script> 
      //LzView.addProxyPolicy( function (){ return false } ); 
   </script>


examples/image/dataimage.lzx (solo, proxied, [swf8, swf9])

examples/music/music.lzx swf8,swf9 [solo and proxied] Note: this
example plays audio in swf8 in proxied and SOLO, but something else is
wrong with it, the app reports a player running slowly before it
displays the player controls (I don't think this is related to this
change, it happens in both proxied and SOLO mode)



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs	2008-11-05 18:23:23 UTC (rev 11695)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzMediaLoader.lzs	2008-11-05 20:53:20 UTC (rev 11696)
@@ -160,27 +160,29 @@
     this.proxied = policy;
     o.proxied = policy;
 
+    var suffix = null;
+    // warn for unsupported media types
+    if (filetype == null) {
+        var si = req.lastIndexOf(".");
+        if (si != -1) {
+            suffix = req.substring(si + 1, si.length).toLowerCase();
+        }
+    } else {
+        var suffix = filetype;
+    }
+
+    this.isjpeg = (suffix == 'jpeg' || suffix == 'jpg');
+    this.isaudio = (suffix == 'mp3');
+
     if (this.proxied) {
         o.proxyurl = proxyurl;
     } else {
-        // warn for unsupported media types
-        if (filetype == null) {
-            var suffix = null;
-            var si = req.lastIndexOf(".");
-            if (si != -1) {
-                suffix = req.substring(si + 1, si.length).toLowerCase();
-            }
-        } else {
-            var suffix = filetype;
-        }
         if ($debug) {
             if (suffix != null && LzMediaLoader.unsupportedMediaTypes[suffix]) {
                 Debug.warn("serverless loading of resources with type '%s'" +
                            " is not supported by the Flash player. %w", suffix, req);
             }
         }
-        this.isjpeg = (suffix == 'jpeg' || suffix == 'jpg');
-        this.isaudio = (suffix == 'mp3');
     }
 
     if (headers != null) {

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCACHEINFO.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCACHEINFO.java	2008-11-05 18:23:23 UTC (rev 11695)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCACHEINFO.java	2008-11-05 20:53:20 UTC (rev 11696)
@@ -3,7 +3,7 @@
  * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -48,7 +48,6 @@
     public static String cacheInfo(boolean doDetails, boolean doSC)
         throws IOException
     {
-        Cache mediaCache    = ResponderMEDIA.getCache();
         Cache dataCache     = ResponderDATA.getCache();
         CompilationManager compilerCache = ResponderCompile.getCompilationManager();
         Cache compilerMediaCache = null;
@@ -60,9 +59,7 @@
 
         StringBuffer buf = new StringBuffer("");
         buf.append("<lps-cacheinfo>\n");
-        if (mediaCache != null) {
-            mediaCache.dumpXML(buf, "media-cache", doDetails);
-        }
+
         if (dataCache != null) {
             dataCache.dumpXML(buf, "data-cache", doDetails);
         }

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCLEARCACHE.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCLEARCACHE.java	2008-11-05 18:23:23 UTC (rev 11695)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderCLEARCACHE.java	2008-11-05 20:53:20 UTC (rev 11696)
@@ -3,7 +3,7 @@
  * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -29,7 +29,6 @@
 
     final static int CLEAR_COMPILATION = 0x01;
     final static int CLEAR_DATA        = 0x02;
-    final static int CLEAR_MEDIA       = 0x04;
     final static int CLEAR_SCRIPT      = 0x08;
 
     protected void respondAdmin(HttpServletRequest req, HttpServletResponse res)
@@ -53,12 +52,6 @@
             if (! cleared) isOk = false;
         }
 
-        if ( doClear(clearOptions, CLEAR_MEDIA) ) {
-            cleared = clearMediaCache();
-            buf.append("<media-cache cleared=\"" + cleared + "\" />\n");
-            if (! cleared) isOk = false;
-        }
-
         if ( doClear(clearOptions, CLEAR_SCRIPT) ) {
             cleared = clearScriptCache();
             buf.append("<script-cache cleared=\"" + cleared + "\" />\n");
@@ -101,7 +94,7 @@
     int getClearOptions(HttpServletRequest req) {
         String tokens = req.getParameter("cache");
         if (tokens == null || tokens.equals("")) {
-            return CLEAR_COMPILATION | CLEAR_DATA | CLEAR_MEDIA | CLEAR_SCRIPT;
+            return CLEAR_COMPILATION | CLEAR_DATA | CLEAR_SCRIPT;
         }
 
         int options = 0x00;
@@ -112,8 +105,6 @@
                 options |= CLEAR_COMPILATION;
             } else if ( o.equals("data") ) {
                 options |= CLEAR_DATA;
-            } else if ( o.equals("media") ) {
-                options |= CLEAR_MEDIA;
             } else if ( o.equals("script") ) {
                 options |= CLEAR_SCRIPT;
             }
@@ -126,12 +117,6 @@
         return ScriptCompiler.clearCacheStatic();
     }
 
-    boolean clearMediaCache() {
-        RequestCache mediaCache = ResponderMEDIA.getCache();
-        if (mediaCache == null) return false;
-        return mediaCache.clearCache();
-    }
-
     boolean clearDataCache() {
         RequestCache dataCache = ResponderDATA.getCache();
         if (dataCache == null) return false;

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderMEDIA.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderMEDIA.java	2008-11-05 18:23:23 UTC (rev 11695)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderMEDIA.java	2008-11-05 20:53:20 UTC (rev 11696)
@@ -3,7 +3,7 @@
  * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -19,52 +19,90 @@
 import org.openlaszlo.cache.MediaCache;
 import org.openlaszlo.cache.RequestCache;
 import org.openlaszlo.server.LPS;
+import org.openlaszlo.data.*;
+import org.openlaszlo.utils.FileUtils;
+import org.openlaszlo.utils.LZHttpUtils;
 
+import org.apache.commons.httpclient.*;
+import org.apache.commons.httpclient.methods.*;
+import org.apache.commons.httpclient.util.*;
+import org.apache.log4j.*;
+
 import org.apache.log4j.Logger;
 
-public final class ResponderMEDIA extends ResponderCache
+/* The Media responder will just request the data from the target URL,
+ * and forward the data verbatim to the client, preserving the content-type MIME
+ * header
+ *
+ */
+public final class ResponderMEDIA extends Responder
 {
-    private static MediaCache mCache = null;
-    private static boolean mIsInitialized = false;
     private static Logger mLogger = Logger.getLogger(ResponderMEDIA.class);
 
-    public void init(String reqName, ServletConfig config, Properties prop)
-        throws ServletException, IOException
-    { 
-        if (! mIsInitialized) {
-            // Initialize media cache
-            String cacheDir = config.getInitParameter("lps.mcache.directory");
-            if (cacheDir == null) {
-                cacheDir = prop.getProperty("mcache.directory");
-            }
-            if (cacheDir == null) {
-                cacheDir = LPS.getWorkDirectory() + File.separator + "mcache";
-            }
+    private static DataSource mHTTPDataSource = new HTTPDataSource();
 
-            File cache = checkDirectory(cacheDir);
-            mLogger.info(
+    
+    protected void respondImpl(HttpServletRequest req, HttpServletResponse res) {
+
+        String path = req.getServletPath();
+        String url;
+        try {
+            url  = DataSource.getURL(req);
+        } catch (java.net.MalformedURLException e) {
+            respondWithErrorSWF(res, "bad url: " + e.getMessage());
+            return;
+        }
+
+        if ( ! LPS.configuration.optionAllows(path, "proxy-security-urls", url) ) {
+            String err = "Forbidden url: " +  url;
+            respondWithError(res, err, HttpServletResponse.SC_FORBIDDEN);
+            mLogger.error(err);
+            return;
+        }
+
+        try { 
+
+            String app = LZHttpUtils.getRealPath(mContext, req);
+            HttpData mdata = (HttpData) mHTTPDataSource.getData(app, req, res, -1);
+            res.setContentType(mdata.getMimeType());
+            long size = mdata.size();
+            if (size != -1) {
+                mLogger.debug(
 /* (non-Javadoc)
  * @i18n.test
- * @org-mes="Media Cache is at " + p[0]
+ * @org-mes="setting content length: " + p[0]
  */
                         org.openlaszlo.i18n.LaszloMessages.getMessage(
-                                ResponderMEDIA.class.getName(),"051018-50", new Object[] {cacheDir})
+                                DataSource.class.getName(),"051018-266", new Object[] {new Long(size)})
 );
+                res.setContentLength((int)size);
+            }
 
+            InputStream instream = mdata.getInputStream();
+            OutputStream outstream = res.getOutputStream();
             try {
-                mCache = new MediaCache(cache, prop);
-            } catch (IOException e) {
-                throw new ServletException(e.getMessage());
+                long n = FileUtils.sendToStream(instream, outstream);
+            } catch (FileUtils.StreamWritingException e) {
+                mLogger.warn(
+                    /* (non-Javadoc)
+                     * @i18n.test
+                     * @org-mes="StreamWritingException while responding: " + p[0]
+                     */
+                    org.openlaszlo.i18n.LaszloMessages.getMessage(
+                        DataSource.class.getName(),"051018-201", new Object[] {e.getMessage()})
+                             );
+            } finally {
+                if (mdata != null) {
+                    mdata.release();
+                }
+                FileUtils.close(outstream);
+                FileUtils.close(instream);
             }
-
-            mIsInitialized = true;
-        }
-
-        super.init(reqName, config, mCache, prop);
+        } catch (Throwable e) { 
+            // Makes much easier to debug runtime exceptions
+            // but perhaps not strictly correct.
+            respondWithExceptionSWF(res, e);
+        } 
     }
 
-    static public RequestCache getCache()
-    {
-        return mCache;
-    }
 }

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSETCACHESIZE.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSETCACHESIZE.java	2008-11-05 18:23:23 UTC (rev 11695)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSETCACHESIZE.java	2008-11-05 20:53:20 UTC (rev 11696)
@@ -3,7 +3,7 @@
  * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -40,7 +40,7 @@
             } else if (t != null && t.equalsIgnoreCase("compiler")) {
                 cache = ResponderCompile.getCompilationManager();
             } else {
-                cache = ResponderMEDIA.getCache();
+                throw new RuntimeException("unknown cache type "+t);
             }
             if (k != null && k.equalsIgnoreCase("disk")) {
                 inMem = false; 

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSTAT.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSTAT.java	2008-11-05 18:23:23 UTC (rev 11695)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/servlets/responders/ResponderSTAT.java	2008-11-05 20:53:20 UTC (rev 11696)
@@ -3,7 +3,7 @@
  * ****************************************************************************/
 
 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
-* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * J_LZ_COPYRIGHT_END *********************************************************/
 
@@ -89,7 +89,6 @@
             mLastCleared = new Date();
         }
 
-        RequestCache mediaCache = ResponderMEDIA.getCache();
         RequestCache dataCache  = ResponderDATA.getCache();
 
         StringBuffer buf = new StringBuffer("");



More information about the Laszlo-checkins mailing list