use of org.jpos.transaction.Context in project jPOS by jpos.
the class HasEntry method select.
public String select(long id, Serializable ser) {
Context ctx = (Context) ser;
String name = cfg.get("name");
String action = ctx.get(name) != null ? YES : NO;
return cfg.get(action, UNKNOWN);
}
use of org.jpos.transaction.Context in project jPOS by jpos.
the class QueryHost method expired.
public void expired(Object handBack) {
Context ctx = (Context) handBack;
ctx.resume();
}
use of org.jpos.transaction.Context 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.transaction.Context in project jPOS by jpos.
the class SelectDestination method prepare.
@Override
public int prepare(long id, Serializable context) {
Context ctx = (Context) context;
ISOMsg m = (ISOMsg) ctx.get(requestName);
boolean destinationSet = false;
if (m != null && (m.hasField(2) || m.hasField(35))) {
try {
Card card = Card.builder().validator(validator).isomsg(m).build();
String destination = getDestination(card);
if (destination != null) {
ctx.put(destinationName, destination);
destinationSet = true;
}
} catch (InvalidCardException ex) {
return ctx.getResult().fail(CMF.INVALID_CARD_OR_CARDHOLDER_NUMBER, Caller.info(), ex.getMessage()).FAIL();
}
}
if (!destinationSet && ctx.get(destinationName) == null)
ctx.put(destinationName, defaultDestination);
if (failOnNoRoute && ctx.get(destinationName) == null)
return ctx.getResult().fail(CMF.ROUTING_ERROR, Caller.info(), "No routing info").FAIL();
return PREPARED | NO_JOIN | READONLY;
}
use of org.jpos.transaction.Context in project jPOS by jpos.
the class Trace method abort.
public void abort(long id, Serializable o) {
Context ctx = (Context) o;
ctx.checkPoint("abort:" + trace);
}
Aggregations