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);
}
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);
}
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;
}
}
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);
}
}
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);
}
Aggregations