Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Mar 21, 2015 · 2 comments
Open

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

GoogleCodeExporter opened this issue Mar 21, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 1 Nov 2011 at 12:24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants