use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionFactory 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.ConnectionFactory in project narayana by jbosstm.
the class TestRollbackOnly method setUp.
public void setUp() throws ConnectionException, ConfigurationException {
server.serverinit();
ConnectionFactory connectionFactory = ConnectionFactory.getConnectionFactory();
connection = connectionFactory.getConnection();
sendlen = "TestRbkOnly".length() + 1;
sendbuf = (X_OCTET) connection.tpalloc("X_OCTET", null);
sendbuf.setByteArray("TestRbkOnly".getBytes());
}
Aggregations