Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Extension of Smack IQ package

2025-02-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

If we want to extend an IQ package like this:

Element

You need to define a custom IQ to extend:

Package com.emcc.stc.demo.iq;import org.jivesoftware.smack.packet.IQ;public class SampleIQ extends IQ {String condition; String value; protected SampleIQ (String childElementName, String childElementNamespace, String condition, String value) {super (childElementName, childElementNamespace); this.condition = condition; this.value = value The most critical implementation class * / @ Override protected IQChildElementXmlStringBuilder getIQChildElementBuilder (IQChildElementXmlStringBuilder xml) {xml.attribute ("condition", condition); xml.rightAngleBracket (); xml.element ("extraElement", "value"); return xml } public static void main (String [] args) {IQ iq = new SampleIQ ("query", "emcc.jiyq", "what", "elemeng"); System.out.println (iq.toXML ());}}

The advantage of this approach is that each IQ has a specific definition, each custom IQ class has its own application scenario, and there is no need to manually configure XML.

In addition, you can write a corresponding IQParser to parse specific types of IQ packages, which is more convenient to use.

Finally, the documentation of Smack is quite missing, and it is better to read the source code carefully for a lot of problems.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report