while (running) {
byte[] dataBlock;
IConnector connector = null;
try {
is.read(requestHeader, 0, SCPPacket.SIZE_OF_HEADER);
SCPPacket packet = new SCPPacket();
packet.setHeaderByte(requestHeader);
int size = packet.getSizeOfDatablock();
if (size > 0) {
dataBlock = new byte[size];
for (int i = 1; i < size; i++) {
dataBlock[i] = is.readByte();
}
} else {
dataBlock = new byte[0];
}
if (SCPPacket.KEEP_ALIVE
.equals(packet.getRequestTypeIdetifier())) {
KeepAliveMonitor.monit();
} else {
if (SCPPacket.HTTP_REQUEST_RESPONSE
.equals(packet.getRequestTypeIdetifier())) {
KeepAliveMonitor.monit();
connector = new HTTPConnector(dataBlock,
config.getWebServerURL(),
packet.getRequestIdetifier());
Thread t = new Thread(connector);
t.start();
} else if (SCPPacket.HTTPS_REQUEST_RESPONSE
.equals(packet.getRequestTypeIdetifier())) {
KeepAliveMonitor.monit();
Iterator it = httpsRequestsList.iterator();
// Serch for conection with id equals requestID
while (it.hasNext()) {
WorkConnectionThreads workThread;
connector = null;
workThread = (WorkConnectionThreads) it.next();
if (workThread.getRequestIdentifier() ==
packet.getRequestIdetifier()) {
connector = workThread.getConnector();
((HTTPSConnector) connector)
.setRequestData(dataBlock);
workThread.start();
}
}
// remove timeouted threads.
it = httpsRequestsList.iterator();
while (it.hasNext()) {
WorkConnectionThreads workThread =
(WorkConnectionThreads) it.next();
if (workThread.isTimeOuted() ||
!workThread.isConnected()) {
((HTTPSConnector) workThread.getConnector())
.close();
httpsRequestsList.remove(workThread);
}
}
// if not found then ceate new connection and run as
// thread
if (connector == null) {
try {
connector = new HTTPSConnector(dataBlock,
config.getWebServerURL(),
packet.getRequestIdetifier());
connector.setWriter(this.writer);
Thread t = new Thread(connector);
t.start();
httpsRequestsList
.add(new WorkConnectionThreads(t,