Projects tigase _server server-core Issues #409
okResult does not include attributes from original XML element (#409)
Closed
Daniele Ricci opened 10 years ago
Due Date
2015-01-30

The okResult method does not consider the attributes from the original XML elements, it copies only the namespace:

Element tmp = new Element(old_child.getName());

tmp.setXMLNS(old_child.getXMLNS());
new_child.addChild(tmp);
new_child = tmp;

Is that the intended behavior or is it a bug?

Artur Hefczyc commented 10 years ago

This is not a bug. The API follows the specification which does not require OK result to include any additional payload. And there is an additional API which allows you to add payload to the okResult packet.

Daniele Ricci commented 10 years ago

Of course I assume that by "payload" you mean also attributes.

Which API is that? Do you mean the standard Element class with all the add* methods?

Eventually I ended up adding the additional attributes manually after ok packet creation.

Artur Hefczyc commented 10 years ago

Daniele Ricci wrote:

Of course I assume that by "payload" you mean also attributes.

Hm, I have re-read your post and comments and I think I understand what you mean. You probably have some custom attributes in the IQ stanza and you expect them to be copied in the "result" response send from the Tigase server. I still think the Tigase behavior is correct and it only copies attributes which are defined in the spec, that is stanza ID and form/to addresses and sets a correct type and xmlns.

I do not think it should copy any custom attributes. And to be honest, I think any custom information should not be carried out in a custom attributed. Instead a custom payload should be used. Then you have an option in the okResult API to include payload from the original IQ request.

Which API is that? Do you mean the standard Element class with all the add* methods?

Yes, I meant Element class API.

Eventually I ended up adding the additional attributes manually after ok packet creation.

Yes, this is what you are supposed to do and this is what I do in such a case.

Daniele Ricci commented 10 years ago

Artur Hefczyc wrote:

Daniele Ricci wrote:

Of course I assume that by "payload" you mean also attributes.

Hm, I have re-read your post and comments and I think I understand what you mean. You probably have some custom attributes in the IQ stanza and you expect them to be copied in the "result" response send from the Tigase server. I still think the Tigase behavior is correct and it only copies attributes which are defined in the spec, that is stanza ID and form/to addresses and sets a correct type and xmlns.

I do not think it should copy any custom attributes. And to be honest, I think any custom information should not be carried out in a custom attributed. Instead a custom payload should be used. Then you have an option in the okResult API to include payload from the original IQ request.

Indeed. The attribute I'm trying to copy is inside a custom child element (that is, the payload you talk about).

Artur Hefczyc commented 10 years ago

Than, the okResult API should be good enough for you. Please note the method comes with 2 parameters which allow you to include new XML payload into the result stanza and/or retain original payload from the IQ request.

Daniele Ricci commented 10 years ago

Artur Hefczyc wrote:

Than, the okResult API should be good enough for you. Please note the method comes with 2 parameters which allow you to include new XML payload into the result stanza and/or retain original payload from the IQ request.

Of course. That's what I've used: it correctly copies the payload elements, but without any attributes except for the namespace which is copied manually. Here is the class that does that:

https://github.com/kontalk/tigase-extension/blob/master/src/main/java/org/kontalk/xmppserver/KontalkLegacyFileUploadComponent.java#L64

The original stanza is an iq with a custom upload element (the custom payload). This custom element has an attribute called "node" which is not copied over by okResult.

Artur Hefczyc commented 10 years ago

Right, now I get it and indeed, you are correct. This is a bug.

For now, as a workaround, I suggest to use the first parameter to the method and submit the payload to send back with the result. The payload can be just a clone of the Element child.

Daniele Ricci commented 10 years ago

Ok, thank you.

wojciech.kapcia@tigase.net commented 10 years ago
  • all attributes are copied;

  • avoid NPE if depth parameter is greater than actual children depth;

  • unit-tests for .okResult() methods.

issue 1 of 1
Type
Bug
Priority
Normal
Assignee
RedmineID
2581
Spent time
19h 30m
Issue Votes (0)
Watchers (0)
Reference
tigase/_server/server-core#409
Please wait...
Page is in error, reload to recover