diff --git a/src/main/java/com/salesforce/emp/connector/EmpConnector.java b/src/main/java/com/salesforce/emp/connector/EmpConnector.java index bd7412f..f6eb7f4 100644 --- a/src/main/java/com/salesforce/emp/connector/EmpConnector.java +++ b/src/main/java/com/salesforce/emp/connector/EmpConnector.java @@ -116,6 +116,8 @@ Future subscribe() { private Function bearerTokenProvider; private AtomicBoolean reauthenticate = new AtomicBoolean(false); + private LoggingExtension loggingExtension; + public EmpConnector(BayeuxParameters parameters) { this.parameters = parameters; httpClient = new HttpClient(parameters.sslContextFactory()); @@ -166,6 +168,10 @@ public void setBearerTokenProvider(Function bearerTokenProvider this.bearerTokenProvider = bearerTokenProvider; } + public void enableLoggingExtension() { + this.loggingExtension = new LoggingExtension(); + } + /** * Subscribe to a topic, receiving events after the replayFrom position * @@ -268,6 +274,10 @@ protected void customize(Request request) { client.addExtension(new ReplayExtension(replay)); + if (loggingExtension != null) { + client.addExtension(loggingExtension); + } + addListeners(client); client.handshake((c, m) -> { diff --git a/src/main/java/com/salesforce/emp/connector/LoggingExtension.java b/src/main/java/com/salesforce/emp/connector/LoggingExtension.java new file mode 100644 index 0000000..e28b0c8 --- /dev/null +++ b/src/main/java/com/salesforce/emp/connector/LoggingExtension.java @@ -0,0 +1,36 @@ +package com.salesforce.emp.connector; + +import org.cometd.bayeux.Message; +import org.cometd.bayeux.client.ClientSession; + +public class LoggingExtension implements ClientSession.Extension { + + @Override + public boolean rcv(ClientSession clientSession, Message.Mutable mutable) { + System.out.println("<<<<"); + System.out.println(mutable.getJSON()); + return true; + } + + @Override + public boolean rcvMeta(ClientSession clientSession, Message.Mutable mutable) { + System.out.println("<<<< Meta"); + System.out.println(mutable.getJSON()); + + return true; + } + + @Override + public boolean send(ClientSession clientSession, Message.Mutable mutable) { + System.out.println(">>>>"); + System.out.println(mutable.getJSON()); + return true; + } + + @Override + public boolean sendMeta(ClientSession clientSession, Message.Mutable mutable) { + System.out.println(">>>> Meta"); + System.out.println(mutable.getJSON()); + return true; + } +} diff --git a/src/main/java/com/salesforce/emp/connector/example/DevLoginExample.java b/src/main/java/com/salesforce/emp/connector/example/DevLoginExample.java index 665d60b..b39163f 100644 --- a/src/main/java/com/salesforce/emp/connector/example/DevLoginExample.java +++ b/src/main/java/com/salesforce/emp/connector/example/DevLoginExample.java @@ -57,6 +57,8 @@ public static void main(String[] argv) throws Throwable { connector.setBearerTokenProvider(tokenProvider); + connector.enableLoggingExtension(); + connector.start().get(5, TimeUnit.SECONDS); long replayFrom = EmpConnector.REPLAY_FROM_TIP;