Search in sources :

Example 1 with Result

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

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

Example 3 with Result

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

Example 4 with Result

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());
}
Also used : Context(org.jpos.transaction.Context) ISOMsg(org.jpos.iso.ISOMsg) Date(java.util.Date) ISODate(org.jpos.iso.ISODate) Result(org.jpos.rc.Result) Test(org.junit.Test)

Example 5 with Result

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

Aggregations

Result (org.jpos.rc.Result)27 Context (org.jpos.transaction.Context)26 Test (org.junit.Test)24 ISOMsg (org.jpos.iso.ISOMsg)17 Date (java.util.Date)3 ISODate (org.jpos.iso.ISODate)3 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 ISOAmount (org.jpos.iso.ISOAmount)1 Chronometer (org.jpos.util.Chronometer)1