use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class TestNBF method test_nbf.
public void test_nbf() throws ConnectionException, ConfigurationException {
log.info("test_nbf");
server.tpadvertiseTestNBF();
try {
BT_NBF buffer = (BT_NBF) connection.tpalloc("BT_NBF", "employee");
assertTrue(buffer.btaddattribute("name", "zhfeng"));
assertTrue(buffer.btaddattribute("id", new Long(1001)));
Response resp = connection.tpcall(RunServer.getServiceNameNBF(), buffer, 0);
assertTrue(resp != null);
BT_NBF rcvbuf = (BT_NBF) resp.getBuffer();
assertTrue(rcvbuf != null);
log.info(rcvbuf);
Long id = (Long) rcvbuf.btgetattribute("id", 0);
assertTrue(id.longValue() == 1234);
String name = (String) rcvbuf.btgetattribute("name", 0);
assertTrue(name == null);
} catch (ConnectionException e) {
log.warn("call service faild with " + e);
throw e;
}
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class CommandHandler method invoke.
public Object invoke(Object proxy, Method method, Object[] args) throws ConfigurationException, ConnectionException, CommandFailedException, ParserConfigurationException, SAXException, IOException {
if (connection == null) {
ConnectionFactory cf = ConnectionFactory.getConnectionFactory();
connection = cf.getConnection();
}
StringBuffer command = new StringBuffer(method.getName());
command.append(',');
if (args != null) {
for (int i = 0; i < args.length; i++) {
if (args[i] == null) {
args[i] = "";
}
command.append(args[i].toString());
command.append(',');
}
}
X_OCTET sendbuf = (X_OCTET) connection.tpalloc("X_OCTET", null);
sendbuf.setByteArray(command.toString().getBytes());
Response received = connection.tpcall("BTDomainAdmin", sendbuf, 0);
X_OCTET rcvbuf = (X_OCTET) received.getBuffer();
Class<?> returnType = method.getReturnType();
byte[] byteArray = rcvbuf.getByteArray();
;
if (returnType == Boolean.class) {
if (byteArray[0] == 1) {
return true;
} else {
return false;
}
} else if (returnType == Long.class) {
return convertLong(byteArray);
} else if (returnType == String.class) {
return new String(byteArray);
} else if (returnType == java.util.List.class) {
String listTerminator = BlacktieAdministration.LIST_TERMINATOR;
String string = new String(byteArray);
StringTokenizer outParameters = new StringTokenizer(string, "," + "", false);
if (!method.getName().equals("listRunningInstanceIds")) {
List<String> toReturn = new ArrayList<String>();
while (outParameters.hasMoreTokens()) {
String nextToken = outParameters.nextToken();
if (!nextToken.equals(listTerminator)) {
toReturn.add(nextToken);
}
}
return toReturn;
} else {
List<Integer> toReturn = new ArrayList<Integer>();
while (outParameters.hasMoreTokens()) {
String nextToken = outParameters.nextToken();
if (!nextToken.equals(listTerminator)) {
toReturn.add(Integer.parseInt(nextToken));
}
}
return toReturn;
}
} else if (returnType == org.w3c.dom.Element.class) {
StringReader sreader = new StringReader(new String(byteArray));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document doc = parser.parse(new InputSource(sreader));
return doc.getDocumentElement();
} else {
log.error("Could not handle response type: " + returnType);
throw new CommandFailedException(-1);
}
// java.util.List<Integer>
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class AdministrationTest method callAdmin.
private String callAdmin(String command, char expect) throws Exception {
int sendlen = command.length() + 1;
X_OCTET sendbuf = (X_OCTET) connection.tpalloc("X_OCTET", null);
sendbuf.setByteArray(command.getBytes());
Response buf = connection.tpcall(service, sendbuf, 0);
assertTrue(buf != null);
byte[] received = ((X_OCTET) buf.getBuffer()).getByteArray();
assertTrue(received[0] == expect);
return new String(received, 1, received.length - 1);
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class TPReturnTpurcodeService method tpservice.
public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
log.info("testtpreturn_service_tpurcode");
X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
toReturn.setByteArray(new byte[] { 0 });
if (TestTPConversation.strcmp(svcinfo.getBuffer(), "24") == 0) {
return new Response(Connection.TPSUCCESS, 24, toReturn, 0);
} else {
return new Response(Connection.TPSUCCESS, 77, toReturn, 0);
}
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class ConnectionImpl method receive.
/**
* Retrieve a response.
*
* @param cd
* The connection descriptor
* @param flags
* The flags to use
* @return The response
* @throws ConnectionException
* If the response cannot be retrieved.
* @throws ConfigurationException
*/
private Response receive(int cd, int flags) throws ConnectionException, ConfigurationException {
log.debug("receive: " + cd);
Receiver endpoint = temporaryQueues.get(cd);
if (endpoint == null) {
throw new ConnectionException(ConnectionImpl.TPEBADDESC, "Session does not exist: " + cd);
}
Message message = endpoint.receive(flags);
Buffer buffer = null;
if (message.type != null && !message.type.equals("")) {
CodecFactory factory = new CodecFactory(this);
String coding_type = properties.getProperty("blacktie." + message.serviceName + ".coding_type");
Codec codec = factory.getCodec(coding_type);
buffer = codec.decode(message.type, message.subtype, message.data, message.len);
// buffer = tpalloc(message.type, message.subtype, message.len);
// buffer.deserialize(message.data);
}
if (message.rval == ConnectionImpl.TPFAIL) {
if (message.rcode == ConnectionImpl.TPESVCERR) {
throw new ResponseException(ConnectionImpl.TPESVCERR, "Got an error back from the remote service", -1, message.rcode, buffer);
}
throw new ResponseException(ConnectionImpl.TPESVCFAIL, "Got a fail back from the remote service", -1, message.rcode, buffer);
} else {
Response response = new Response(cd, message.rval, message.rcode, buffer, message.flags);
log.debug("received returned a response? " + (response == null ? "false" : "true"));
return response;
}
}
Aggregations