Search in sources :

Example 1 with Response

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.

the class TPCallXCTypeService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("test_tpcall_x_c_type_service");
    boolean ok = false;
    X_C_TYPE aptr = (X_C_TYPE) svcinfo.getBuffer();
    byte[] receivedName = new byte[3];
    byte[] charArray = aptr.getByteArray("name");
    System.arraycopy(charArray, 0, receivedName, 0, 3);
    byte[] expectedName = "TOM".getBytes();
    long accountNumber = aptr.getLong("acct_no");
    float fooOne = aptr.getFloatArray("foo")[0];
    float fooTwo = aptr.getFloatArray("foo")[1];
    double balanceOne = aptr.getDoubleArray("balances")[0];
    double balanceTwo = aptr.getDoubleArray("balances")[1];
    if (accountNumber == 12345678 && Arrays.equals(receivedName, expectedName) && fooOne == 1.1F && fooTwo == 2.2F && balanceOne == 1.1 && balanceTwo == 2.2) {
        ok = true;
    }
    int len = 60;
    X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
    if (ok) {
        toReturn.setByteArray("tpcall_x_c_type".getBytes());
    } else {
        toReturn.setByteArray("fail".getBytes());
    }
    return new Response(Connection.TPSUCCESS, 23, toReturn, 0);
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) X_C_TYPE(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_C_TYPE)

Example 2 with Response

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.

the class TPCallXOctetService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("test_tpcall_x_octet_service");
    boolean ok = false;
    if (svcinfo.getBuffer() != null) {
        byte[] received = ((X_OCTET) svcinfo.getBuffer()).getByteArray();
        byte[] expected = "test_tpcall_x_octet".getBytes();
        for (int i = 0; i < expected.length; i++) {
            if (expected[i] != received[i]) {
                ok = false;
                break;
            }
            ok = true;
        }
    // byte[] expected = new
    // byte["test_tpcall_x_octet".getBytes().length + 1];
    // System.arraycopy("test_tpcall_x_octet".getBytes(), 0, expected,
    // 0,
    // received.length - 1);
    // if (Arrays.equals(received, expected)) {
    // ok = true;
    // }
    }
    int len = 60;
    X_OCTET toReturn;
    toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
    if (ok) {
        toReturn.setByteArray("tpcall_x_octet".getBytes());
    } else {
        StringBuffer buffer = new StringBuffer("fail");
        if (svcinfo.getBuffer() != null) {
            buffer.append(new String(((X_OCTET) svcinfo.getBuffer()).getByteArray()));
        } else {
            buffer.append("dud");
        }
        toReturn.setByteArray("fail".getBytes());
    }
    return new Response(Connection.TPSUCCESS, 20, toReturn, 0);
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)

Example 3 with Response

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.

the class TPCancelService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("testtpcancel_service");
    if ((svcinfo.getFlags() & Connection.TPNOREPLY) != Connection.TPNOREPLY) {
        int len = 21;
        X_OCTET toReturn;
        String received = new String(((X_OCTET) svcinfo.getBuffer()).getByteArray());
        if (received.equals("cancel")) {
            toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
            toReturn.setByteArray("testtpcancel_service".getBytes());
            return new Response(Connection.TPSUCCESS, 0, toReturn, 0);
        } else {
            return new Response(Connection.TPFAIL, 1, null, 0);
        }
    } else {
        return null;
    }
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)

Example 4 with Response

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.

the class TPConversationService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("testTPConversation_service");
    boolean fail = false;
    if (TestTPConversation.strcmp((X_OCTET) svcinfo.getBuffer(), "conversate") != 0) {
        if (svcinfo.getBuffer() != null) {
            log.error("Got invalid data %s" + new String(((X_OCTET) svcinfo.getBuffer()).getByteArray()));
        } else {
            log.error("GOT A NULL");
        }
        fail = true;
    } else {
        long revent = 0;
        log.info("Chatting");
        for (int i = 0; i < TestTPConversation.interationCount; i++) {
            byte[] bytes = ("hi" + i).getBytes();
            X_OCTET sendbuf = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
            sendbuf.setByteArray(bytes);
            // btlogger((char*) "testTPConversation_service:%s:",
            // sendbuf);
            int result = svcinfo.getSession().tpsend(sendbuf, Connection.TPRECVONLY);
            if (result != -1) {
                try {
                    svcinfo.getSession().tprecv(0);
                    fail = true;
                    break;
                } catch (ResponseException e) {
                    if (e.getEvent() == Connection.TPEV_SENDONLY) {
                        Buffer rcvbuf = e.getReceived();
                        if (TestTPConversation.strcmp("yo" + i, rcvbuf) != 0) {
                            fail = true;
                            break;
                        }
                    } else {
                        fail = true;
                        break;
                    }
                } catch (ConnectionException e) {
                    fail = true;
                    break;
                }
            } else {
                fail = true;
                break;
            }
        }
        log.info("Chatted");
    }
    if (fail) {
        return new Response((short) Connection.TPESVCFAIL, 0, null, 0);
    } else {
        byte[] bytes = ("hi" + TestTPConversation.interationCount).getBytes();
        X_OCTET sendbuf = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
        sendbuf.setByteArray(bytes);
        return new Response(Connection.TPSUCCESS, 0, sendbuf, 0);
    }
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ResponseException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 5 with Response

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.

the class TPGetRplyService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("testtpgetrply_service");
    X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
    toReturn.setByteArray("testtpgetrply_service".getBytes());
    return new Response(Connection.TPSUCCESS, 0, toReturn, 0);
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)

Aggregations

Response (org.jboss.narayana.blacktie.jatmibroker.xatmi.Response)35 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)29 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)12 ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)8 StringTokenizer (java.util.StringTokenizer)3 X_C_TYPE (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_C_TYPE)3 IOException (java.io.IOException)2 List (java.util.List)2 Buffer (org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer)2 ResponseException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException)2 X_COMMON (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_COMMON)2 StringReader (java.io.StringReader)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 CodecFactory (org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory)1 Codec (org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec)1 Message (org.jboss.narayana.blacktie.jatmibroker.core.transport.Message)1 Receiver (org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver)1