Search in sources :

Example 26 with ConnectionException

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException 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 ConnectionException

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException in project narayana by jbosstm.

the class TransportImpl method createSender.

public Sender createSender(Object destination) throws ConnectionException {
    if (closed) {
        log.error("Already closed");
        throw new ConnectionException(Connection.TPEPROTO, "Already closed");
    }
    Sender sender;
    String callback_ior = (String) destination;
    log.debug("Creating a sender for: " + callback_ior);
    if (callback_ior.contains("IOR:")) {
        log.debug(callback_ior + " is for corba");
        throw new ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.Connection.TPESYSTEM, "Could not create a Corba sender");
    } else {
        log.debug(callback_ior + " is for socket");
        sender = new SocketSenderImpl(callback_ior);
    }
    log.debug("Created sender");
    return sender;
}
Also used : Sender(org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 28 with ConnectionException

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException in project narayana by jbosstm.

the class TransportImpl method getSender.

public Sender getSender(String serviceName, boolean conversational) throws ConnectionException {
    if (closed) {
        log.error("Already closed");
        throw new ConnectionException(Connection.TPEPROTO, "Already closed");
    }
    log.debug("Get sender: " + serviceName);
    Map<String, Sender> conversationalMap = senders.get(conversational);
    if (conversationalMap == null) {
        conversationalMap = new HashMap<String, Sender>();
        senders.put(conversational, conversationalMap);
    }
    Sender toReturn = conversationalMap.get(serviceName);
    if (toReturn == null) {
        try {
            String type = (String) properties.get("blacktie." + serviceName + ".type");
            toReturn = new StompSenderImpl(serviceName, conversational, type, conversationalMap, properties);
            conversationalMap.put(serviceName, toReturn);
        } catch (ConnectionException e) {
            throw e;
        } catch (Throwable t) {
            throw new ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.Connection.TPESYSTEM, "Could not create a service sender: " + t.getMessage(), t);
        }
    }
    return toReturn;
}
Also used : Sender(org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender) StompSenderImpl(org.jboss.narayana.blacktie.jatmibroker.core.transport.hybrid.stomp.StompSenderImpl) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 29 with ConnectionException

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException in project narayana by jbosstm.

the class StompSenderImpl method close.

/**
 * Don't want send and close at the same time
 */
public synchronized void close() throws ConnectionException {
    log.debug("Sender closing: " + destinationName);
    if (closed) {
        throw new ConnectionException(Connection.TPEPROTO, "Sender already closed");
    }
    closed = true;
    try {
        log.debug("closing socket: " + socket);
        StompManagement.close(socket, outputStream, inputStream);
        socket.close();
        log.debug("closed socket: " + socket);
        conversationalMap.remove(serviceName);
    } catch (Throwable t) {
        throw new ConnectionException(Connection.TPESYSTEM, "Could not send the message", t);
    }
}
Also used : ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 30 with ConnectionException

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException in project narayana by jbosstm.

the class BufferImpl method setAttributeValue.

/**
 * Set the value.
 *
 * @param key The key to set
 * @param type The type of the value.
 * @param value The value to use
 * @throws ConnectionException In case the message is not formatted.
 */
protected void setAttributeValue(String key, Class type, Object value) throws ConnectionException {
    if (!formatted) {
        throw new ConnectionException(ConnectionImpl.TPEPROTO, "Message not formatted");
    }
    int position = -1;
    for (int i = 0; i < keys.length; i++) {
        if (keys[i].equals(key)) {
            position = i;
        }
    }
    if (position == -1) {
        throw new ConnectionException(ConnectionImpl.TPEITYPE, "Key is not part of the structure: " + key);
    } else if (types[position] != type) {
        throw new ConnectionException(ConnectionImpl.TPEITYPE, "Key is not request type, it is a: " + types[position]);
    }
    structure.put(key, value);
}
Also used : ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Aggregations

ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)41 Response (org.jboss.narayana.blacktie.jatmibroker.xatmi.Response)12 ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)11 IOException (java.io.IOException)9 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)9 ResponseException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException)6 Message (org.jboss.narayana.blacktie.jatmibroker.core.transport.Message)5 Receiver (org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver)5 Buffer (org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer)5 CodecFactory (org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory)3 Codec (org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec)3 Transport (org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport)3 TransactionException (org.jboss.narayana.blacktie.jatmibroker.core.tx.TransactionException)3 SocketException (java.net.SocketException)2 HashMap (java.util.HashMap)2 StringTokenizer (java.util.StringTokenizer)2 ServiceData (org.jboss.narayana.blacktie.jatmibroker.core.server.ServiceData)2 Sender (org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1