use of org.jpos.rc.Result in project jPOS by jpos.
the class Context method getResult.
/**
* return (or creates) a Resultr object
* @return Profiler object
*/
public synchronized Result getResult() {
Result result = (Result) get(RESULT.toString());
if (result == null) {
result = new Result();
put(RESULT.toString(), result);
}
return result;
}
use of org.jpos.rc.Result in project jPOS by jpos.
the class QueryHost method prepare.
public int prepare(long id, Serializable ser) {
Context ctx = (Context) ser;
Result result = ctx.getResult();
String ds = ctx.getString(destination);
if (ds == null) {
return result.fail(CMF.MISCONFIGURED_ENDPOINT, Caller.info(), "'%s' not present in Context", destination).FAIL();
}
String muxName = cfg.get("mux." + ds, "mux." + ds);
MUX mux = (MUX) NameRegistrar.getIfExists(muxName);
if (mux == null)
return result.fail(CMF.MISCONFIGURED_ENDPOINT, Caller.info(), "MUX '%s' not found", muxName).FAIL();
ISOMsg m = (ISOMsg) ctx.get(requestName);
if (m == null)
return result.fail(CMF.INVALID_REQUEST, Caller.info(), "'%s' is null", requestName).FAIL();
Chronometer chronometer = new Chronometer();
if (isConnected(mux)) {
// give at least a second to catch a response
long t = Math.max(timeout - chronometer.elapsed(), 1000L);
try {
if (continuations) {
mux.request(m, t, this, ctx);
return PREPARED | READONLY | PAUSE | NO_JOIN;
} else {
ISOMsg resp = mux.request(m, t);
if (resp != null) {
ctx.put(responseName, resp);
return PREPARED | READONLY | NO_JOIN;
} else {
return result.fail(CMF.HOST_UNREACHABLE, Caller.info(), "'%s' does not respond", muxName).FAIL();
}
}
} catch (ISOException e) {
return result.fail(CMF.SYSTEM_ERROR, Caller.info(), e.getMessage()).FAIL();
}
} else {
return result.fail(CMF.HOST_UNREACHABLE, Caller.info(), "'%s' is not connected", muxName).FAIL();
}
}
use of org.jpos.rc.Result in project jPOS by jpos.
the class CheckFieldsTest method testMidAndTidWithSpaces.
@Test
public void testMidAndTidWithSpaces() {
Context ctx = new Context();
ISOMsg m = new ISOMsg();
m.set(41, "0001 ");
m.set(42, "0000000001 ");
ctx.put(ContextConstants.REQUEST.toString(), m);
cfg.put("mandatory", "MID, TID");
int action = cf.prepare(1L, ctx);
assertEquals(PREPARED | NO_JOIN | READONLY, action);
Result rc = ctx.getResult();
assertFalse(rc.hasFailures());
}
use of org.jpos.rc.Result in project jPOS by jpos.
the class CheckFieldsTest method testValidTimestamps.
@Test
public void testValidTimestamps() {
Date now = new Date();
Context ctx = new Context();
ISOMsg m = new ISOMsg();
m.set(7, ISODate.getDateTime(now));
m.set(12, ISODate.getDateTime(now));
ctx.put(ContextConstants.REQUEST.toString(), m);
cfg.put("mandatory", "7 12");
int action = cf.prepare(1L, ctx);
assertEquals(PREPARED | NO_JOIN | READONLY, action);
Result rc = ctx.getResult();
assertFalse(rc.hasInfo());
assertFalse(rc.hasWarnings());
assertFalse(rc.hasFailures());
}
use of org.jpos.rc.Result in project jPOS by jpos.
the class CheckFieldsTest method testInvalidTransaction.
@Test
public void testInvalidTransaction() {
Context ctx = new Context();
int action = cf.prepare(1L, ctx);
assertEquals("Action should be ABORTED|NO_JOIN|READONLY", ABORTED | NO_JOIN | READONLY, action);
Result rc = ctx.getResult();
assertTrue("RC should have failures", rc.hasFailures());
assertEquals("IRC should be INVALID_TRANSACTION", CMF.INVALID_TRANSACTION, rc.failure().getIrc());
}
Aggregations