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

Emtpy messages received in client (through BasicCoapClientChannel) will provide ClassCastException #17

Open
GoogleCodeExporter opened this issue Aug 18, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Start from the CoapSampleResourceServer.java and BasicCoapClient.java 
examples given with this package
2. Modify the request in BasicCoapClient.java to request an observe message 
from the resource (i.e coapRequest.setObserveOption(0); 
coapRequest.setUriPath("/test/light"); ). See included file for details
3. Run first the server, then the client.

What is the expected output? What do you see instead?
The expected output is:
- An updated light value received whenever the value changes on the server side
What I see is:
- A ClassCastException:

Exception in thread "Thread-0" java.lang.ClassCastException: 
org.ws4d.coap.messages.CoapEmptyMessage cannot be cast to 
org.ws4d.coap.interfaces.CoapRequest
    at org.ws4d.coap.connection.BasicCoapClientChannel.sendMessage(BasicCoapClientChannel.java:140)
    at org.ws4d.coap.connection.BasicCoapClientChannel.handleMessage(BasicCoapClientChannel.java:74)
    at org.ws4d.coap.connection.BasicCoapSocketHandler$WorkerThread.handleIncommingMessage(BasicCoapSocketHandler.java:272)
    at org.ws4d.coap.connection.BasicCoapSocketHandler$WorkerThread.run(BasicCoapSocketHandler.java:155)

What version of the product are you using? On what operating system?
Coap source checkout:
Commit: 020caefedb4c135829f550c803deebceb29f740f [020caef]
Parents: 789c5c0959
Author: Christian <[email protected]>
Date: Tuesday, 12 June, 2012 11:06:01
Labels: HEAD, origin/master, origin/HEAD, master

OS: Windows 8.1 Enterprise

Please provide any additional information below.
The bug can be fixed by adding a check for CoapRequest format, i.e in 
BasicCoapClientChannel.java change the sendMessage function:

    @Override
    public void sendMessage(CoapMessage msg) {
        super.sendMessage(msg);
        //TODO: check
        if(msg instanceof CoapRequest){
            lastRequest = (CoapRequest) msg;
        }
    }

I suppose this is why the "//TODO: check" was here

Original issue reported on code.google.com by [email protected] on 26 May 2015 at 8:08

Attachments:

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

No branches or pull requests

1 participant