Advertisement
olegtikhonov

TcpClientInterceptorFactory.java

Apr 1st, 2013
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14.  
  15.  
  16. package org.example.tcpclient;
  17.  
  18. import org.apache.log4j.Logger;
  19. import org.springframework.integration.Message;
  20. import org.springframework.integration.MessageChannel;
  21. import org.springframework.integration.ip.tcp.connection.AbstractTcpConnectionInterceptor;
  22. import org.springframework.integration.ip.tcp.connection.TcpConnection;
  23. import org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptor;
  24. import org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactory;
  25.  
  26.  
  27. public class TcpClientInterceptorFactory implements TcpConnectionInterceptorFactory{
  28.  
  29. private MessageChannel outputChannel;
  30. private static final Logger LOG = Logger.getLogger(TcpClientInterceptorFactory.class);
  31.  
  32.  
  33. public TcpConnectionInterceptor getInterceptor() {
  34. return new AbstractTcpConnectionInterceptor(){
  35. @Override
  36. public void send(Message<?> message) throws Exception {
  37. super.send(message);
  38. LOG.debug("Sent message [" + new String((byte[]) message.getPayload()) + "]");
  39. }
  40.  
  41.  
  42. @Override
  43. public void close() {
  44. super.close();
  45. LOG.debug("Closed connection");
  46. }
  47.  
  48. @Override
  49. public void addNewConnection(TcpConnection connection) {
  50. super.addNewConnection(connection);
  51. LOG.debug("Added new connection" + connection.getHostName() + ":" + connection.getPort());
  52. }
  53. };
  54. }
  55.  
  56.  
  57.  
  58. //---------------------------------------------------------
  59. // Accessors
  60. //---------------------------------------------------------
  61.  
  62. public MessageChannel getOutputChannel() {
  63. return outputChannel;
  64. }
  65.  
  66.  
  67. public void setOutputChannel(MessageChannel outputChannel) {
  68. this.outputChannel = outputChannel;
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement