├── .gitignore ├── LICENSE ├── README.md ├── Screenshots └── mina.gif ├── pom.xml └── src └── main ├── java └── net │ └── aimeizi │ └── mina │ └── examples │ ├── handler │ ├── Command.java │ ├── HelloClientHandler.java │ ├── HelloServerHandler.java │ └── Message.java │ ├── spring │ └── MinaSpringMain.java │ ├── tcp │ ├── HelloTcpClient.java │ └── HelloTcpServer.java │ └── udp │ ├── HelloUdpClient.java │ └── HelloUdpServer.java └── resources ├── applicationContext.xml └── log4j.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .classpath 3 | .project 4 | .settings 5 | target 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.jar 12 | *.war 13 | *.ear 14 | 15 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 16 | hs_err_pid* 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 雪山飞鹄 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mina-examples 2 | 3 | 4 | 一个简单的spring整合mina实例。分别介绍了TCP和UDP的用法。同时与Spring4.1.X进行了整合。 5 | 6 | 7 | # useage 8 | 9 | Tcp:首先运行HelloTcpServer,接着在运行HelloTcpClient。在HelloTcpClient的控制台输入消息内容,观察服务端返回的应答。 10 | 11 | Udp:首先运行HelloUdpServer,接着在运行HelloUdpClient。在HelloUdpClient的控制台输入消息内容,观察服务端返回的应答。 12 | 13 | Spring: 首先运行MinaSpringMain,接着运行HelloTcpClient或HelloUdpClient。在HelloTcpClient或HelloUdpClient的控制台输入消息内容,观察服务端返回的应答。 14 | 15 | 16 | # Screenshots 17 | 18 | ![](Screenshots/mina.gif) 19 | 20 | -------------------------------------------------------------------------------- /Screenshots/mina.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v5tech/mina-examples/300b6078ee379dfd1b5b00b0cf27748ad66752d4/Screenshots/mina.gif -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | net.aimeizi 6 | mina-examples 7 | 1.0 8 | jar 9 | 10 | mina-examples 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.apache.mina 21 | mina-core 22 | 2.0.9 23 | 24 | 25 | org.apache.mina 26 | mina-integration-beans 27 | 2.0.9 28 | 29 | 30 | org.apache.mina 31 | mina-integration-jmx 32 | 2.0.9 33 | 34 | 35 | org.springframework 36 | spring-context 37 | 4.1.2.RELEASE 38 | 39 | 40 | org.slf4j 41 | slf4j-log4j12 42 | 1.7.7 43 | 44 | 45 | junit 46 | junit 47 | 4.11 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.apache.felix 57 | maven-bundle-plugin 58 | true 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/handler/Command.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.handler; 2 | 3 | public class Command { 4 | public static final int LOGIN = 0; 5 | 6 | public static final int QUIT = 1; 7 | 8 | public static final int BROADCAST = 2; 9 | 10 | private final int num; 11 | 12 | private Command(int num) { 13 | this.num = num; 14 | } 15 | 16 | public int toInt() { 17 | return num; 18 | } 19 | 20 | public static Command valueOf(String s) { 21 | s = s.toUpperCase(); 22 | if ("LOGIN".equals(s)) { 23 | return new Command(LOGIN); 24 | } 25 | if ("QUIT".equals(s)) { 26 | return new Command(QUIT); 27 | } 28 | if ("BROADCAST".equals(s)) { 29 | return new Command(BROADCAST); 30 | } 31 | 32 | throw new IllegalArgumentException("Unrecognized command: " + s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/handler/HelloClientHandler.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.handler; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | import java.util.Scanner; 6 | 7 | import org.apache.mina.core.service.IoHandler; 8 | import org.apache.mina.core.session.IdleStatus; 9 | import org.apache.mina.core.session.IoSession; 10 | 11 | /** 12 | * 客户端消息处理类 13 | * @author welcome 14 | * 15 | */ 16 | public class HelloClientHandler implements IoHandler { 17 | 18 | public void exceptionCaught(IoSession session, Throwable cause) 19 | throws Exception { 20 | // cause.printStackTrace(); 21 | } 22 | 23 | public void inputClosed(IoSession session) throws Exception { 24 | 25 | } 26 | 27 | /** 28 | * 处理从服务端或控制台输入的消息 29 | */ 30 | public void messageReceived(IoSession session, Object message) throws Exception { 31 | 32 | if(message!=null){//接受服务端返回的消息 33 | Date date = new Date(); 34 | String printmsg = ""; 35 | if(message instanceof Message){ 36 | Message msg = (Message) message; 37 | int command = msg.getCommand(); 38 | switch (command) { 39 | case Command.QUIT://处理服务端返回的退出消息 40 | session.close(true); 41 | System.exit(0);//退出客户端 42 | break; 43 | default: 44 | System.out.println("服务器已抽风...."); 45 | break; 46 | } 47 | printmsg = "服务端应答:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) +" "+msg.getMsgContent(); 48 | }else{ 49 | printmsg = "服务端应答:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) +" "+message.toString(); 50 | } 51 | System.out.println(printmsg); 52 | } 53 | 54 | //从控制台接受输入 55 | Scanner scanner = new Scanner(System.in); 56 | if(scanner.hasNext()){ 57 | String in = scanner.next(); 58 | Message msg = new Message(); 59 | msg.setId(session.getId()); 60 | msg.setUser("admin"); 61 | if(in.equalsIgnoreCase("quit")){ 62 | msg.setMsgContent(in);//接受用户从控制台的输入 63 | msg.setCommand(Command.QUIT); 64 | }else{ 65 | msg.setMsgContent(in);//接受用户从控制台的输入 66 | msg.setCommand(Command.BROADCAST); 67 | } 68 | session.write(msg); 69 | } 70 | 71 | } 72 | 73 | public void messageSent(IoSession session, Object message) throws Exception { 74 | } 75 | 76 | public void sessionClosed(IoSession session) throws Exception { 77 | 78 | } 79 | 80 | //创建会话 81 | public void sessionCreated(IoSession session) throws Exception { 82 | 83 | } 84 | 85 | public void sessionIdle(IoSession session, IdleStatus status) throws Exception { 86 | } 87 | 88 | //会话建立并打开时调用。第一次建立连接的时候 89 | public void sessionOpened(IoSession session) throws Exception { 90 | Message message = new Message(); 91 | message.setId(session.getId()); 92 | message.setUser("admin"); 93 | message.setMsgContent("客户:"+message.getUser()+"已连接!"); 94 | message.setCommand(Command.LOGIN); 95 | session.write(message); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/handler/HelloServerHandler.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.handler; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Collections; 5 | import java.util.Date; 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | import org.apache.mina.core.service.IoHandler; 10 | import org.apache.mina.core.session.IdleStatus; 11 | import org.apache.mina.core.session.IoSession; 12 | import org.apache.mina.filter.logging.MdcInjectionFilter; 13 | 14 | /** 15 | * 服务端消息处理类 16 | * @author welcome 17 | * 18 | */ 19 | public class HelloServerHandler implements IoHandler { 20 | 21 | //保存所有客户端已连接的会话 22 | private final Set sessions = Collections.synchronizedSet(new HashSet()); 23 | 24 | //保存已连接的客户端 25 | private final Set users = Collections.synchronizedSet(new HashSet()); 26 | 27 | public void exceptionCaught(IoSession session, Throwable cause) 28 | throws Exception { 29 | // cause.printStackTrace(); 30 | } 31 | 32 | public void inputClosed(IoSession session) throws Exception { 33 | 34 | } 35 | 36 | public void messageReceived(IoSession session, Object message) throws Exception { 37 | Message msg = (Message)message; 38 | int command = msg.getCommand(); 39 | String user = msg.getUser(); 40 | switch (command) { 41 | case Command.QUIT: 42 | session.write(msg); 43 | sessionClosed(session); 44 | break; 45 | case Command.BROADCAST: 46 | Date date = new Date(); 47 | broadCast(user + " " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) +" "+msg.getMsgContent());//发送广播 48 | break; 49 | case Command.LOGIN: 50 | //保存当前会话 51 | sessions.add(session); 52 | session.setAttribute("user", user); 53 | MdcInjectionFilter.setProperty(session, "user", user); 54 | users.add(user); 55 | broadCast("用户:"+user+"加入了会话!");//发送广播 56 | break; 57 | default: 58 | broadCast("阁下莫非来自外太空?地球很危险,快回火星去吧!");//发送广播 59 | break; 60 | } 61 | } 62 | 63 | public void messageSent(IoSession session, Object message) throws Exception { 64 | } 65 | 66 | public void sessionClosed(IoSession session) throws Exception { 67 | String user = (String) session.getAttribute("user"); 68 | users.remove(user);//移除用户 69 | sessions.remove(session);//移除会话 70 | broadCast("用户" + user + "离开了会话."); 71 | } 72 | 73 | public void sessionCreated(IoSession session) throws Exception { 74 | 75 | } 76 | 77 | public void sessionIdle(IoSession session, IdleStatus status) throws Exception { 78 | } 79 | 80 | public void sessionOpened(IoSession session) throws Exception { 81 | 82 | } 83 | 84 | /** 85 | * 广播到所有的会话 86 | * @param message 87 | */ 88 | public void broadCast(String message) { 89 | synchronized (sessions) { 90 | for (IoSession session : sessions) { 91 | if (session.isConnected()) { 92 | session.write(message); 93 | } 94 | } 95 | } 96 | } 97 | 98 | /** 99 | * 返回已连接的客户端总数 100 | * @return 101 | */ 102 | public int getNumberOfUsers(){ 103 | return users.size(); 104 | } 105 | 106 | /** 107 | * 把客户踢出会话 108 | * @param client 109 | */ 110 | public void kick(String name) { 111 | synchronized (sessions) { 112 | for (IoSession session : sessions) { 113 | if (name.equals(session.getAttribute("user"))) { 114 | // Message msg = new Message(); 115 | // msg.setId(session.getId()); 116 | // msg.setUser("admin"); 117 | // msg.setMsgContent("用户" + name + "被踢出会话."); 118 | // msg.setCommand(Command.QUIT); 119 | // session.write(msg); 120 | broadCast("用户" + name + "被踢出会话."); 121 | break; 122 | } 123 | } 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/handler/Message.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.handler; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 封装消息实体类 7 | * @author welcome 8 | * 9 | */ 10 | public class Message implements Serializable{ 11 | 12 | private static final long serialVersionUID = -2587568580316224999L; 13 | 14 | private long id; 15 | private String msgContent; 16 | private String user; 17 | private int command; 18 | 19 | public Message() { 20 | } 21 | 22 | public Message(long id, String msgContent, String user, int command) { 23 | super(); 24 | this.id = id; 25 | this.msgContent = msgContent; 26 | this.user = user; 27 | this.command = command; 28 | } 29 | 30 | public long getId() { 31 | return id; 32 | } 33 | public void setId(long id) { 34 | this.id = id; 35 | } 36 | public String getMsgContent() { 37 | return msgContent; 38 | } 39 | public void setMsgContent(String msgContent) { 40 | this.msgContent = msgContent; 41 | } 42 | public String getUser() { 43 | return user; 44 | } 45 | public void setUser(String user) { 46 | this.user = user; 47 | } 48 | public int getCommand() { 49 | return command; 50 | } 51 | public void setCommand(int command) { 52 | this.command = command; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/spring/MinaSpringMain.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.spring; 2 | 3 | import org.springframework.context.support.ClassPathXmlApplicationContext; 4 | import org.springframework.context.ConfigurableApplicationContext; 5 | 6 | public class MinaSpringMain { 7 | 8 | public static void main(String[] args) throws Exception { 9 | if (System.getProperty("com.sun.management.jmxremote") != null) { 10 | System.out.println("JMX enabled."); 11 | } else { 12 | System.out.println("JMX disabled. Please set the " 13 | + "'com.sun.management.jmxremote' system property to enable JMX."); 14 | } 15 | getApplicationContext(); 16 | System.out.println("Listening ..."); 17 | } 18 | 19 | public static ConfigurableApplicationContext getApplicationContext() { 20 | return new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/tcp/HelloTcpClient.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.tcp; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import net.aimeizi.mina.examples.handler.HelloClientHandler; 6 | 7 | import org.apache.mina.core.RuntimeIoException; 8 | import org.apache.mina.core.future.ConnectFuture; 9 | import org.apache.mina.core.session.IoSession; 10 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 11 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 12 | import org.apache.mina.filter.logging.LoggingFilter; 13 | import org.apache.mina.filter.logging.MdcInjectionFilter; 14 | import org.apache.mina.transport.socket.nio.NioSocketConnector; 15 | 16 | /** 17 | * 基于Tcp的Client 18 | * @author welcome 19 | * 20 | */ 21 | public class HelloTcpClient { 22 | 23 | private static final String HOSTNAME = "127.0.0.1"; 24 | private static final int PORT = 9898; 25 | 26 | public static void main(String[] args) { 27 | NioSocketConnector connector = new NioSocketConnector(); //TCP Connector 28 | connector.getFilterChain().addLast("logging", new LoggingFilter()); 29 | connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); 30 | connector.getFilterChain().addLast("mdc", new MdcInjectionFilter()); 31 | connector.setHandler(new HelloClientHandler()); 32 | IoSession session; 33 | 34 | for (;;) { 35 | try { 36 | ConnectFuture future = connector.connect(new InetSocketAddress(HOSTNAME, PORT)); 37 | future.awaitUninterruptibly(); 38 | session = future.getSession(); 39 | break; 40 | } catch (RuntimeIoException e) { 41 | System.err.println("Failed to connect."); 42 | e.printStackTrace(); 43 | } 44 | } 45 | session.getCloseFuture().awaitUninterruptibly(); 46 | connector.dispose(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/tcp/HelloTcpServer.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.tcp; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import net.aimeizi.mina.examples.handler.HelloServerHandler; 6 | 7 | import org.apache.mina.core.service.IoAcceptor; 8 | import org.apache.mina.core.session.IdleStatus; 9 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 10 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 11 | import org.apache.mina.filter.logging.LoggingFilter; 12 | import org.apache.mina.filter.logging.MdcInjectionFilter; 13 | import org.apache.mina.transport.socket.nio.NioSocketAcceptor; 14 | 15 | /** 16 | * 基于Tcp的服务端 17 | * @author welcome 18 | * 19 | */ 20 | public class HelloTcpServer { 21 | 22 | private static final int PORT = 9898; 23 | 24 | public static void main(String[] args) throws Exception { 25 | IoAcceptor acceptor = new NioSocketAcceptor(); //TCP Acceptor 26 | acceptor.getFilterChain().addLast("logging", new LoggingFilter()); 27 | acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); 28 | acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter()); 29 | acceptor.setHandler(new HelloServerHandler()); 30 | acceptor.getSessionConfig().setReadBufferSize(2048); 31 | acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); 32 | acceptor.bind(new InetSocketAddress(PORT)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/udp/HelloUdpClient.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.udp; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import net.aimeizi.mina.examples.handler.HelloClientHandler; 6 | 7 | import org.apache.mina.core.future.ConnectFuture; 8 | import org.apache.mina.core.future.IoFuture; 9 | import org.apache.mina.core.future.IoFutureListener; 10 | import org.apache.mina.core.session.IoSession; 11 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 12 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 13 | import org.apache.mina.filter.logging.LoggingFilter; 14 | import org.apache.mina.filter.logging.MdcInjectionFilter; 15 | import org.apache.mina.transport.socket.nio.NioDatagramConnector; 16 | 17 | /** 18 | * 基于Udp客户端 19 | * @author welcome 20 | * 21 | */ 22 | public class HelloUdpClient { 23 | 24 | private static final String HOSTNAME = "127.0.0.1"; 25 | private static final int PORT = 9898; 26 | 27 | public static void main(String[] args) { 28 | NioDatagramConnector connector = new NioDatagramConnector();//UDP Connector 29 | connector.getFilterChain().addLast("logging", new LoggingFilter()); 30 | connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); 31 | connector.getFilterChain().addLast("mdc", new MdcInjectionFilter()); 32 | connector.setHandler(new HelloClientHandler()); 33 | ConnectFuture connFuture = connector.connect(new InetSocketAddress(HOSTNAME, PORT)); 34 | for ( ; ; ) { 35 | try { 36 | connFuture.addListener(new IoFutureListener() { 37 | IoSession session; 38 | public void operationComplete(IoFuture future) { 39 | ConnectFuture connFuture = (ConnectFuture)future; 40 | if(connFuture.isConnected()){ 41 | session = future.getSession(); 42 | } else { 43 | System.out.println("Not connected...exiting"); 44 | } 45 | } 46 | }); 47 | } catch (Exception e) { 48 | System.err.println("Failed to connect."); 49 | e.printStackTrace(); 50 | } 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/aimeizi/mina/examples/udp/HelloUdpServer.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.mina.examples.udp; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import net.aimeizi.mina.examples.handler.HelloServerHandler; 6 | 7 | import org.apache.mina.core.session.IdleStatus; 8 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 9 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 10 | import org.apache.mina.filter.logging.LoggingFilter; 11 | import org.apache.mina.filter.logging.MdcInjectionFilter; 12 | import org.apache.mina.transport.socket.DatagramSessionConfig; 13 | import org.apache.mina.transport.socket.nio.NioDatagramAcceptor; 14 | 15 | /** 16 | * 基于Udp的服务端 17 | * @author welcome 18 | * 19 | */ 20 | public class HelloUdpServer { 21 | 22 | private static final int PORT = 9898; 23 | 24 | public static void main(String[] args) throws Exception { 25 | NioDatagramAcceptor acceptor = new NioDatagramAcceptor();//UDP Acceptor 26 | acceptor.getFilterChain().addLast("logging", new LoggingFilter()); 27 | acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); 28 | acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter()); 29 | acceptor.setHandler(new HelloServerHandler()); 30 | acceptor.getSessionConfig().setReadBufferSize(2048); 31 | acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); 32 | DatagramSessionConfig dcfg = acceptor.getSessionConfig(); 33 | dcfg.setReuseAddress(true); 34 | acceptor.bind(new InetSocketAddress(PORT)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | ############################################################################# 17 | # Please don't modify the log level until we reach to acceptable test coverage. 18 | # It's very useful when I test examples manually. 19 | log4j.rootCategory=INFO, stdout 20 | 21 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 22 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 23 | #log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n 24 | 25 | # you could use this pattern to test the MDC with the Chat server 26 | log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %t %p %X{name} [%X{user}] [%X{remoteAddress}] [%c] - %m%n --------------------------------------------------------------------------------