use of org.jivesoftware.smack.packet.Message in project wso2-axis2-transports by wso2.
the class XMPPPacketListener method createMessageContext.
/**
* Creates message context using values received in XMPP packet
* @param packet
* @return MessageContext
* @throws AxisFault
*/
private MessageContext createMessageContext(Packet packet) throws AxisFault {
Message message = (Message) packet;
Boolean isServerSide = (Boolean) message.getProperty(XMPPConstants.IS_SERVER_SIDE);
String serviceName = (String) message.getProperty(XMPPConstants.SERVICE_NAME);
String action = (String) message.getProperty(XMPPConstants.ACTION);
MessageContext msgContext = null;
TransportInDescription transportIn = configurationContext.getAxisConfiguration().getTransportIn("xmpp");
TransportOutDescription transportOut = configurationContext.getAxisConfiguration().getTransportOut("xmpp");
if ((transportIn != null) && (transportOut != null)) {
msgContext = configurationContext.createMessageContext();
msgContext.setTransportIn(transportIn);
msgContext.setTransportOut(transportOut);
if (isServerSide != null) {
msgContext.setServerSide(isServerSide.booleanValue());
}
msgContext.setProperty(CONTENT_TYPE, "text/xml");
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
msgContext.setIncomingTransportName("xmpp");
Map services = configurationContext.getAxisConfiguration().getServices();
AxisService axisService = (AxisService) services.get(serviceName);
msgContext.setAxisService(axisService);
msgContext.setSoapAction(action);
// pass the configurationFactory to transport sender
msgContext.setProperty("XMPPConfigurationFactory", this.xmppConnectionFactory);
if (packet.getFrom() != null) {
msgContext.setFrom(new EndpointReference(packet.getFrom()));
}
if (packet.getTo() != null) {
msgContext.setTo(new EndpointReference(packet.getTo()));
}
XMPPOutTransportInfo xmppOutTransportInfo = new XMPPOutTransportInfo();
xmppOutTransportInfo.setConnectionFactory(this.xmppConnectionFactory);
String packetFrom = packet.getFrom();
if (packetFrom != null) {
EndpointReference fromEPR = new EndpointReference(packetFrom);
xmppOutTransportInfo.setFrom(fromEPR);
xmppOutTransportInfo.setDestinationAccount(packetFrom);
}
// Save Message-Id to set as In-Reply-To on reply
String xmppMessageId = packet.getPacketID();
if (xmppMessageId != null) {
xmppOutTransportInfo.setInReplyTo(xmppMessageId);
}
xmppOutTransportInfo.setSequenceID((String) message.getProperty(XMPPConstants.SEQUENCE_ID));
msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, xmppOutTransportInfo);
buildSOAPEnvelope(packet, msgContext);
} else {
throw new AxisFault("Either transport in or transport out is null");
}
return msgContext;
}
use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.
the class AttentionManager method sendAttention.
public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
if (!(chat instanceof RegularChat)) {
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
}
Jid to = chat.getTo();
if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
final Presence presence = RosterManager.getInstance().getPresence(account, user);
if (presence == null) {
to = null;
} else {
to = presence.getFrom();
}
}
if (to == null) {
throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
}
if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.NAMESPACE)) {
throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
}
Message message = new Message();
message.setTo(to);
message.setType(Message.Type.headline);
message.addExtension(new AttentionExtension());
StanzaSender.sendStanza(account, message);
chat.newAction(null, null, ChatAction.attention_called);
}
use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.
the class AttentionManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(stanza instanceof Message)) {
return;
}
if (!SettingsManager.chatsAttention()) {
return;
}
final AccountJid account = connection.getAccount();
UserJid from;
try {
from = UserJid.from(stanza.getFrom());
} catch (UserJid.UserJidCreateException e) {
e.printStackTrace();
return;
}
for (ExtensionElement packetExtension : stanza.getExtensions()) {
if (packetExtension instanceof AttentionExtension) {
MessageManager.getInstance().openChat(account, from);
MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested);
attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
}
}
}
use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.
the class ChatStateManager method updateChatState.
/**
* Update chat state information and send message if necessary.
*/
private void updateChatState(AccountJid account, UserJid user, ChatState chatState) {
if (!SettingsManager.chatsStateNotification() || sent.get(account.toString(), user.toString()) == chatState) {
return;
}
AbstractChat chat = MessageManager.getInstance().getChat(account, user);
if (chat == null || !isSupported(chat, false)) {
return;
}
sent.put(chat.getAccount().toString(), chat.getUser().toString(), chatState);
Message message = new Message();
message.setType(chat.getType());
message.setTo(chat.getTo());
message.addExtension(new ChatStateExtension(chatState));
try {
StanzaSender.sendStanza(account, message);
} catch (NetworkException e) {
// Just ignore it.
}
}
use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.
the class MUCManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(connection instanceof AccountItem)) {
return;
}
AccountJid account = ((AccountItem) connection).getAccount();
Jid from = stanza.getFrom();
if (from == null || !(stanza instanceof Message)) {
return;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.normal && message.getType() != Message.Type.chat) {
return;
}
MUCUser mucUser = MUCUser.from(stanza);
if (mucUser == null || mucUser.getInvite() == null) {
return;
}
RoomChat roomChat = getRoomChat(account, from.asEntityBareJidIfPossible());
if (roomChat == null || !roomChat.getState().inUse()) {
UserJid inviter = null;
try {
inviter = UserJid.from(mucUser.getInvite().getFrom());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
if (inviter == null) {
try {
inviter = UserJid.from(from);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
try {
inviteProvider.add(new RoomInvite(account, UserJid.from(from), inviter, mucUser.getInvite().getReason(), mucUser.getPassword()), true);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
}
}
Aggregations