Create message while sending Image through Asmack

前端 未结 1 718
耶瑟儿~
耶瑟儿~ 2021-01-25 06:37

There is an issue that I am facing while sending Images through XMPP.Below is the code snippet that i have done. I don\'t know what is wrong with the code .

Mess         


        
1条回答
  •  死守一世寂寞
    2021-01-25 07:21

    You can use any name and namespace for your custom packets, but XML stream of your outgoing packets should be valid and well-formed XML document. In your example I see unbound ftpurl, httpurl, imageName nodes. Any good XML/XMPP parser will throw error, because your stream is not well-formed. Common practice is - wrap all you custom nodes in one top-level node and define namespace, like this:

    
     http://my.image.jpg
     ftp://my/image.jpg
    
    

    This will cause XML parser to treat all your custom XML nodes as they come from "my:image:transfer" namespace and XML stream will be valid.

    In the context of your "Image transfer extension" - you are trying to reinvent "Out-of-Band" XMPP File Transfer, which has well-known XMPP Extension - http://xmpp.org/extensions/xep-0066.html

    Packets with OOB extension look like that:

    
      Yeah, but do you have a license to Jabber?
      
        http://www.jabber.org/images/psa-license.jpg
        Jabber license
      
    
    

    Smack PacketExtension for this type of payload should look like:

    public class OutOfBandData implements PacketExtension {
    
        String description;
        String url;
    
        @Override
        public String getElementName() {
            return "x";
        }
    
        @Override
        public String getNamespace() {
            return "jabber:x:oob";
        }
    
        @Override
        public String toXML() {
        StringBuilder builder = new StringBuilder();
        builder.("<" + getElementName() + " xmlns=\"" + getNamespace() + "\">");
        if (url != null) {
            builder.append("").append(url).append("");
        }
        if (description != null) {
            builder.append("").append(description).append("");
        }
        builder.append("");
        return builder.toString();
        }
    
        public String getDescription() {
            return description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    
        public String getUrl() {
            return url;
        }
    
        public void setUrl(String imageUrl) {
            this.url = imageUrl;
        }
    

    This is not far from your implementation, but chances where other XMPP clients understand your "Image Transfer" are growing.

    0 讨论(0)
提交回复
热议问题