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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations