在Tomcat上记录HTTP和WebSocket

时间:2019-06-11 09:11:42

标签: java tomcat

我有一个运行在MyApp服务器上的Eclipse IDE中的简单应用程序TomCat

package server.ws;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;




@ServerEndpoint("/websocketendpoint")

public class WsServer {

    @OnOpen
    public void onOpen(){
        System.out.println("Open Connection ...");
    }

    @OnClose
    public void onClose(){
        System.out.println("Close Connection ...");
    }

    @OnMessage
    public String onMessage(String message){
        System.out.println("Message from the client: " + message);
        String echoMsg = "Echo from the server : " + message;
        return echoMsg;
    }

    @OnError
    public void onError(Throwable e){
        e.printStackTrace();
    }

}

如何在TomcatServer上启用日志记录所有请求和响应?

0 个答案:

没有答案