Search in sources :

Example 6 with ConnectionFactory

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>
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ConnectionFactory(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionFactory) StringTokenizer(java.util.StringTokenizer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with ConnectionFactory

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());
}
Also used : ConnectionFactory(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionFactory)

Aggregations

ConnectionFactory (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionFactory)7 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Response (org.jboss.narayana.blacktie.jatmibroker.xatmi.Response)1 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1