Polished and use netty helper to write to channel.

git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x@1395050 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
index 5685318..5819f6f 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyHelper.java
@@ -86,8 +86,14 @@
         // the write operation is asynchronous. Use future to wait until the session has been written
         ChannelFuture future;
         if (remoteAddress != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Writing to channel: {} remote address: {} with body: {}", new Object[]{channel, remoteAddress, body});
+            }
             future = channel.write(body, remoteAddress);
         } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Writing to channel: {} with body: {}", new Object[]{channel, body});
+            }
             future = channel.write(body);
         }
 
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
index 46ed76e..51d5b1f0 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyProducer.java
@@ -186,15 +186,10 @@
             return true;
         }
 
-        // log what we are writing
-        LOG.debug("Writing body: {}", body);
-        // write the body asynchronously
-        ChannelFuture future = channel.write(body);
-
-        // add listener which handles the operation
-        future.addListener(new ChannelFutureListener() {
+        // write body
+        NettyHelper.writeBodyAsync(channel, null, body, exchange, new ChannelFutureListener() {
             public void operationComplete(ChannelFuture channelFuture) throws Exception {
-                LOG.debug("Operation complete {}", channelFuture);
+                LOG.trace("Operation complete {}", channelFuture);
                 if (!channelFuture.isSuccess()) {
                     // no success the set the caused exception and signal callback and break
                     exchange.setException(channelFuture.getCause());
@@ -219,8 +214,8 @@
                             disconnect = close;
                         }
                         if (disconnect) {
-                            if (LOG.isDebugEnabled()) {
-                                LOG.debug("Closing channel when complete at address: {}", getEndpoint().getConfiguration().getAddress());
+                            if (LOG.isTraceEnabled()) {
+                                LOG.trace("Closing channel when complete at address: {}", getEndpoint().getConfiguration().getAddress());
                             }
                             NettyHelper.close(channel);
                         }
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
index f157edf..b92ca01 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
@@ -117,7 +117,9 @@
         AsyncCallback callback = getAsyncCallback(ctx);
 
         Object body = messageEvent.getMessage();
-        LOG.debug("Message received: {}", body);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Receiving from channel: {} body: {}", new Object[]{messageEvent.getChannel(), body});
+        }
 
         // if textline enabled then covert to a String which must be used for textline
         if (producer.getConfiguration().isTextline()) {
@@ -152,8 +154,8 @@
                 disconnect = close;
             }
             if (disconnect) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing channel when complete at address: {}", producer.getConfiguration().getAddress());
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing channel when complete at address: {}", producer.getConfiguration().getAddress());
                 }
                 NettyHelper.close(ctx.getChannel());
             }
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
index 8301368..f50ace8 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
@@ -54,14 +54,18 @@
 
     @Override
     public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
-        LOG.trace("Channel open: {}", e.getChannel());
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Channel open: {}", e.getChannel());
+        }
         // to keep track of open sockets
         consumer.getAllChannels().add(e.getChannel());
     }
 
     @Override
     public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
-        LOG.trace("Channel closed: {}", e.getChannel());
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Channel closed: {}", e.getChannel());
+        }
     }
 
     @Override
@@ -78,7 +82,9 @@
     @Override
     public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent messageEvent) throws Exception {
         Object in = messageEvent.getMessage();
-        LOG.debug("Incoming message: {}", in);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Receiving from channel: {} body: {}", new Object[]{messageEvent.getChannel(), in});
+        }
 
         // create Exchange and let the consumer process it
         final Exchange exchange = consumer.getEndpoint().createExchange(ctx, messageEvent);
@@ -148,8 +154,8 @@
             if (consumer.getConfiguration().isDisconnectOnNoReply()) {
                 // must close session if no data to write otherwise client will never receive a response
                 // and wait forever (if not timing out)
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing channel as no payload to send as reply at address: {}", messageEvent.getRemoteAddress());
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing channel as no payload to send as reply at address: {}", messageEvent.getRemoteAddress());
                 }
                 NettyHelper.close(messageEvent.getChannel());
             }
@@ -160,7 +166,6 @@
             }
 
             // we got a body to write
-            LOG.debug("Writing body: {}", body);
             ChannelFutureListener listener = new ResponseFutureListener(exchange, messageEvent.getRemoteAddress());
             if (consumer.getConfiguration().isTcp()) {
                 NettyHelper.writeBodyAsync(messageEvent.getChannel(), null, body, exchange, listener);
@@ -206,8 +211,8 @@
                 disconnect = close;
             }
             if (disconnect) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing channel when complete at address: {}", remoteAddress);
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Closing channel when complete at address: {}", remoteAddress);
                 }
                 NettyHelper.close(future.getChannel());
             }