return "" + reqCode.charAt(0) + numericPart + reqCode.substring(CODE_LENGTH);
}
protected String send (String request) throws HostException {
Timer totalTimer = new Timer();
totalTimer.start();
Timer sendTimer = new Timer();
sendTimer.start();
Timer receiveTimer = new Timer();
String response = null;
boolean tooLongAlreadyDumped = false;
try {
CGISocket socket = createSocket();
try {
socket.setTimeout(timeout);
request = transformRequest(request);
socket.write(request);
sendTimer.stop();
logger.finer(sendTimer.ellapsed(), "[SENT] {" + request + "} (len=" + request.length() + ")");
receiveTimer.start();
response = socket.read();
response = transformResponse(response);
receiveTimer.stop();
} finally {
socket.close();
totalTimer.stop();
}
} catch (InterruptedIOException e) {
logger.error(e);
// s� mostra o erro se a mensagem n�o tiver dados confidenciais (ex: login)
logger.error(sendTimer.ellapsed(), "[SENT] {" + request + "} (len=" + request.length() + ")");
if (response != null && logger.getLevel().getLevel() < Level.FINER.getLevel()) {
receiveTimer.stop();
totalTimer.stop();
if (threshold > 0 && !tooLongAlreadyDumped && totalTimer.ellapsed() > threshold){
logger.push("too long");
tooLongAlreadyDumped = true;
}
logger.error(receiveTimer.ellapsed(), "[RCVD] {" + response + "} (len=" + response.length() + ")");
}
throw new HostUnavailableSystemException("SISTEMA CENTRAL INDISPONIVEL! ERRO COMUNICACOES! TIMEOUT!");
} catch (Exception e) {
logger.error(e);
// s� mostra o erro se a mensagem n�o tiver dados confidenciais (ex: login)
logger.error(sendTimer.ellapsed(), "[SENT] {" + request + "}");
if (response != null && logger.getLevel().getLevel() < Level.FINER.getLevel()) {
receiveTimer.stop();
totalTimer.stop();
if (threshold > 0 && !tooLongAlreadyDumped && totalTimer.ellapsed() > threshold){
logger.push("too long");
tooLongAlreadyDumped = true;
}
logger.error(receiveTimer.ellapsed(), "[RCVD] {" + response + "}");
}
throw new HostUnavailableSystemException("SISTEMA CENTRAL INDISPONIVEL! ERRO COMUNICACOES!");
}
if (threshold > 0 && !tooLongAlreadyDumped && totalTimer.ellapsed() > threshold){
logger.push("too long");
tooLongAlreadyDumped = true;
}
logger.finer(receiveTimer.ellapsed(), "[RCVD] {" + response + "} (len=" + response.length() + ")");
return response;
}