use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class ImageSizeImpl method checkThisImageInAllHTMLOrCSS.
/**
* This method checks the existence of specific image in all HTML Or CSS files.
*
* @return List of HtmlImage
*/
private List<HtmlImage> checkThisImageInAllHTMLOrCSS(Session tcpSession, HttpRequestResponseInfo reqRessInfo) {
ArrayList<HtmlImage> htmlImageLst = new ArrayList<HtmlImage>();
int noOfRRRecords = 0;
for (HttpRequestResponseInfo hrri : tcpSession.getRequestResponseInfo()) {
++noOfRRRecords;
if (hrri.getDirection() == HttpDirection.RESPONSE && hrri.getContentType() != null) {
String contentType = hrri.getContentType();
if (contentType.equalsIgnoreCase("text/css") || contentType.equalsIgnoreCase("text/html")) {
HttpRequestResponseInfo assocReqResp = reqRessInfo.getAssocReqResp();
if (assocReqResp != null) {
String imageToSearchFor = assocReqResp.getObjName();
String imageDownloaded = null;
try {
imageDownloaded = reqhelper.getContentString(hrri, tcpSession);
} catch (IOException e) {
LOG.warn("IOException, something is wrong.", e);
} catch (Exception e) {
LOG.error("Failed to get content from HttpRequestResponseInfo", e);
}
if ((imageToSearchFor != null && imageDownloaded != null) && (imageDownloaded.toLowerCase().contains(imageToSearchFor.toLowerCase()))) {
Document doc = Jsoup.parse(imageDownloaded);
Elements images = doc.select("[src]");
for (Element src : images) {
if ((src.tagName().equals("img")) && ((src.attr("abs:src")).contains(imageToSearchFor))) {
mImageFoundInHtmlOrCss = true;
/* Get width and height from HTML or CSS */
String width = extractNumericValue(src.attr("width"));
String height = extractNumericValue(src.attr("height"));
if (!width.isEmpty() && !height.isEmpty()) {
double iWidth = Double.parseDouble(width);
double iHeight = Double.parseDouble(height);
htmlImageLst.add(new HtmlImage((int) iWidth, (int) iHeight));
break;
}
}
}
}
}
} else if (!mImageFoundInHtmlOrCss && (noOfRRRecords == tcpSession.getRequestResponseInfo().size())) {
/*
* searched all the RR records in this session. calculate the size of this image w.r.t to screen size
*/
mImageFoundInHtmlOrCss = true;
}
}
}
return htmlImageLst;
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class ImageSizeImpl method runTest.
@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
mImageFoundInHtmlOrCss = false;
ImageSizeResult result = new ImageSizeResult();
List<ImageSizeEntry> entrylist = new ArrayList<ImageSizeEntry>();
// 480 * 1.1;
int deviceScreenSizeX = 528;
// 800 * 1.1;
int deviceScreenSizeY = 880;
// screen size is available when reading trace directory
if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) {
TraceDirectoryResult dirdata = (TraceDirectoryResult) tracedata.getTraceresult();
deviceScreenSizeX = (dirdata.getDeviceScreenSizeX() * 110) / 100;
deviceScreenSizeY = (dirdata.getDeviceScreenSizeY() * 110) / 100;
}
for (Session session : tracedata.getSessionlist()) {
HttpRequestResponseInfo lastReq = null;
for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) {
if (req.getDirection() == HttpDirection.REQUEST) {
lastReq = req;
}
if (req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getContentType().contains("image/")) {
boolean isBigSize = false;
List<HtmlImage> htmlImageList = checkThisImageInAllHTMLOrCSS(session, req);
if (mImageFoundInHtmlOrCss) {
mImageFoundInHtmlOrCss = false;
if (!htmlImageList.isEmpty()) {
for (int index = 0; index < htmlImageList.size(); index++) {
HtmlImage htmlImage = htmlImageList.get(index);
isBigSize = compareDownloadedImgSizeWithStdImageSize(req, htmlImage, deviceScreenSizeX, deviceScreenSizeY, session);
if (isBigSize) {
break;
}
}
} else {
isBigSize = compareDownloadedImgSizeWithStdImageSize(req, null, deviceScreenSizeX, deviceScreenSizeY, session);
}
if (isBigSize) {
entrylist.add(new ImageSizeEntry(req, lastReq, session.getDomainName()));
}
}
}
}
}
result.setDeviceScreenSizeRangeX(deviceScreenSizeX);
result.setDeviceScreenSizeRangeY(deviceScreenSizeY);
result.setResults(entrylist);
String text = "";
if (entrylist.isEmpty()) {
result.setResultType(BPResultType.PASS);
text = MessageFormat.format(textResultPass, entrylist.size());
result.setResultText(text);
result.setResultExcelText(BPResultType.PASS.getDescription());
} else {
result.setResultType(BPResultType.FAIL);
text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), entrylist.size());
result.setResultText(text);
result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), entrylist.size()));
}
result.setAboutText(aboutText);
result.setDetailTitle(detailTitle);
result.setLearnMoreUrl(learnMoreUrl);
result.setOverviewTitle(overviewTitle);
result.setExportNumberOfLargeImages(exportNumberOfLargeImages);
return result;
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class MinificationImpl method runTest.
@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
htmlCompressor = null;
MinificationResult result = new MinificationResult();
initHtmlCompressor();
List<MinificationEntry> minificationEntryList = new ArrayList<MinificationEntry>();
String contentType = null;
int totalSavingInBytes = 0;
int totalBytes = 0;
final ExecutorService executorService = Executors.newFixedThreadPool(50);
Collection<Worker> workers = new ArrayList<Worker>();
for (Session session : tracedata.getSessionlist()) {
HttpRequestResponseInfo lastRequestObj = null;
for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) {
if (req.getDirection() == HttpDirection.REQUEST) {
lastRequestObj = req;
}
contentType = req.getContentType();
if (req.getDirection() == HttpDirection.RESPONSE && req.getContentLength() > 0 && contentType != null) {
workers.add(new Worker(contentType, req, lastRequestObj, session));
// if (reqhelper.isJavaScript(contentType)) {
// entry = calculateSavingMinifiedJavascript(req, lastRequestObj, session);
// } else if (reqhelper.isCss(contentType)) {
// workers.add(new Worker(req, lastRequestObj, session));
// // Future<MinificationEntry> res1 = executorService.submit(new Worker(req, lastRequestObj, session);
// // entry = calculateSavingMinifiedCss(req, lastRequestObj, session);
// } else if (reqhelper.isHtml(contentType)) {
// entry = calculateSavingMinifiedHtml(req, lastRequestObj, session);
// } else if (reqhelper.isJSON(contentType)) {
// entry = calculateSavingMinifiedJson(req, lastRequestObj, session);
// }
// if (entry != null) {
// totalSavingInBytes += entry.getSavingsSizeInByte();
// minificationEntryList.add(entry);
// }
}
}
}
try {
List<Future<MinificationEntry>> list = executorService.invokeAll(workers);
for (Future<MinificationEntry> future : list) {
if (future != null && future.get() != null) {
totalSavingInBytes += future.get().getSavingsSizeInByte();
totalBytes += future.get().getOriginalSizeInByte();
minificationEntryList.add(future.get());
}
}
} catch (InterruptedException | ExecutionException ee) {
LOGGER.error(ee.getMessage(), ee);
}
executorService.shutdown();
int savingInKb = totalSavingInBytes / 1024;
result.setTotalSavingsInKb(savingInKb);
result.setTotalSavingsInByte(totalSavingInBytes);
result.setMinificationEntryList(minificationEntryList);
int numberOfFiles = minificationEntryList.size();
String text = "";
if (minificationEntryList.isEmpty()) {
result.setResultType(BPResultType.PASS);
text = MessageFormat.format(textResultPass, numberOfFiles, savingInKb);
result.setResultText(text);
result.setResultExcelText(BPResultType.PASS.getDescription());
} else if (savingInKb < 1) {
result.setResultType(BPResultType.FAIL);
text = MessageFormat.format(textResultFail, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles);
result.setResultText(text);
result.setResultExcelText(MessageFormat.format(textExcelResultsFail, BPResultType.FAIL.getDescription(), numberOfFiles));
} else {
result.setResultType(BPResultType.FAIL);
String percentageSaving = String.valueOf(Math.round(((double) totalSavingInBytes / totalBytes) * 100));
text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles, savingInKb, percentageSaving);
result.setResultText(text);
result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), numberOfFiles, savingInKb, percentageSaving));
}
result.setAboutText(aboutText);
result.setDetailTitle(detailTitle);
result.setLearnMoreUrl(learnMoreUrl);
result.setOverviewTitle(overviewTitle);
result.setExportAllNumberOfMinifyFiles(exportAllNumberOfMinifyFiles);
return result;
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class PeriodicTransferImpl method diagnosisPeriodicRequest.
/**
* Burst data's analyzed to categorize the periodic bursts.
*/
private void diagnosisPeriodicRequest(List<Session> sessionlist, List<Burst> burstCollection, Profile profile) {
/*
* Represent lists of hosts, objects, and IPs requested via HTTP and
* timestamps when these requests were made.
*/
Map<String, List<Double>> requestedHost2tsList = new HashMap<String, List<Double>>();
Map<String, List<Double>> requestedObj2tsList = new HashMap<String, List<Double>>();
Map<InetAddress, List<Double>> connectedIP2tsList = new HashMap<InetAddress, List<Double>>();
// int count = 0;
for (Session tcpSession : sessionlist) {
// Get a list of timestamps of established sessions with each remote IP
if (!tcpSession.isUdpOnly()) {
PacketInfo firstPacket = tcpSession.getTcpPackets().get(0);
if (firstPacket.getTcpInfo() == TcpInfo.TCP_ESTABLISH) {
List<Double> res = connectedIP2tsList.get(tcpSession.getRemoteIP());
if (res == null) {
res = new ArrayList<Double>();
connectedIP2tsList.put(tcpSession.getRemoteIP(), res);
}
res.add(Double.valueOf(firstPacket.getTimeStamp()));
}
// Get a list of timestamps of HTTP requests to hosts/object names
for (HttpRequestResponseInfo hrri : tcpSession.getRequestResponseInfo()) {
PacketInfo pkt = hrri.getFirstDataPacket();
if (hrri.getDirection() == HttpDirection.REQUEST && pkt != null) {
Double ts0 = Double.valueOf(pkt.getTimeStamp());
if (hrri.getHostName() != null) {
List<Double> tempRequestHostEventList = requestedHost2tsList.get(hrri.getHostName());
if (tempRequestHostEventList == null) {
tempRequestHostEventList = new ArrayList<Double>();
requestedHost2tsList.put(hrri.getHostName(), tempRequestHostEventList);
}
tempRequestHostEventList.add(ts0);
}
if (hrri.getObjName() != null) {
String objName = hrri.getObjNameWithoutParams();
List<Double> tempRequestObjEventList = requestedObj2tsList.get(objName);
if (tempRequestObjEventList == null) {
tempRequestObjEventList = new ArrayList<Double>();
requestedObj2tsList.put(objName, tempRequestObjEventList);
}
tempRequestObjEventList.add(ts0);
}
}
}
}
}
// logger.info("done looping session");
Set<String> hostList = new HashSet<String>();
Set<String> objList = new HashSet<String>();
Set<InetAddress> ipList = new HashSet<InetAddress>();
// count = 0;
for (Map.Entry<String, List<Double>> iter : requestedHost2tsList.entrySet()) {
if (determinePeriodicity(iter.getValue(), profile)) {
hostList.add(iter.getKey());
}
// logger.info("count: "+count++);
}
// count = 0;
for (Map.Entry<String, List<Double>> iter : requestedObj2tsList.entrySet()) {
if (determinePeriodicity(iter.getValue(), profile)) {
objList.add(iter.getKey());
}
// logger.info("count: "+count++);
}
// count = 0;
for (Map.Entry<InetAddress, List<Double>> iter : connectedIP2tsList.entrySet()) {
if (determinePeriodicity(iter.getValue(), profile)) {
ipList.add(iter.getKey());
}
// logger.info("count: "+count++);
}
// logger.info("Done looping, now go to determinePeriodicity");
determinePeriodicity(hostList, objList, ipList, burstCollection, profile, sessionlist);
}
use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.
the class TransmissionPrivateDataImpl method getContent.
/**
* get content string from given session
* @param session
* @return
*/
private SearchingContent getContent(Session session) {
String str = "";
ByteArrayOutputStream data = new ByteArrayOutputStream();
BufferedOutputStream dataWrapper = new BufferedOutputStream(data);
try {
for (HttpRequestResponseInfo rrInfo : session.getRequestResponseInfo()) {
if (rrInfo.getDirection() == HttpDirection.REQUEST) {
dataWrapper.write(rrInfo.getPayloadData().toByteArray());
}
}
dataWrapper.flush();
} catch (IOException e) {
LOGGER.error("Error extracting content from Session: " + session.getSessionKey());
}
str = Util.byteArrayToString(data.toByteArray());
return new SearchingContent(str);
}
Aggregations