Quantcast
Channel: Ignite Realtime : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 10742

Problems with new IQ-API in 4.1.0-alpha7-SNAPSHOT

$
0
0

I have found a solution to make Smack full OSGi-compliant with minimum interference. I am currently migrating my code to 4.1.0-alpha7-SNAPSHOT, but I am confronted with a serious problem concerning the new IQ-API. I am using JAXB and put an extension to my IQs. At the moment I cannot find a possibility to create an IQ without defining the child element. It is part of the extension itself provided by JAXB. If I pass the child element name of the extension via the constructor the extension gets enclosed twice which breaks everything. Is there a way to return the whole extension as a valid XML string? This is my old code from 4.0.5 which did the job:

 

import org.jivesoftware.smack.packet.IQ;

import org.jivesoftware.smack.packet.Packet;

import org.jivesoftware.smack.packet.PacketExtension;

import org.jxmpp.jid.Jid;

 

public class JaxbMessageIQ extends IQ {

 

    private final PacketExtension payload;

 

    private JaxbMessageIQ(Builder builder) {

        payload = builder.payload;

        addExtension(payload);

    }

 

    @Override

    public CharSequence getChildElementXML() {

        return payload.toXML();

    }

 

    public static Builder create() {

        return new Builder();

    }

 

    public static Builder error() {

        return new Builder(IQ.Type.ERROR);

    }

 

    public static Builder get() {

        return new Builder(IQ.Type.GET);

    }

 

    public static Builder result() {

        return new Builder(IQ.Type.RESULT);

    }

 

    public static Builder set() {

        return new Builder(IQ.Type.SET);

    }

 

    public static class Builder {

    

        private PacketExtension payload;

        private IQ.Type type;

        private String to;

        private String from;

        private String packetId;

    

        private Builder() {

            init();

        }

    

        private void init() {

            type = IQ.Type.GET;

        }

    

        private Builder(IQ.Type type) {

            this.type = type;

        }

    

        public Builder payload(PacketExtension payload) {

            this.payload = payload;

            return this;

        }

    

        public Builder type(IQ.Type type) {

            this.type = type;

            return this;

        }

    

        public Builder to(Jid to) {

            return to(to.asUnescapedString());

        }

    

        public Builder to(String to) {

            this.to = to;

            return this;

        }

    

        public Builder from(String from) {

            this.from = from;

            return this;

        }

    

        public Builder packetId(String packetId) {

            this.packetId = packetId;

            return this;

        }

    

        public Builder response(Packet request) {

            to(request.getFrom());

            from(request.getTo());

            packetId(request.getPacketID());

            return this;

        }

    

        public JaxbMessageIQ build() {

            JaxbMessageIQ iq = new JaxbMessageIQ(this);

            if (type != null)

                iq.setType(type);

            if (to != null)

                iq.setTo(to);

            if (from != null)

                iq.setFrom(from);

            if (packetId != null)

                iq.setPacketID(packetId);

        

            return iq;

        }

    

    }

 

}

 

Regards,

Jens


Viewing all articles
Browse latest Browse all 10742

Trending Articles