Hi everyone, I have a strange problem with the duration time of http request
operation. I'm using HttpClient to invoking external http service.
This is the code:
public void onMessageExchange(MessageExchange exchange) throws
MessagingException {
if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
NormalizedMessage inMessage = exchange.getMessage("in");
HttpClient httpClient = new HttpClient();
PostMethod method = new PostMethod(locationURI);
String request;
try {
request = new
SourceTransformer().toString(inMessage.getContent());
method.setRequestEntity(new StringRequestEntity(request,
"text/xml", "utf-8"));
long before = System.currentTimeMillis();
httpClient.executeMethod(method);
long after = System.currentTimeMillis();
String response = method.getResponseBodyAsString();
// creating out message
NormalizedMessage outMessage = exchange.createMessage();
outMessage.setContent(new StringSource(response));
long timing = after - before;
if (timing < 0) {
LOG.error("==================== THIS SHOULD NOT BE
HAPPEND ===========================");
}
exchange.setMessage(outMessage, "out");
} catch (Exception ex) {
Fault fault = exchange.createFault();
fault.setContent(new StringSource(ex.toString()));
exchange.setFault(fault);
} finally {
method.releaseConnection();
}
channel.send(exchange);
}
}
The problem is, sometime before is grater then after. I've tried to replace
System.currentTimeMillis() to joda time (org.joda.time.DateTime), and
StopWatch class (org.apache.commons.lang.time.StopWatch), but this not help.
Please help, I don't know where could be the problem?
Best regards,
razu