How to use loadProvidersInternal method of org.cerberus.service.har.impl.HarService class

Best Cerberus-source code snippet using org.cerberus.service.har.impl.HarService.loadProvidersInternal

Source:HarService.java Github

copy

Full Screen

...73 String provider = null;74 // Load third party from json file.75 HashMap<String, List<String>> providersRules = loadProvidersExternal();76 // Load third party from invariant WEBPERFTHRIDPARTY.77 providersRules = loadProvidersInternal(providersRules);78 List<String> internalRules = new ArrayList<>();79 String[] dList = domains.split(",");80 for (String domain : dList) {81 internalRules.add(domain.trim());82 }83 String ignore = parameterService.getParameterStringByKey("cerberus_webperf_ignoredomainlist", system, "");84 List<String> ignoreRules = new ArrayList<>();85 dList = ignore.split(",");86 for (String domain : dList) {87 ignoreRules.add(domain.trim());88 }89 for (int i = 0; i < harEntries.length(); i++) {90 url = harEntries.getJSONObject(i).getJSONObject("request").getString("url");91 LOG.debug("Process hit " + i + " URL : " + url);92 // Getting provider from the url called.93 provider = getProvider(url, internalRules, ignoreRules, providersRules);94 // If we don't IGNORE, we add it to total.95 if (!provider.equalsIgnoreCase(PROVIDER_IGNORE)) {96 harTotalStat = processEntry(harTotalStat, harEntries.getJSONObject(i), url, provider, true);97 }98 // In all cases, we enrish the stat of the HasMap (if it exist) and put it back.99 if (!target.containsKey(provider)) {100 harProviderStat = new HarStat();101 } else {102 harProviderStat = target.get(provider);103 }104 harProviderStat = processEntry(harProviderStat, harEntries.getJSONObject(i), url, provider, false);105 target.put(provider, harProviderStat);106 }107 if (!target.containsKey(PROVIDER_IGNORE)) {108 target.put(PROVIDER_IGNORE, new HarStat());109 }110 if (!target.containsKey(PROVIDER_INTERNAL)) {111 target.put(PROVIDER_INTERNAL, new HarStat());112 }113 if (!target.containsKey(PROVIDER_UNKNOWN)) {114 target.put(PROVIDER_UNKNOWN, new HarStat());115 }116 // Build Recap of the total 117 harTotalStat = processRecap(harTotalStat);118 Date firstEver = new Date();119 if (harTotalStat.getFirstStart() != null) {120 firstEver = new Date(harTotalStat.getFirstStart().getTime());121 }122 JSONObject stat = new JSONObject();123 JSONObject thirdPartyStat = new JSONObject();124 // Adding total to HAR JSON.125 stat = addStat("total", harTotalStat, stat, firstEver);126 // Adding all providers to HAR JSON.127 int nbTP = 0;128 for (Map.Entry<String, HarStat> entry : target.entrySet()) {129 String key = entry.getKey();130 HarStat val = entry.getValue();131 // Build Recap of the provider132 val = processRecap(val);133 if (key.equals(PROVIDER_INTERNAL) || key.equals(PROVIDER_UNKNOWN) || key.equals(PROVIDER_IGNORE)) {134 stat = addStat(key, val, stat, firstEver);135 } else {136 nbTP++;137 thirdPartyStat = addStat(key, val, thirdPartyStat, firstEver);138 }139 }140 stat.put(PROVIDER_THIRDPARTY, thirdPartyStat);141 // Adding total ThirdParty nb to root level142 stat.put("nbThirdParty", nbTP);143 JSONArray req = new JSONArray();144 for (JSONObject jSONObject : harTotalStat.getUrlList()) {145 jSONObject.put("start", jSONObject.getLong("start") - firstEver.getTime());146 req.put(jSONObject);147 }148 stat.put("requests", req);149 har.put("stat", stat);150 return har;151 } catch (JSONException ex) {152 LOG.error("Exception when trying to enrich har file : " + ex.toString());153 } catch (Exception ex) {154 LOG.error("Exception when trying to enrich har file.", ex);155 }156 return har;157 }158 private HashMap<String, List<String>> loadProvidersExternal() {159 HashMap<String, List<String>> rules = new HashMap<>();160 try {161 String configFile = parameterService.getParameterStringByKey("cerberus_webperf_thirdpartyfilepath", "", "");162 if (StringUtil.isNullOrEmpty(configFile)) {163 LOG.warn("Could not load config file of Web Third Party. Please define a valid parameter for cerberus_webperf_thirdpartyfilepath.");164 return rules;165 }166 if (!Files.exists(Paths.get(configFile))) {167 LOG.error("Could not load config file of Web Third Party. File " + configFile + " does not exist. Please define a valid parameter for cerberus_webperf_thirdpartyfilepath.");168 return rules;169 }170 StringBuilder fileContent = new StringBuilder();171 try (Stream<String> stream = Files.lines(Paths.get(configFile), StandardCharsets.UTF_8)) {172 stream.forEach(s -> fileContent.append(s).append("\n"));173 } catch (Exception e) {174 LOG.error(e, e);175 }176 String thirdPartyList = fileContent.toString();177// LOG.debug(thirdPartyList);178 JSONArray json = new JSONArray(thirdPartyList);179 for (int i = 0; i < json.length(); i++) {180 List<String> tmpList = new ArrayList<>();181 JSONObject thirdParty = json.getJSONObject(i);182 for (int j = 0; j < thirdParty.getJSONArray("domains").length(); j++) {183 tmpList.add(thirdParty.getJSONArray("domains").getString(j));184 }185 rules.put(thirdParty.getString("name"), tmpList);186 }187 return rules;188 } catch (JSONException ex) {189 LOG.error("JSON Exception during loading of Third Party config.", ex);190 }191 return rules;192 }193 private HashMap<String, List<String>> loadProvidersInternal(HashMap<String, List<String>> list) {194 try {195 List<Invariant> invList = new ArrayList<>();196 invList = invariantService.readByIdName("WEBPERFTHIRDPARTY");197 for (Invariant invariant : invList) {198 List<String> provInterRules = new ArrayList<>();199 String[] dList = invariant.getGp1().split(",");200 for (String domain : dList) {201 provInterRules.add(domain.trim());202 }203 list.put(invariant.getValue(), provInterRules);204 }205 return list;206 } catch (CerberusException ex) {207 LOG.error(ex, ex);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful