Search in sources :

Example 26 with Response

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

Example 27 with Response

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>
}
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 28 with Response

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

Example 29 with Response

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

Example 30 with Response

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;
    }
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) Codec(org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec) Message(org.jboss.narayana.blacktie.jatmibroker.core.transport.Message) ResponseException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException) Receiver(org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver) CodecFactory(org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

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