@Override
    public void process(Exchange exchange) throws Exception {
        final String msg = exchange.getIn().getBody(String.class);
        final String sendTo = exchange.getIn().getHeader(IrcConstants.IRC_SEND_TO, String.class);

        if (connection == null || !connection.isConnected()) {
            reconnect();
        }
        if (connection == null || !connection.isConnected()) {
            throw new RuntimeCamelException("Lost connection" + (connection == null ? "" : " to " + connection.getHost()));
        }

        if (msg != null) {
            if (isMessageACommand(msg)) {
                LOG.debug("Sending command: {}", msg);
                connection.send(msg);
            } else if (sendTo != null) {
                LOG.debug("Sending to: {} message: {}", sendTo, msg);
                connection.doPrivmsg(sendTo, msg);
            } else {
                for (IrcChannel channel : getEndpoint().getConfiguration().getChannelList()) {
                    LOG.debug("Sending to: {} message: {}", channel, msg);
                    connection.doPrivmsg(channel.getName(), msg);
                }
            }
        }
    }
@Test
    public void processTest() throws Exception {

        when(connection.isConnected()).thenReturn(true);
        when(exchange.getIn()).thenReturn(message);
        when(message.getBody(String.class)).thenReturn("PART foo");
        when(message.getHeader(IrcConstants.IRC_SEND_TO, String.class)).thenReturn("bottest");

        producer.process(exchange);
        verify(connection).send("PART foo");

        when(message.getBody(String.class)).thenReturn("foo");

        producer.process(exchange);
        verify(connection).doPrivmsg("bottest", "foo");

        when(message.getHeader(IrcConstants.IRC_SEND_TO, String.class)).thenReturn(null);

        producer.process(exchange);
        verify(connection).doPrivmsg("#chan1", "foo");
        verify(connection).doPrivmsg("#chan2", "foo");
    }