1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.xmpp; |
19 |
|
|
20 |
|
import org.apache.camel.Exchange; |
21 |
|
import org.apache.camel.impl.DefaultProducer; |
22 |
|
import org.apache.commons.logging.Log; |
23 |
|
import org.apache.commons.logging.LogFactory; |
24 |
|
import org.jivesoftware.smack.Chat; |
25 |
|
import org.jivesoftware.smack.XMPPException; |
26 |
|
import org.jivesoftware.smack.packet.Message; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
public class XmppPrivateChatProducer extends DefaultProducer { |
32 |
0 |
private static final transient Log log = LogFactory.getLog(XmppPrivateChatProducer.class); |
33 |
|
private final XmppEndpoint endpoint; |
34 |
|
private final String participant; |
35 |
|
private Chat chat; |
36 |
|
|
37 |
|
public XmppPrivateChatProducer(XmppEndpoint endpoint, String participant) { |
38 |
0 |
super(endpoint); |
39 |
0 |
this.endpoint = endpoint; |
40 |
0 |
this.participant = participant; |
41 |
0 |
if (participant == null) { |
42 |
0 |
throw new IllegalArgumentException("No participant property specified"); |
43 |
|
} |
44 |
0 |
} |
45 |
|
|
46 |
|
public void process(Exchange exchange) { |
47 |
|
|
48 |
0 |
Message message = chat.createMessage(); |
49 |
0 |
message.setTo(participant); |
50 |
0 |
message.setFrom(endpoint.getUser()); |
51 |
0 |
message.setThread(exchange.getExchangeId()); |
52 |
0 |
message.setType(Message.Type.NORMAL); |
53 |
|
|
54 |
0 |
endpoint.getBinding().populateXmppMessage(message, exchange); |
55 |
0 |
if (log.isDebugEnabled()) { |
56 |
0 |
log.debug(">>>> message: " + message.getBody()); |
57 |
|
} |
58 |
|
try { |
59 |
0 |
chat.sendMessage(message); |
60 |
|
} |
61 |
0 |
catch (XMPPException e) { |
62 |
0 |
throw new RuntimeXmppException(e); |
63 |
0 |
} |
64 |
0 |
} |
65 |
|
|
66 |
|
@Override |
67 |
|
protected void doStart() throws Exception { |
68 |
0 |
super.doStart(); |
69 |
0 |
if (chat == null) { |
70 |
0 |
chat = endpoint.getConnection().createChat(getParticipant()); |
71 |
|
} |
72 |
0 |
} |
73 |
|
|
74 |
|
@Override |
75 |
|
protected void doStop() throws Exception { |
76 |
0 |
chat = null; |
77 |
0 |
super.doStop(); |
78 |
0 |
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
public Chat getChat() { |
83 |
0 |
return chat; |
84 |
|
} |
85 |
|
|
86 |
|
public void setChat(Chat chat) { |
87 |
0 |
this.chat = chat; |
88 |
0 |
} |
89 |
|
|
90 |
|
public String getParticipant() { |
91 |
0 |
return participant; |
92 |
|
} |
93 |
|
} |