Search in sources :

Example 1 with HttpRequestResponseInfo

use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.

the class DisplayNoneInCSSImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    DisplayNoneInCSSResult result = new DisplayNoneInCSSResult();
    List<DisplayNoneInCSSEntry> results = new ArrayList<DisplayNoneInCSSEntry>();
    for (Session session : tracedata.getSessionlist()) {
        for (HttpRequestResponseInfo reqinfo : session.getRequestResponseInfo()) {
            Document doc = null;
            String css;
            if ((reqinfo.getDirection() == HttpDirection.RESPONSE) && (reqinfo.getContentType() != null) && (reqinfo.getContentType().equalsIgnoreCase("text/html"))) {
                doc = getParsedHtml(reqinfo, session);
                if (doc != null && checkIfDisplayNoneIsPresentInCSSembeddedInHTML(doc)) {
                    results.add(new DisplayNoneInCSSEntry(reqinfo));
                }
            } else if (reqinfo.getDirection() == HttpDirection.RESPONSE && reqinfo.getContentType() != null && reqinfo.getContentType().equalsIgnoreCase("text/css")) {
                css = getCSS(reqinfo, session);
                if (css != null && checkIfDisplayNoneIsPresentInCSS(css)) {
                    results.add(new DisplayNoneInCSSEntry(reqinfo));
                }
            }
        }
    }
    int numOfCSSFiles = results.size();
    String text = "";
    if (results.isEmpty()) {
        result.setResultType(BPResultType.PASS);
        text = MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName(), numOfCSSFiles);
    } else {
        result.setResultType(BPResultType.FAIL);
        text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numOfCSSFiles);
    }
    result.setResultExcelText(MessageFormat.format(textExcelResults, result.getResultType().getDescription(), numOfCSSFiles));
    result.setResultText(text);
    result.setResults(results);
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setExportAll(exportAll);
    return result;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) DisplayNoneInCSSEntry(com.att.aro.core.bestpractice.pojo.DisplayNoneInCSSEntry) DisplayNoneInCSSResult(com.att.aro.core.bestpractice.pojo.DisplayNoneInCSSResult) Document(org.jsoup.nodes.Document) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 2 with HttpRequestResponseInfo

use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.

the class CombineCsJssImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    CombineCsJssResult result = new CombineCsJssResult();
    // Changes for US432336
    List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>();
    int inefficientCssRequests = 0;
    PacketInfo consecutiveCssJsFirstPacket = null;
    int inefficientJsRequests = 0;
    double cssLastTimeStamp = 0.0;
    double jsLastTimeStamp = 0.0;
    String contentType = "";
    for (Session session : tracedata.getSessionlist()) {
        HttpRequestResponseInfo lastRequestObj = null;
        for (HttpRequestResponseInfo httpreq : session.getRequestResponseInfo()) {
            if (httpreq.getDirection() == HttpDirection.REQUEST) {
                lastRequestObj = httpreq;
            }
            if (httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null) {
                PacketInfo pktInfo = httpreq.getFirstDataPacket();
                if (pktInfo != null) {
                    contentType = httpreq.getContentType().toLowerCase().trim();
                    if (contentType.equalsIgnoreCase("text/css")) {
                        if (cssLastTimeStamp == 0.0) {
                            cssLastTimeStamp = pktInfo.getTimeStamp();
                            continue;
                        } else {
                            if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) {
                                inefficientCssRequests++;
                                // Changes for US432336
                                CsJssFilesDetails cssFileDetails = new CsJssFilesDetails();
                                cssFileDetails.setTimeStamp(pktInfo.getTimeStamp());
                                if (httpreq.getObjName() != null) {
                                    cssFileDetails.setFileName(httpreq.getObjName());
                                } else {
                                    if (lastRequestObj != null) {
                                        cssFileDetails.setFileName(lastRequestObj.getObjName());
                                    }
                                }
                                cssFileDetails.setSize(httpreq.getContentLength());
                                fileDetails.add(cssFileDetails);
                                if (consecutiveCssJsFirstPacket == null) {
                                    consecutiveCssJsFirstPacket = pktInfo;
                                }
                            }
                            cssLastTimeStamp = pktInfo.getTimeStamp();
                        }
                    } else if (contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")) {
                        if (jsLastTimeStamp == 0.0) {
                            jsLastTimeStamp = pktInfo.getTimeStamp();
                            continue;
                        } else {
                            if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) {
                                inefficientJsRequests++;
                                // Changes for US432336
                                CsJssFilesDetails jsFileDetails = new CsJssFilesDetails();
                                jsFileDetails.setTimeStamp(pktInfo.getTimeStamp());
                                if (httpreq.getObjName() != null) {
                                    jsFileDetails.setFileName(httpreq.getObjName());
                                } else {
                                    if (lastRequestObj != null) {
                                        jsFileDetails.setFileName(lastRequestObj.getObjName());
                                    }
                                }
                                jsFileDetails.setSize(httpreq.getContentLength());
                                fileDetails.add(jsFileDetails);
                                if (consecutiveCssJsFirstPacket == null) {
                                    consecutiveCssJsFirstPacket = pktInfo;
                                }
                            }
                            jsLastTimeStamp = pktInfo.getTimeStamp();
                        }
                    }
                }
            }
        }
    }
    result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket);
    result.setInefficientCssRequests(inefficientCssRequests);
    result.setInefficientJsRequests(inefficientJsRequests);
    if (inefficientCssRequests < 1 && inefficientJsRequests < 1) {
        result.setResultType(BPResultType.PASS);
        result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName()));
    } else {
        result.setResultType(BPResultType.FAIL);
        result.setResultText(textResults);
        // Changes for US432336
        result.setFilesDetails(fileDetails);
    }
    result.setResultExcelText(result.getResultType().getDescription());
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest);
    result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest);
    return result;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) CombineCsJssResult(com.att.aro.core.bestpractice.pojo.CombineCsJssResult) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) CsJssFilesDetails(com.att.aro.core.bestpractice.pojo.CsJssFilesDetails) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 3 with HttpRequestResponseInfo

use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.

the class FileOrderImpl method runTest.

@Override
public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) {
    FileOrderResult result = new FileOrderResult();
    List<FileOrderEntry> results = new ArrayList<FileOrderEntry>();
    for (Session session : tracedata.getSessionlist()) {
        HttpRequestResponseInfo lastRequestObj = null;
        for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) {
            Document doc = null;
            if (req.getDirection() == HttpDirection.RESPONSE) {
                doc = parseHtml(req, session);
            } else if (req.getDirection() == HttpDirection.REQUEST) {
                lastRequestObj = req;
            }
            if (doc != null && checkFileOrderAnalysisResults(doc, result)) {
                results.add(new FileOrderEntry(req, lastRequestObj, session.getDomainName()));
            }
        }
    }
    String text = "";
    if (results.isEmpty()) {
        result.setResultType(BPResultType.PASS);
        text = MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName(), results.size());
        result.setResultExcelText(BPResultType.PASS.getDescription());
    } else {
        result.setResultType(BPResultType.FAIL);
        if (results.size() > 1) {
            text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), results.size());
        } else {
            text = MessageFormat.format(textResult, ApplicationConfig.getInstance().getAppShortName(), results.size());
        }
        result.setResultExcelText(MessageFormat.format(textExcelResults, BPResultType.FAIL.getDescription(), results.size()));
    }
    result.setResultText(text);
    result.setResults(results);
    result.setAboutText(aboutText);
    result.setDetailTitle(detailTitle);
    result.setLearnMoreUrl(learnMoreUrl);
    result.setOverviewTitle(overviewTitle);
    result.setTextResult(textResult);
    result.setExportAll(exportAll);
    return result;
}
Also used : FileOrderEntry(com.att.aro.core.bestpractice.pojo.FileOrderEntry) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) ArrayList(java.util.ArrayList) FileOrderResult(com.att.aro.core.bestpractice.pojo.FileOrderResult) Document(org.jsoup.nodes.Document) Session(com.att.aro.core.packetanalysis.pojo.Session)

Example 4 with HttpRequestResponseInfo

use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.

the class SessionManagerImpl method readFileAndPopulateRequestResponse.

private ArrayList<HttpRequestResponseInfo> readFileAndPopulateRequestResponse(Session session, ArrayList<HttpRequestResponseInfo> results, String filePath, PacketDirection packetDirection, HttpDirection httpDirection) throws IOException {
    String dataRead;
    long timeStamp = 0;
    HttpRequestResponseInfo rrInfo = null;
    int requestCount = 0;
    TreeMap<Double, PacketInfo> packetMap;
    BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
    Map<Double, PacketInfo> usedPackets = new HashMap<>();
    if (packetDirection == PacketDirection.UPLINK) {
        packetMap = new TreeMap<>(session.getAllPackets().stream().filter(packetInfo -> packetInfo.getDir().equals(PacketDirection.UPLINK)).collect(Collectors.toMap(PacketInfo::getTimeStamp, Function.identity(), (existing, replacement) -> existing)));
    } else {
        packetMap = new TreeMap<>(session.getAllPackets().stream().filter(packetInfo -> packetInfo.getDir().equals(PacketDirection.DOWNLINK)).collect(Collectors.toMap(PacketInfo::getTimeStamp, Function.identity(), (existing, replacement) -> existing)));
    }
    try {
        while ((dataRead = bufferedReader.readLine()) != null) {
            if (dataRead.length() > 0) {
                String comparisonString = "RequestTime: ";
                if (dataRead.startsWith(comparisonString)) {
                    ++requestCount;
                    timeStamp = Long.parseLong(dataRead.substring(comparisonString.length(), dataRead.length()));
                    continue;
                }
                rrInfo = initializeRequestResponseObject(dataRead, session, packetDirection);
                if (rrInfo != null) {
                    rrInfo.setTCP(true);
                    rrInfo.setRawSize(-1);
                    // Converting the System Time in Millis to Seconds and Microsecond format.
                    double time = ((double) timeStamp / 1000) + (((double) timeStamp % 1000) / 1000000.0);
                    // The math below allows the request time to have a start time relative to trace capture.
                    rrInfo.setTime(time - pcapTimeOffset);
                    // TODO: Will Review this after ARO22945-1645
                    if (packetMap.containsKey(rrInfo.getTime()) && !usedPackets.containsKey(rrInfo.getTime())) {
                        rrInfo.setFirstDataPacket(packetMap.get(rrInfo.getTime()));
                        usedPackets.put(rrInfo.getTime(), packetMap.get(rrInfo.getTime()));
                    } else {
                        Map.Entry<Double, PacketInfo> lowKey = packetMap.floorEntry(rrInfo.getTime());
                        Map.Entry<Double, PacketInfo> highKey = packetMap.ceilingEntry(rrInfo.getTime());
                        if (lowKey != null) {
                            setFirstAndLastDataPacket(results, usedPackets, rrInfo, packetMap, lowKey);
                        } else if (highKey != null) {
                            setFirstAndLastDataPacket(results, usedPackets, rrInfo, packetMap, highKey);
                        }
                    }
                    rrInfo.writeHeader(dataRead);
                    while ((dataRead = bufferedReader.readLine()) != null && dataRead.length() != 0) {
                        rrInfo.writeHeader(System.lineSeparator());
                        rrInfo.writeHeader(dataRead);
                        parseHeaderLine.parseHeaderLine(dataRead, rrInfo);
                    }
                    rrInfo.writeHeader(System.lineSeparator());
                    // Check for payload and read
                    File file = new File(filePath + "_" + requestCount);
                    if (file.exists()) {
                        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
                        rrInfo.writePayload(bis);
                        bis.close();
                    }
                    results.add(rrInfo);
                }
            }
        }
    } finally {
        bufferedReader.close();
    }
    return results;
}
Also used : UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) StringUtils(org.apache.commons.lang.StringUtils) BufferedInputStream(java.io.BufferedInputStream) IParseHeaderLine(com.att.aro.core.packetanalysis.IParseHeaderLine) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URISyntaxException(java.net.URISyntaxException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) HttpPattern(com.att.aro.core.packetanalysis.pojo.HttpPattern) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) Function(java.util.function.Function) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) RequestResponseTimeline(com.att.aro.core.packetanalysis.pojo.RequestResponseTimeline) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Logger(org.apache.log4j.Logger) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) DomainNameSystem(com.att.aro.core.packetreader.pojo.DomainNameSystem) Matcher(java.util.regex.Matcher) Packet(com.att.aro.core.packetreader.pojo.Packet) Map(java.util.Map) URI(java.net.URI) TcpInfo(com.att.aro.core.packetanalysis.pojo.TcpInfo) HttpDirection(com.att.aro.core.packetanalysis.pojo.HttpDirection) Util(com.att.aro.core.util.Util) Set(java.util.Set) Session(com.att.aro.core.packetanalysis.pojo.Session) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) ISessionManager(com.att.aro.core.packetanalysis.ISessionManager) IByteArrayLineReader(com.att.aro.core.packetanalysis.IByteArrayLineReader) List(java.util.List) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Termination(com.att.aro.core.packetanalysis.pojo.Termination) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) LogManager(org.apache.log4j.LogManager) PacketDirection(com.att.aro.core.packetreader.pojo.PacketDirection) Collections(java.util.Collections) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedReader(java.io.BufferedReader) PacketInfo(com.att.aro.core.packetanalysis.pojo.PacketInfo) FileReader(java.io.FileReader) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) File(java.io.File)

Example 5 with HttpRequestResponseInfo

use of com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo in project VideoOptimzer by attdevsupport.

the class SessionManagerImpl method extractHttpRequestResponseInfo.

private HttpRequestResponseInfo extractHttpRequestResponseInfo(ArrayList<HttpRequestResponseInfo> results, Session session, PacketInfo packetInfo, PacketDirection packetDirection, PacketInfo previousPacketInfo, int addToOffset) {
    TCPPacket tcpPacket = null;
    UDPPacket udpPacket = null;
    HttpRequestResponseInfo rrInfo = null;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    BufferedOutputStream bufferedStream = new BufferedOutputStream(stream);
    int carryoverPayloadLength = 0;
    if (packetInfo.getPacket() instanceof TCPPacket) {
        tcpPacket = (TCPPacket) packetInfo.getPacket();
        try {
            if (previousPacketInfo != null) {
                TCPPacket previousTCPPacket = (TCPPacket) previousPacketInfo.getPacket();
                carryoverPayloadLength = previousTCPPacket.getData().length - (previousTCPPacket.getDataOffset() + addToOffset);
                bufferedStream.write(previousTCPPacket.getData(), (previousTCPPacket.getDataOffset() + addToOffset), carryoverPayloadLength);
            }
            bufferedStream.write(tcpPacket.getData(), tcpPacket.getDataOffset(), tcpPacket.getData().length - tcpPacket.getDataOffset());
        } catch (Exception exception) {
            LOGGER.error("Error Reading Data from TCP Packet: ", exception);
        }
    } else {
        udpPacket = (UDPPacket) packetInfo.getPacket();
        try {
            if (previousPacketInfo != null) {
                UDPPacket previousUDPPacket = (UDPPacket) previousPacketInfo.getPacket();
                carryoverPayloadLength = previousUDPPacket.getData().length - (previousUDPPacket.getDataOffset() + addToOffset);
                bufferedStream.write(previousUDPPacket.getData(), (previousUDPPacket.getDataOffset() + addToOffset), carryoverPayloadLength);
            }
            bufferedStream.write(udpPacket.getData(), udpPacket.getDataOffset(), udpPacket.getData().length - udpPacket.getDataOffset());
        } catch (Exception exception) {
            LOGGER.error("Error Reading Data from UDP Packet: ", exception);
        }
    }
    try {
        bufferedStream.flush();
        byte[] streamArray = stream.toByteArray();
        storageReader.init(streamArray);
        return getLastRRInfo(streamArray, packetInfo, tcpPacket, previousPacketInfo, carryoverPayloadLength, session, results, packetDirection);
    } catch (IOException e) {
        LOGGER.error(e);
    }
    return rrInfo;
}
Also used : HttpRequestResponseInfo(com.att.aro.core.packetanalysis.pojo.HttpRequestResponseInfo) TCPPacket(com.att.aro.core.packetreader.pojo.TCPPacket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UDPPacket(com.att.aro.core.packetreader.pojo.UDPPacket) BufferedOutputStream(java.io.BufferedOutputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

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