Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    FileLoader.cacheISC() uses wrong directory (isomorphicDir is set)

    Hi Isomorphic,

    I noticed the following behaviour playing with FileLoader.cacheISC() in SmartGWT v9.0p_2013-10-29/EVAL Deployment. I have this in my html login page (it's a plain page pointing to j_security_check):

    Code:
    <script type="text/javascript" language="javascript">var isomorphicDir = "myproj/sc/";</script>
    <script type="text/javascript" language="javascript" src="myproj/sc/modules/ISC_FileLoader.js"></script>
    <script type="text/javascript" language="javascript">FL.cacheISC();</script>
    FF Developer console shows a HTTP 200/OK for the http://localhost:8080/myproj/myproj/sc/modules/ISC_FileLoader.js.

    The calls made by the FileLoader for ISC_Core.js and the other js files all return HTTP 404 because the path used is http://localhost:8080/myproj/myproj/sc/system/modules/ISC_Core.js.

    In http://www.smartclient.com/docs/9.0/...ss..FileLoader I did not find a setting for the path to the modules.

    Is this a bug or am I missing something?

    Best regards,
    Blama
    Last edited by Blama; 30 Oct 2013, 03:38.

    #2
    As further note, when using cacheModules() instead of cacheISC(), I get this JavaScript error in FF24: TypeError: iscRPCManager is undefined

    Comment


      #3
      Set isc.FileLoader.modulesDir = "modules/" to match your layout.

      It also seems like your "isomorphicDir" should not have "myproj" (since it appears twice in the generated path).

      About that JS error - are you processing JavaScript files in some way? There is no "iscRPCManager" or even "isc.RPCManager" token anywhere in the FileLoader JavaScript code.

      Comment


        #4
        Hi Isomorphic,

        thanks for the answer.
        Code:
        <script type="text/javascript" language="javascript">[B]FL.modulesDir = "modules/"; FL.defaultSkin = "Enterprise";[/B] FL.cacheISC();</script>
        worked for me.

        FL.modulesDir solved the modules part, the skin I found by searching for "skin" in ISC_FileLoader.js, but it would have been listed in the SmartClient Docs from my first post, too.
        Could I have found out about FL.modulesDir on my own? It's not listed there.



        Regarding the JS exception:
        You were right, it is written "isc.RPCManager" with the dot. And it does not come from FileLoader but from the verbatim pasted code for the relogin-mechanism. Is this code correct the way it is or does it change from version to version?

        Thanks for your answer,
        Blama

        Comment


          #5
          Originally posted by Isomorphic View Post
          It also seems like your "isomorphicDir" should not have "myproj" (since it appears twice in the generated path).
          That works for me, the URL of the 1st SmartGWT page is "http://localhost:8080/lms/Lms.html", the files are e.g. under "http://localhost:8080/lms/lms/sc/modules/ISC_FileLoader.js".

          I think I took this setup from the BuiltInDS-sample. Is it somehow unrecommended?

          Thanks,
          Blama

          Comment


            #6
            modulesDir wasn't doc'd, but it is now.

            We would need a way to reproduce the relogin issue. There's no obvious reason that should happen.

            Your directory setup is actually normal for GWT, it just looked like a redudant path entry because you deployed your app under a URL "myproj" (or "lms" in the second example), which happened to be the same as your module name.

            Comment


              #7
              Hi Isomorphic,

              thanks for the answer. For me everything is clear here now. Regarding the relogin I found the root cause:

              Below is my login.html (as described in https://isomorphic.atlassian.net/wik...mcat+JDBCRealm) used by Tomcat for unauthenticated users. But you can use any html with the ISC_FileLoader.js include.

              What happens when you include the ISC_FileLoader.js file is that the var isc in the verbatim code becomes an object, so if(isc) becomes true and therefore Firefox tries to execute isc.RPCManager.delayCall() from the verbatim copied relogin block. This does does not succeed, resulting in the JS error. I don't think that this is something one should worry about, but perhaps you like to know.

              The SHA1 code does not matter here and is there only as Tomcat does not support useful ciphers for passwd hashing, that could prevent brute force attacks on passwords.

              Best regards,
              Blama

              Code:
              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              <title></title>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
              <link rel="stylesheet" type="text/css" href="stylesheet.css" />
              
              <script type="text/javascript" language="javascript">var isomorphicDir = "lms/sc/";</script>
              <!-- 
              <script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_FileLoader.js"></script>
              <script type="text/javascript" language="javascript">FL.modulesDir = "modules/"; FL.defaultSkin = "Enterprise"; FL.cacheISC();</script>
              -->
              <script type="text/javascript" language="javascript" charset="utf-8">
              /**
              *
              *  Secure Hash Algorithm (SHA1)
              *  http://www.webtoolkit.info/
              *
              **/
              
              function SHA1x (msg, count) {
              		var salt = "123456abc";
              		var passwd = msg + salt;
              	  for( i = 1; i <= count; i++ ) {
              			passwd = SHA1(passwd);
              		}
              		return passwd;
              }
              
              function SHA1 (msg) {
               
              	function rotate_left(n,s) {
              		var t4 = ( n<<s ) | (n>>>(32-s));
              		return t4;
              	};
               
              	function lsb_hex(val) {
              		var str="";
              		var i;
              		var vh;
              		var vl;
               
              		for( i=0; i<=6; i+=2 ) {
              			vh = (val>>>(i*4+4))&0x0f;
              			vl = (val>>>(i*4))&0x0f;
              			str += vh.toString(16) + vl.toString(16);
              		}
              		return str;
              	};
               
              	function cvt_hex(val) {
              		var str="";
              		var i;
              		var v;
               
              		for( i=7; i>=0; i-- ) {
              			v = (val>>>(i*4))&0x0f;
              			str += v.toString(16);
              		}
              		return str;
              	};
               
               
              	function Utf8Encode(string) {
              		string = string.replace(/\r\n/g,"\n");
              		var utftext = "";
               
              		for (var n = 0; n < string.length; n++) {
               
              			var c = string.charCodeAt(n);
               
              			if (c < 128) {
              				utftext += String.fromCharCode(c);
              			}
              			else if((c > 127) && (c < 2048)) {
              				utftext += String.fromCharCode((c >> 6) | 192);
              				utftext += String.fromCharCode((c & 63) | 128);
              			}
              			else {
              				utftext += String.fromCharCode((c >> 12) | 224);
              				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
              				utftext += String.fromCharCode((c & 63) | 128);
              			}
               
              		}
               
              		return utftext;
              	};
               
              	var blockstart;
              	var i, j;
              	var W = new Array(80);
              	var H0 = 0x67452301;
              	var H1 = 0xEFCDAB89;
              	var H2 = 0x98BADCFE;
              	var H3 = 0x10325476;
              	var H4 = 0xC3D2E1F0;
              	var A, B, C, D, E;
              	var temp;
               
              	msg = Utf8Encode(msg);
               
              	var msg_len = msg.length;
               
              	var word_array = new Array();
              	for( i=0; i<msg_len-3; i+=4 ) {
              		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
              		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
              		word_array.push( j );
              	}
               
              	switch( msg_len % 4 ) {
              		case 0:
              			i = 0x080000000;
              		break;
              		case 1:
              			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
              		break;
               
              		case 2:
              			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
              		break;
               
              		case 3:
              			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
              		break;
              	}
               
              	word_array.push( i );
               
              	while( (word_array.length % 16) != 14 ) word_array.push( 0 );
               
              	word_array.push( msg_len>>>29 );
              	word_array.push( (msg_len<<3)&0x0ffffffff );
               
               
              	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
               
              		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
              		for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
               
              		A = H0;
              		B = H1;
              		C = H2;
              		D = H3;
              		E = H4;
               
              		for( i= 0; i<=19; i++ ) {
              			temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
              			E = D;
              			D = C;
              			C = rotate_left(B,30);
              			B = A;
              			A = temp;
              		}
               
              		for( i=20; i<=39; i++ ) {
              			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
              			E = D;
              			D = C;
              			C = rotate_left(B,30);
              			B = A;
              			A = temp;
              		}
               
              		for( i=40; i<=59; i++ ) {
              			temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
              			E = D;
              			D = C;
              			C = rotate_left(B,30);
              			B = A;
              			A = temp;
              		}
               
              		for( i=60; i<=79; i++ ) {
              			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
              			E = D;
              			D = C;
              			C = rotate_left(B,30);
              			B = A;
              			A = temp;
              		}
               
              		H0 = (H0 + A) & 0x0ffffffff;
              		H1 = (H1 + B) & 0x0ffffffff;
              		H2 = (H2 + C) & 0x0ffffffff;
              		H3 = (H3 + D) & 0x0ffffffff;
              		H4 = (H4 + E) & 0x0ffffffff;
               
              	}
               
              	var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
               
              	return temp.toLowerCase();
              }
              </script>
              </head>
              <body>
              <!--
              <div id="outer"> 
                <div id="row1"></div>
                <div id="row2"></div>
                <div id="row3"></div>
                <div id="clearer"></div>
              </div>
              -->
              <div id="box">
              <form method="post" action="j_security_check" onsubmit="j_password.value = (SHA1x(password.value, 999))"> 
                      <label>Benutzername:</label>
                          <input type="text" name="j_username" />
                      <label>Passwort:</label>
                          <input type="password" name="password" />
                          <input type="password" name="j_password" style="display: none;" />
                          <input type="submit" value="Einloggen" name="submit" class="submit" />
                          <input type="reset" value="Abbrechen" class="submit" />
              </form>
              </div>
              <SCRIPT>//'"]]>>isc_loginRequired
              //
              // Embed this whole script block VERBATIM into your login page to enable
              // SmartClient RPC relogin.
              
              while (!window.isc && document.domain.indexOf(".") != -1) {
                  try {
              	
                      if (parent.isc == null) {
                          document.domain = document.domain.replace(/.*?\./, '');
                          continue;
                      } 
                      break;
                  } catch (e) {
                      document.domain = document.domain.replace(/.*?\./, '');
                  }
              }
              
              var isc = top.isc ? top.isc : window.opener ? window.opener.isc : null;
              if (isc) isc.RPCManager.delayCall("handleLoginRequired", [window]);
              </SCRIPT>
              </body>
              </html>

              Comment


                #8
                We see what you mean. You should either:

                1. just put the ISC_FileLoader.js include later in the file, after the loginSuccessMarker

                OR

                2. improve upon the if (isc) conditional. For example, "if (isc.Canvas)" would detect whether you've actually got ISC_Core.js loaded and executed in the page.

                Comment


                  #9
                  Hi Isomorphic,

                  thanks for the answer, I'll do so.
                  I stumbled upon another problem with cacheISC() and loadISC().

                  In my plain login page login.html I have this code:
                  Code:
                  <script type="text/javascript" language="javascript">var isomorphicDir = "lms/sc/";</script>
                  <script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_FileLoader.js"></script>
                  <script type="text/javascript" language="javascript">FL.modulesDir = "modules/"; FL.defaultSkin = "Enterprise"; FL.cacheISC();</script>
                  This caches the modules just fine. Cached URLs are:
                  Code:
                  GET http://localhost:8080/lms/lms/sc/modules/ISC_Core.js[B]?isc_version=v9.0p_2013-10-30.js[/B]
                  and the like. On refresh I get a 302/Not modified, just as expected.

                  In my Lms.html (the page executing SmartGWT and lms.nocache.js) I had this working code:
                  Code:
                  	....
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_Core.js"></script>
                  	
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_Foundation.js"></script>
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_Containers.js"></script>
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_Grids.js"></script>
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_Forms.js"></script>
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_RichTextEditor.js"></script>
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_Calendar.js"></script>
                  	
                  	<script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_DataBinding.js"></script>
                  	<script type="text/javascript" language="javascript" src="lms/sc/skins/Enterprise/load_skin.js"></script>
                      <script type="text/javascript" language="javascript" src="lms/lms.nocache.js"></script>
                    </head>
                    <body>
                      <script type="text/javascript" language="javascript" src="lms/sc/DataSourceLoader?dataSource=...longlist"></script>
                      <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
                    </body>
                  This worked just fine, but meant another GET with HTTP 200 to all the SmartGWT JS files, as they did not have the version as parameter, so the requests differed.
                  Nevertheless it worked because (I might be wrong here) the JS files were executed in sequence.

                  To resolve the caching issue, I included FileLoader in my main file as well in the following way (removing the handwritten SmartGWT JS imports):
                  Code:
                  	....
                    <script type="text/javascript" language="javascript">var isomorphicDir = "lms/sc/";</script>
                    <script type="text/javascript" language="javascript" src="lms/sc/modules/ISC_FileLoader.js"></script>
                    <script type="text/javascript" language="javascript">FL.modulesDir = "modules/"; FL.defaultSkin = "Enterprise"; FL.loadISC();</script>
                    <script type="text/javascript" language="javascript" src="lms/lms.nocache.js"></script>
                    </head>
                    <body>
                      <script type="text/javascript" language="javascript" src="lms/sc/DataSourceLoader?dataSource=...longlist"></script>
                      <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
                    </body>
                  This resolves the caching issue (requests now with version, response is 304/Not modified), but as it seems the lms.nocache.js and src="lms/sc/DataSourceLoader?dataSource=...longlist" are executed too early, resulting in JS errors from the lms.nocache.js and an error alert from the DSLoader ("Can't load DataSources - SmartClient runtime not loaded").

                  I saw that loadISC() has an overload taking a callback as 3rd parameter. Is this the way to get rid of the JS errors? If so, how would it look like (I'm not that proficient in JS).

                  Best regards,
                  Blama

                  Comment


                    #10
                    You shouldn't use FileLoader for the main page, you should just have your <script> tags match the URLs FileLoader is using.

                    Comment


                      #11
                      Hi Isomorphic,

                      OK. I'll do it manually/with JSP.
                      Is there an easy way to get the date/version from a SmartGWT file so that I don't have to change the html/jsp every time I download a new version?

                      Best regards,
                      Blama

                      Comment

                      Working...
                      X