InvokerThread(Invocation invocation) {
_invocation = invocation;
}
public void run() {
final MyRoleMessageExchange mex;
final Future<MessageExchange.Status> running;
// Wait for it....
try {
Thread.sleep(_invocation.invokeDelayMs);
} catch (Exception ex) {
}
scheduler.begin();
try {
mex = _server.getEngine().createMessageExchange(new GUID().toString(), _invocation.target, _invocation.operation);
mexContext.clearCurrentResponse();
Message request = mex.createMessage(_invocation.requestType);
request.setMessage(_invocation.request);
_invocation.invokeTime = System.currentTimeMillis();
running = mex.invoke(request);
Status status = mex.getStatus();
CorrelationStatus cstatus = mex.getCorrelationStatus();
if (_invocation.expectedStatus != null && !status.equals(_invocation.expectedStatus))
failure(_invocation, "Unexpected message exchange status", _invocation.expectedStatus, status);
if (_invocation.expectedCorrelationStatus != null && !cstatus.equals(_invocation.expectedCorrelationStatus))
failure(_invocation, "Unexpected correlation status", _invocation.expectedCorrelationStatus, cstatus);
} catch (Exception ex) {
if (_invocation.expectedInvokeException == null)
failure(_invocation, "Unexpected invocation exception.", ex);
else if (_invocation.expectedInvokeException.isAssignableFrom(ex.getClass()))
failure(_invocation, "Unexpected invocation exception.", _invocation.expectedInvokeException, ex.getClass());
return;
} finally {
scheduler.commit();
}
if (isFailed())
return;
try {
running.get(_invocation.maximumWaitMs, TimeUnit.MILLISECONDS);
} catch (Exception ex) {
failure(_invocation, "Exception on future object.", ex);
return;
}
long ctime = System.currentTimeMillis();
long itime = ctime - _invocation.invokeTime;
if (_invocation.minimumWaitMs != null && _invocation.minimumWaitMs >= itime)
failure(_invocation, "Response received too soon.", _invocation.minimumWaitMs, itime);
if (_invocation.maximumWaitMs <= itime)
failure(_invocation, "Response took too long.", _invocation.maximumWaitMs, itime);
if (isFailed())
return;
scheduler.begin();
try {
Status finalstat = mex.getStatus();
if (_invocation.expectedFinalStatus != null && !_invocation.expectedFinalStatus.equals(finalstat))
if (finalstat.equals(Status.FAULT)) {
failure(_invocation, "Unexpected final message exchange status", _invocation.expectedFinalStatus, "FAULT: "
+ mex.getFault() + " | " + mex.getFaultExplanation());
} else {
failure(_invocation, "Unexpected final message exchange status", _invocation.expectedFinalStatus, finalstat);
}
if (_invocation.expectedFinalCorrelationStatus != null
&& !_invocation.expectedFinalCorrelationStatus.equals(mex.getCorrelationStatus())) {
failure(_invocation, "Unexpected final correlation status", _invocation.expectedFinalCorrelationStatus, mex
.getCorrelationStatus());
}
if (_invocation.expectedResponsePattern != null) {
if (mex.getResponse() == null)
failure(_invocation, "Expected response, but got none.", null);
String responseStr = DOMUtils.domToString(mex.getResponse().getMessage());
System.out.println("=>" + responseStr);
Matcher matcher = _invocation.expectedResponsePattern.matcher(responseStr);
if (!matcher.matches())
failure(_invocation, "Response does not match expected pattern", _invocation.expectedResponsePattern, responseStr);
}