Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #5193 - Adding more WebSocket EventDriver logging #5202

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Objects;

import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
Expand All @@ -42,7 +43,7 @@
*/
public abstract class AbstractEventDriver extends AbstractLifeCycle implements IncomingFrames, EventDriver
{
private static final Logger LOG = Log.getLogger(AbstractEventDriver.class);
private final Logger logger;
protected final Logger targetLog;
protected WebSocketPolicy policy;
protected final Object websocket;
Expand All @@ -51,8 +52,9 @@ public abstract class AbstractEventDriver extends AbstractLifeCycle implements I

public AbstractEventDriver(WebSocketPolicy policy, Object websocket)
{
this.logger = Log.getLogger(this.getClass());
this.policy = policy;
this.websocket = websocket;
this.websocket = Objects.requireNonNull(websocket, "WebSocket endpoint may not be null");
this.targetLog = Log.getLogger(websocket.getClass());
}

Expand Down Expand Up @@ -87,9 +89,9 @@ public WebSocketSession getSession()
@Override
public void incomingFrame(Frame frame)
{
if (LOG.isDebugEnabled())
if (logger.isDebugEnabled())
{
LOG.debug("incomingFrame({})", frame);
logger.debug("incomingFrame({})", frame);
}

try
Expand All @@ -112,9 +114,9 @@ public void incomingFrame(Frame frame)
}
case OpCode.PING:
{
if (LOG.isDebugEnabled())
if (logger.isDebugEnabled())
{
LOG.debug("PING: {}", BufferUtil.toDetailString(frame.getPayload()));
logger.debug("PING: {}", BufferUtil.toDetailString(frame.getPayload()));
}
ByteBuffer pongBuf;
if (frame.hasPayload())
Expand All @@ -133,9 +135,9 @@ public void incomingFrame(Frame frame)
}
case OpCode.PONG:
{
if (LOG.isDebugEnabled())
if (logger.isDebugEnabled())
{
LOG.debug("PONG: {}", BufferUtil.toDetailString(frame.getPayload()));
logger.debug("PONG: {}", BufferUtil.toDetailString(frame.getPayload()));
}
onPong(frame.getPayload());
break;
Expand All @@ -157,8 +159,8 @@ public void incomingFrame(Frame frame)
}
default:
{
if (LOG.isDebugEnabled())
LOG.debug("Unhandled OpCode: {}", opcode);
if (logger.isDebugEnabled())
logger.debug("Unhandled OpCode: {}", opcode);
}
}
}
Expand Down Expand Up @@ -202,10 +204,9 @@ public BatchMode getBatchMode()
@Override
public void openSession(WebSocketSession session)
{
if (LOG.isDebugEnabled())
if (logger.isDebugEnabled())
{
LOG.debug("openSession({})", session);
LOG.debug("objectFactory={}", session.getContainerScope().getObjectFactory());
logger.debug("openSession({}) objectFactory={}", session, session.getContainerScope().getObjectFactory());
}
this.session = session;
this.session.getContainerScope().getObjectFactory().decorate(this.websocket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.io.InputStream;
import java.io.Reader;
import java.nio.ByteBuffer;
import java.util.Objects;

import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.BatchMode;
Expand All @@ -36,6 +38,7 @@
import org.eclipse.jetty.websocket.common.message.NullMessage;
import org.eclipse.jetty.websocket.common.message.SimpleBinaryMessage;
import org.eclipse.jetty.websocket.common.message.SimpleTextMessage;
import org.eclipse.jetty.websocket.common.util.TextUtil;

/**
* Handler for Annotated User WebSocket objects.
Expand All @@ -50,7 +53,7 @@ public class JettyAnnotatedEventDriver extends AbstractEventDriver
public JettyAnnotatedEventDriver(WebSocketPolicy policy, Object websocket, JettyAnnotatedMetadata events)
{
super(policy, websocket);
this.events = events;
this.events = Objects.requireNonNull(events, "JettyAnnotatedMetadata may not be null");

WebSocket anno = websocket.getClass().getAnnotation(WebSocket.class);
// Setup the policy
Expand All @@ -71,6 +74,11 @@ public JettyAnnotatedEventDriver(WebSocketPolicy policy, Object websocket, Jetty
this.policy.setIdleTimeout(anno.maxIdleTime());
}
this.batchMode = anno.batchMode();

if (LOG.isDebugEnabled())
{
LOG.debug("ctor / object={}, policy={}, batchMode={}, events={}", websocket, policy, batchMode, events);
}
}

@Override
Expand All @@ -82,6 +90,12 @@ public BatchMode getBatchMode()
@Override
public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException
{
if (LOG.isDebugEnabled())
{
LOG.debug("onBinaryFrame({}, {}) - events.onBinary={}, activeMessage={}",
BufferUtil.toDetailString(buffer), fin, events.onBinary, activeMessage);
}

if (events.onBinary == null)
{
// not interested in binary events
Expand Down Expand Up @@ -126,6 +140,11 @@ public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException
@Override
public void onBinaryMessage(byte[] data)
{
if (LOG.isDebugEnabled())
{
LOG.debug("onBinaryMessage([{}]) - events.onBinary={}", data.length, events.onBinary);
}

if (events.onBinary != null)
{
events.onBinary.call(websocket, session, data, 0, data.length);
Expand All @@ -141,6 +160,12 @@ public void onClose(CloseInfo close)
return;
}
hasCloseBeenCalled = true;

if (LOG.isDebugEnabled())
{
LOG.debug("onClose({}) - events.onClose={}", close, events.onClose);
}

if (events.onClose != null)
{
events.onClose.call(websocket, session, close.getStatusCode(), close.getReason());
Expand All @@ -150,6 +175,11 @@ public void onClose(CloseInfo close)
@Override
public void onConnect()
{
if (LOG.isDebugEnabled())
{
LOG.debug("onConnect() - events.onConnect={}", events.onConnect);
}

if (events.onConnect != null)
{
events.onConnect.call(websocket, session);
Expand All @@ -159,6 +189,11 @@ public void onConnect()
@Override
public void onError(Throwable cause)
{
if (LOG.isDebugEnabled())
{
LOG.debug("onError({}) - events.onError={}", cause.getClass().getName(), events.onError);
}

if (events.onError != null)
{
events.onError.call(websocket, session, cause);
Expand All @@ -172,6 +207,11 @@ public void onError(Throwable cause)
@Override
public void onFrame(Frame frame)
{
if (LOG.isDebugEnabled())
{
LOG.debug("onFrame({}) - events.onFrame={}", frame, events.onFrame);
}

if (events.onFrame != null)
{
events.onFrame.call(websocket, session, frame);
Expand All @@ -181,6 +221,13 @@ public void onFrame(Frame frame)
@Override
public void onInputStream(InputStream stream)
{
Objects.requireNonNull(stream, "InputStream may not be null");

if (LOG.isDebugEnabled())
{
LOG.debug("onInputStream({}) - events.onBinary={}", stream.getClass().getName(), events.onBinary);
}

if (events.onBinary != null)
{
events.onBinary.call(websocket, session, stream);
Expand All @@ -190,6 +237,13 @@ public void onInputStream(InputStream stream)
@Override
public void onReader(Reader reader)
{
Objects.requireNonNull(reader, "Reader may not be null");

if (LOG.isDebugEnabled())
{
LOG.debug("onReader({}) - events.onText={}", reader.getClass().getName(), events.onText);
}

if (events.onText != null)
{
events.onText.call(websocket, session, reader);
Expand All @@ -199,6 +253,12 @@ public void onReader(Reader reader)
@Override
public void onTextFrame(ByteBuffer buffer, boolean fin) throws IOException
{
if (LOG.isDebugEnabled())
{
LOG.debug("onTextFrame({}, {}) - events.onText={}, activeMessage={}",
BufferUtil.toDetailString(buffer), fin, events.onText, activeMessage);
}

if (events.onText == null)
{
// not interested in text events
Expand Down Expand Up @@ -243,6 +303,12 @@ public void onTextFrame(ByteBuffer buffer, boolean fin) throws IOException
@Override
public void onTextMessage(String message)
{
if (LOG.isDebugEnabled())
{
LOG.debug("onTextMessage([{}] \"{}\") - events.onText={}",
message.length(), TextUtil.maxStringLength(60, message), events.onText);
}

if (events.onText != null)
{
events.onText.call(websocket, session, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,36 @@
public class JettyAnnotatedMetadata
{
/**
* @OnWebSocketConnect ()
* {@code @OnWebSocketConnect ()}
*/
public CallableMethod onConnect;
/**
* @OnWebSocketMessage (byte[], or ByteBuffer, or InputStream)
* {@code @OnWebSocketMessage (byte[], or ByteBuffer, or InputStream)}
*/
public OptionalSessionCallableMethod onBinary;
/**
* @OnWebSocketMessage (String, or Reader)
* {@code @OnWebSocketMessage (String, or Reader)}
*/
public OptionalSessionCallableMethod onText;
/**
* @OnWebSocketFrame (Frame)
* {@code @OnWebSocketFrame (Frame)}
*/
public OptionalSessionCallableMethod onFrame;
/**
* @OnWebSocketError (Throwable)
* {@code @OnWebSocketError (Throwable)}
*/
public OptionalSessionCallableMethod onError;
/**
* @OnWebSocketClose (Frame)
* {@code @OnWebSocketClose (Frame)}
*/
public OptionalSessionCallableMethod onClose;

@Override
public String toString()
{
StringBuilder s = new StringBuilder();
s.append("JettyPojoMetadata[");
s.append(this.getClass().getSimpleName());
s.append("[");
s.append("onConnect=").append(onConnect);
s.append(",onBinary=").append(onBinary);
s.append(",onText=").append(onText);
Expand Down
Loading