Search in sources :

Example 21 with HttpRequestResponseInfo

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;
}
Also used : HtmlImage(com.att.aro.core.bestpractice.pojo.HtmlImage) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IOException(java.io.IOException)

Example 22 with HttpRequestResponseInfo

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;
}
Also used : HtmlImage(com.att.aro.core.bestpractice.pojo.HtmlImage) ImageSizeEntry(com.att.aro.core.bestpractice.pojo.ImageSizeEntry) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) ImageSizeResult(com.att.aro.core.bestpractice.pojo.ImageSizeResult) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 23 with HttpRequestResponseInfo

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;
}
Also used : MinificationResult(com.att.aro.core.bestpractice.pojo.MinificationResult) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) MinificationEntry(com.att.aro.core.bestpractice.pojo.MinificationEntry) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 24 with HttpRequestResponseInfo

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);
}
Also used : HashMap(java.util.HashMap) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) ArrayList(java.util.ArrayList) List(java.util.List) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map) Session(com.att.aro.core.packetanalysis.pojo.Session) HashSet(java.util.HashSet)

Example 25 with HttpRequestResponseInfo

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);
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) SearchingContent(com.att.aro.core.searching.pojo.SearchingContent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

HttpRequestResponseInfo (com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo)108 Session (com.att.aro.core.packetanalysis.pojo.Session)74 ArrayList (java.util.ArrayList)62 BaseTest (com.att.aro.core.BaseTest)40 Test (org.junit.Test)40 AbstractBestPracticeResult (com.att.aro.core.bestpractice.pojo.AbstractBestPracticeResult)29 PacketInfo (com.att.aro.core.packetanalysis.pojo.PacketInfo)14 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 TreeMap (java.util.TreeMap)10 File (java.io.File)9 IHttpRequestResponseHelper (com.att.aro.core.packetanalysis.IHttpRequestResponseHelper)5 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)5 TCPPacket (com.att.aro.core.packetreader.pojo.TCPPacket)5 URISyntaxException (java.net.URISyntaxException)5 List (java.util.List)5 PacketAnalyzerResult (com.att.aro.core.packetanalysis.pojo.PacketAnalyzerResult)4 RequestResponseTimeline (com.att.aro.core.packetanalysis.pojo.RequestResponseTimeline)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InetAddress (java.net.InetAddress)4