Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.example.tcpclient;
- import org.apache.log4j.Logger;
- import org.springframework.integration.Message;
- import org.springframework.integration.MessageChannel;
- import org.springframework.integration.ip.tcp.connection.AbstractTcpConnectionInterceptor;
- import org.springframework.integration.ip.tcp.connection.TcpConnection;
- import org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptor;
- import org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactory;
- public class TcpClientInterceptorFactory implements TcpConnectionInterceptorFactory{
- private MessageChannel outputChannel;
- private static final Logger LOG = Logger.getLogger(TcpClientInterceptorFactory.class);
- public TcpConnectionInterceptor getInterceptor() {
- return new AbstractTcpConnectionInterceptor(){
- @Override
- public void send(Message<?> message) throws Exception {
- super.send(message);
- LOG.debug("Sent message [" + new String((byte[]) message.getPayload()) + "]");
- }
- @Override
- public void close() {
- super.close();
- LOG.debug("Closed connection");
- }
- @Override
- public void addNewConnection(TcpConnection connection) {
- super.addNewConnection(connection);
- LOG.debug("Added new connection" + connection.getHostName() + ":" + connection.getPort());
- }
- };
- }
- //---------------------------------------------------------
- // Accessors
- //---------------------------------------------------------
- public MessageChannel getOutputChannel() {
- return outputChannel;
- }
- public void setOutputChannel(MessageChannel outputChannel) {
- this.outputChannel = outputChannel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement