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 with a Communicator.EventHandler.receivedMessage(Object input) logger #93

Open
artado opened this issue Jan 23, 2019 · 3 comments
Open

Comments

@artado
Copy link

@artado artado commented Jan 23, 2019

Hello,

I believe there is an issue with a Communicator.EventHandler.receivedMessage(Object input) when it tries to logger.trace("Receive a message: {}", message) for a JSON message.

        public void receivedMessage(Object input) {
            Message message = parse(input);
            if (message != null) {
                Object payload = message.getPayload();
                if (payload instanceof Document) {
                    logger.trace("Receive a message: {}", SugarUtil.docToString((Document) payload));
                } else {
                    logger.trace("Receive a message: {}", message);
                }
            }
            if (message instanceof CallResultMessage) {
                events.onCallResult(message.getId(), message.getAction(), message.getPayload());
            } else if (message instanceof CallErrorMessage) {
                failedFlag = true;
                CallErrorMessage call = (CallErrorMessage) message;
                events.onError(call.getId(), call.getErrorCode(), call.getErrorDescription(), call.getRawPayload());
            } else if (message instanceof CallMessage) {
                CallMessage call = (CallMessage) message;
                events.onCall(call.getId(), call.getAction(), call.getPayload());
            }
        }

What I`m getting in a log console is:

FINEST [03:19:20 23-Jan-19 PST][eu.chargetime.ocpp.Communicator] Receive a message: eu.chargetime.ocpp.model.CallMessage@9023eb

While in a Wireshark I can see:

[2, "69015629", "Heartbeat", {}]

Could it be something to do with a missing .toString() method for a Message class?

@TVolden
Copy link
Member

@TVolden TVolden commented Jan 24, 2019

Hi @artado,

Thanks for your input.

My guess is, that there isn't any ToString() on the CallMessage class. It would be a good idea to implement one.

In unrelated news, I see there is a lower level check on the data type, and then a downcast. I'll mark it in my black book of technical debt. :)

@dersteve
Copy link

@dersteve dersteve commented Jan 24, 2019

@TVolden or we create a separate issue as 'good first issue' for the data type check?

@TVolden
Copy link
Member

@TVolden TVolden commented Jan 24, 2019

Good idea @dersteve

I'm thinking we could solve it using a double dispatch method, like visitor pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.