Havanero / gwt-syncproxy

Automatically exported from code.google.com/p/gwt-syncproxy
0 stars 0 forks source link

Find policy names in deferred javascript (with patch) #20

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Using code splitting, when a service is not included in the initial code, the 
policy name for this service is not found in the permutation html but in the 
deferred js file.

I changed the fetchSerializationPolicyName method to crawl the deferred js 
files.

Here is the modified method:

//////CODE//////////

public static Map<String, String> fetchSerializationPolicyName(String 
moduleBaseURL) throws IOException{
    Map<String, String> result = new HashMap<String, String>();

    moduleBaseURL = moduleBaseURL.trim(); //remove outer trim just in case
    String[] urlparts = moduleBaseURL.split("/");
    String moduleNoCacheJs = urlparts[urlparts.length-1] + ".nocache.js";   //get last word of url appended with .nocache.js

    String responseText = "";
    responseText = getResposeText(moduleBaseURL + moduleNoCacheJs);
    // parse the .nocache.js for list of Permutation name
    // Permutation name is 32 chars surrounded by apostrophe
    String regex = "\'([A-Z0-9]){32}\'";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(responseText);
    // while (matcher.find())
    if (matcher.find()){
        /// BEGIN CHANGE////
        String permutationName=matcher.group();
        permutationName = permutationName.replace("\'", "");

      // Load the first permutation html file
      String  permutationFile =permutationName+ ".cache.html";
        /// END CHANGE///
      responseText = getResposeText(moduleBaseURL + permutationFile);
      matcher = pattern.matcher(responseText);
      int i = 0;
      while (matcher.find()){
        String policyName = matcher.group();

        policyName = policyName.replace("\'", "");

        if (0 == i++){
          // The first one is the permutation name
          continue;
        }
        responseText = getResposeText(moduleBaseURL + policyName + GWT_PRC_POLICY_FILE_EXT);
        result.putAll(parsePolicyName(policyName, new ByteArrayInputStream(responseText.getBytes("UTF8"))));
      }
        /// BEGIN CHANGE////
      //Iterate over fragment files
      boolean exists=true;
      int fragmentIndex=1;
      while(exists){
         String url= moduleBaseURL+"deferredjs/"+permutationName+"/"+fragmentIndex+".cache.js";
         try {
                 responseText = getResposeText(url);
              matcher = pattern.matcher(responseText);
              i = 0;
              while (matcher.find()){
                String policyName = matcher.group();

                policyName = policyName.replace("\'", "");

                responseText = getResposeText(moduleBaseURL + policyName + GWT_PRC_POLICY_FILE_EXT);
                result.putAll(parsePolicyName(policyName, new ByteArrayInputStream(responseText.getBytes("UTF8"))));
              }

        } catch (IOException e) {
            //no found
            exists=false;
        }
         fragmentIndex++;

      }
        /// END CHANGE///

    }

    if (result.size() == 0){
      logger.warning("No RemoteService fetched from server");
    }else{
      dumpRemoteService(result);
    }

    return result;
  }

//////END CODE//////////

I made that quickly but it works for my installation.

Original issue reported on code.google.com by xfrontli...@gmail.com on 1 Nov 2011 at 12:24

GoogleCodeExporter commented 8 years ago
Thanks for submitting that patch, it worked for me right off the bat. But damn 
there are tons of warnings. I wonder if you happen to have patched the problem 
when it complains about certain classes not being found in the serialization 
policy file.

Original comment by george....@gmail.com on 13 Jan 2012 at 7:53

GoogleCodeExporter commented 8 years ago
The patch you've submitted will be integrated into the next version (probably 
0.6) of the library as I will need to make some larger changes to the testing 
system to verify this feature. Thanks

Original comment by p.pr...@blueesoteric.com on 9 Jan 2015 at 4:54

GoogleCodeExporter commented 8 years ago
This project is being migrated over to github as part of the Google Code 
Sunset. Please follow this issue at the GitHub project 
(https://github.com/jcricket/gwt-syncproxy/issues/20).

Original comment by p.pr...@blueesoteric.com on 30 Mar 2015 at 2:16