Search in sources :

Example 1 with Context

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);
}
Also used : Context(org.jpos.transaction.Context)

Example 2 with Context

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();
}
Also used : Context(org.jpos.transaction.Context)

Example 3 with Context

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();
    }
}
Also used : Context(org.jpos.transaction.Context) Chronometer(org.jpos.util.Chronometer) Result(org.jpos.rc.Result)

Example 4 with Context

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;
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg)

Example 5 with Context

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);
}
Also used : Context(org.jpos.transaction.Context)

Aggregations

Context (org.jpos.transaction.Context)45 Test (org.junit.Test)29 Result (org.jpos.rc.Result)26 ISOMsg (org.jpos.iso.ISOMsg)20 Date (java.util.Date)5 ISODate (org.jpos.iso.ISODate)3 SpaceSource (org.jpos.space.SpaceSource)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Element (org.jdom2.Element)1 Configurable (org.jpos.core.Configurable)1 Configuration (org.jpos.core.Configuration)1 ConfigurationException (org.jpos.core.ConfigurationException)1 ISOAmount (org.jpos.iso.ISOAmount)1 ISOSource (org.jpos.iso.ISOSource)1 LocalSpace (org.jpos.space.LocalSpace)1 Space (org.jpos.space.Space)1 SpaceFactory (org.jpos.space.SpaceFactory)1