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

Possible bug in exposing WoT formats attribute #364

Closed
SteinerPascal opened this issue Dec 8, 2020 · 6 comments
Closed

Possible bug in exposing WoT formats attribute #364

SteinerPascal opened this issue Dec 8, 2020 · 6 comments

Comments

@SteinerPascal
Copy link

I was following the starter template. I created my own thing and serving it worked well. You can find it on gist. Except, that the forms attribute of my action has changed. It got changed to some apparently standard forms attribute. The console output was the following:

"actions":{"takePhoto":{"title":"takePhoto","description":"description","input":{"unit":"","type":"string"},"forms":[{"href":"http://192.168.8.128:8080/KWH2/actions/takePhoto","contentType":"application/json","op":["invokeaction"],"htv:methodName":"POST"}],"idempotent":false,"safe":false}},


the contentType of my action got changed from image/jpeg to application/json. I tracked the issue down a bit and figured out it happens when i call exposedthing.expose() . More detailed in getServient().expose(_this)
https://github.com/eclipse/thingweb.node-wot/blob/6854ab79022a7c71ee627a6f77a23e0eaaa9d702/packages/core/src/exposed-thing.ts#L99
At this point the _thing still contains the proper form attribute with the image/jpeg.
But then in Servient.expose() Line 133 you are going to overwrite it.
https://github.com/eclipse/thingweb.node-wot/blob/6854ab79022a7c71ee627a6f77a23e0eaaa9d702/packages/core/src/servient.ts#L115-L137
Is this behavior wanted or is this a bug?

@egekorkan
Copy link
Member

This is not a bug but not really wanted either. The "TD" is accepted to a certain degree. You can specify some content types in forms and jpeg is not supported. href is always overwritten since it depends on the available IP addresses and security also depends on internal logic.

@SteinerPascal
Copy link
Author

Thanks for the quick reply! Okay I thought support for image/jpeg got implemented and merged with #187 ? Regarding the IP, I understand the behavior.

@egekorkan
Copy link
Member

There only png and svg got incorporated :)

@SteinerPascal
Copy link
Author

SteinerPascal commented Dec 9, 2020

okay thanks for the info. One last question though. It seems you have already done a beginning in supporting jpeg (see below base64 codec which implements the necessary interface and lists "image/jpeg")
https://github.com/eclipse/thingweb.node-wot/blob/45d8fa739cb6e796c2ee38bf156a977c4f0739bf/packages/core/src/content-serdes.ts#L58-L61
What would be missing to add it?

Update: It doesn't seem to work with "image/png" either.

@danielpeintner
Copy link
Member

I think generally it should just work fine. We do have running examples on http://plugfest.thingweb.io/

E.g., the counter example has a simple

A simple GET on http://plugfest.thingweb.io:8083/counter/properties/redDotImage returns a PNG image (a red dot only)

The code for it is here, https://github.com/eclipse/thingweb.node-wot/blob/master/packages/examples/src/scripts/counter.ts

The following lines show how it is setup
https://github.com/eclipse/thingweb.node-wot/blob/6854ab79022a7c71ee627a6f77a23e0eaaa9d702/packages/examples/src/scripts/counter.ts#L71-L78
and
https://github.com/eclipse/thingweb.node-wot/blob/6854ab79022a7c71ee627a6f77a23e0eaaa9d702/packages/examples/src/scripts/counter.ts#L157
shows what the handler does.

The only obvious difference I see is property vs. action. I did try a simple change (see attached file counter.zip) and for me it works.

        takePhoto: {
            description: "Take photo",
            forms: [{
                    contentType: "image/png"
                }],
        }
thing.setActionHandler("takePhoto", async (params, options) => "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");

@SteinerPascal
Copy link
Author

Okay that's my bad. tested it again and it's because of the npm versions. It's working with the latest version 0.7.4 . I didn't update the dependency and was using the version in the template which is at 0.7.0-SNAPSHOT.3. So before #187 got merged into main
But thank you for the help and quick answers!

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

No branches or pull requests

3 participants