use of com.att.aro.core.packetanalysis.pojo.HttpDirection 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.HttpDirection in project VideoOptimzer by attdevsupport.
the class SessionManagerImpl method getLastRRInfo.
private HttpRequestResponseInfo getLastRRInfo(byte[] streamArray, PacketInfo packetInfo, TCPPacket tcpPacket, PacketInfo previousPacket, int carryoverPayloadLength, Session session, List<HttpRequestResponseInfo> results, PacketDirection packetDirection) {
HttpRequestResponseInfo rrInfo = null;
String line = null;
int readerIndex = -1;
boolean carryoverPayloadForNewRRInfo = false;
int remainingLength = 0;
try {
do {
while (true) {
readerIndex = storageReader.getIndex();
line = storageReader.readLine();
if (line == null) {
return rrInfo;
}
if (line.length() != 0) {
break;
}
}
rrInfo = initializeRequestResponseObject(line, session, packetDirection);
if (rrInfo == null || tcpPacket == null) {
break;
}
carryoverPayloadForNewRRInfo = false;
rrInfo.setTCP(true);
rrInfo = populateRRInfo(session, tcpPacket, rrInfo);
boolean isExtractable, isTCP;
isExtractable = isTCP = session.isUdpOnly() ? false : true;
HttpDirection direction = PacketDirection.DOWNLINK.equals(packetDirection) ? HttpDirection.RESPONSE : HttpDirection.REQUEST;
// Set first and last packet info data to rrInfo
if (previousPacket == null || readerIndex >= carryoverPayloadLength) {
populateRRInfo(rrInfo, packetInfo, isExtractable, isTCP, direction);
} else {
populateRRInfo(rrInfo, previousPacket, isExtractable, isTCP, direction);
}
if (!rrInfo.isHeaderParseComplete()) {
return rrInfo;
} else {
results.add(rrInfo);
rrInfo.getHeaderData().write(streamArray, 0, storageReader.getIndex());
remainingLength = streamArray.length - storageReader.getIndex();
if (remainingLength <= 0) {
return rrInfo;
}
if (rrInfo.getContentLength() > 0) {
if (rrInfo.getContentLength() <= remainingLength) {
rrInfo.getPayloadData().write(streamArray, storageReader.getIndex(), rrInfo.getContentLength());
storageReader.setArrayIndex(storageReader.getIndex() + rrInfo.getContentLength());
remainingLength = streamArray.length - storageReader.getIndex();
if (remainingLength <= 0) {
return rrInfo;
}
// We have found the whole payload data for the current rrInfo. There's still remaining data which belongs to a new rrInfo object.
// Continue processing for the next rrInfo object.
carryoverPayloadForNewRRInfo = true;
} else {
rrInfo.getPayloadData().write(streamArray, storageReader.getIndex(), remainingLength);
return rrInfo;
}
} else {
// We are not sure if content length is explicitly 0 in the response or if it is a set by default during the initialization of object.
// Try to create a new rrInfo object for next line.
carryoverPayloadForNewRRInfo = true;
}
}
} while (true);
} catch (Exception e) {
LOGGER.error("Error extracting request response object for packet id " + packetInfo.getPacketId() + " and session port " + session.getLocalPort(), e);
}
// We have a carry over payload data belonging to previous rrInfo object
if (tcpPacket != null && carryoverPayloadForNewRRInfo && remainingLength > 0) {
rrInfo = results.get(results.size() - 1);
rrInfo.getPayloadData().write(streamArray, readerIndex, remainingLength);
}
return rrInfo;
}
Aggregations