1 10 11 package org.mule.providers.xmpp; 12 13 import org.jivesoftware.smack.packet.Message; 14 import org.jivesoftware.smack.packet.Packet; 15 import org.mule.providers.AbstractMessageAdapter; 16 import org.mule.umo.MessagingException; 17 import org.mule.umo.provider.MessageTypeNotSupportedException; 18 19 import java.util.Iterator ; 20 21 27 public class XmppMessageAdapter extends AbstractMessageAdapter 28 { 29 32 private static final long serialVersionUID = -4003299444661664762L; 33 34 private final Packet message; 35 36 public XmppMessageAdapter(Object message) throws MessagingException 37 { 38 if (message instanceof Packet) 39 { 40 this.message = (Packet)message; 41 for (Iterator iter = this.message.getPropertyNames(); iter.hasNext();) 42 { 43 String name = (String )iter.next(); 44 setProperty(name, this.message.getProperty(name)); 45 } 46 if (this.message instanceof Message) 47 { 48 setProperty("subject", ((Message)this.message).getSubject()); 49 setProperty("thread", ((Message)this.message).getThread()); 50 } 51 } 52 else 53 { 54 throw new MessageTypeNotSupportedException(message, getClass()); 55 } 56 } 57 58 66 public String getPayloadAsString(String encoding) throws Exception 67 { 68 if (message instanceof Message) 69 { 70 return ((Message)message).getBody(); 71 } 72 else 73 { 74 return message.toString(); 75 } 76 } 77 78 public byte[] getPayloadAsBytes() throws Exception 79 { 80 if (message instanceof Message) 81 { 82 return ((Message)message).getBody().getBytes(); 83 } 84 else 85 { 86 return message.toString().getBytes(); 87 } 88 } 89 90 public Object getPayload() 91 { 92 return message; 93 } 94 95 public String getUniqueId() 96 { 97 return message.getPacketID(); 98 } 99 } 100 | Popular Tags |