use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class EnhancedDebugger method createDebug.
/**
* Creates the debug process, which is a GUI window that displays XML traffic.
*/
private void createDebug() {
// We'll arrange the UI into six tabs. The first tab contains all data, the second
// client generated XML, the third server generated XML, the fourth allows to send
// ad-hoc messages and the fifth contains connection information.
tabbedPane = new JTabbedPane();
// Add the All Packets, Sent, Received and Interpreted panels
addBasicPanels();
// Add the panel to send ad-hoc messages
addAdhocPacketPanel();
// Add the connection information panel
addInformationPanel();
// Create a thread that will listen for all incoming packets and write them to
// the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML.
packetReaderListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS");
@Override
public void processStanza(final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
addReadPacketToTable(dateFormatter, packet);
}
});
}
};
// Create a thread that will listen for all outgoing packets and write them to
// the GUI.
packetWriterListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS");
@Override
public void processStanza(final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
addSentPacketToTable(dateFormatter, packet);
}
});
}
};
// Create a thread that will listen for any connection closed event
connListener = new AbstractConnectionListener() {
@Override
public void connectionClosed() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Closed");
EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this);
}
});
}
@Override
public void connectionClosedOnError(final Exception e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Closed due to an exception");
EnhancedDebuggerWindow.connectionClosedOnError(EnhancedDebugger.this, e);
}
});
}
@Override
public void reconnectingIn(final int seconds) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Attempt to reconnect in " + seconds + " seconds");
}
});
}
@Override
public void reconnectionSuccessful() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Reconnection stablished");
EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this);
}
});
}
@Override
public void reconnectionFailed(Exception e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Reconnection failed");
}
});
}
};
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class ForwardedProvider method parse.
@Override
public Forwarded parse(XmlPullParser parser, int initialDepth) throws Exception {
DelayInformation di = null;
Stanza packet = null;
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
String name = parser.getName();
String namespace = parser.getNamespace();
switch(name) {
case DelayInformation.ELEMENT:
if (DelayInformation.NAMESPACE.equals(namespace)) {
di = DelayInformationProvider.INSTANCE.parse(parser, parser.getDepth());
} else {
LOGGER.warning("Namespace '" + namespace + "' does not match expected namespace '" + DelayInformation.NAMESPACE + "'");
}
break;
case Message.ELEMENT:
packet = PacketParserUtils.parseMessage(parser);
break;
default:
LOGGER.warning("Unsupported forwarded packet type: " + name);
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
if (packet == null)
throw new SmackException("forwarded extension must contain a packet");
return new Forwarded(di, packet);
}
use of org.jivesoftware.smack.packet.Stanza in project yellowmessenger-sdk by yellowmessenger.
the class XMPPService method createConnection.
private void createConnection() throws XmppStringprepException, NoSuchAlgorithmException {
if (mConnection == null) {
AndroidSmackInitializer androidSmackInitializer = new AndroidSmackInitializer();
androidSmackInitializer.initialize();
ExtensionsInitializer extensionsInitializer = new ExtensionsInitializer();
extensionsInitializer.initialize();
XMPPUser xmppUser = PreferencesManager.getInstance(XMPPService.this.getApplicationContext()).getXMPPUser();
XMPPTCPConnectionConfiguration connConfig = XMPPTCPConnectionConfiguration.builder().setXmppDomain(JidCreate.domainBareFrom(DOMAIN)).setHost(HOST).setPort(PORT).setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible).setCustomSSLContext(SSLContext.getInstance("TLS")).setSocketFactory(SSLSocketFactory.getDefault()).setUsernameAndPassword(xmppUser.getUsername(), xmppUser.getPassword()).build();
SmackConfiguration.setDefaultPacketReplyTimeout(5000);
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
mConnection = new XMPPTCPConnection(connConfig);
mConnection.setPacketReplyTimeout(5000);
mConnection.setPreferredResumptionTime(10);
mConnection.setUseStreamManagement(true);
mConnection.setUseStreamManagementResumption(true);
mConnection.addAsyncStanzaListener(packetListener, packetFilter);
mConnection.addAsyncStanzaListener(pingPacketListener, pingPacketFilter);
mConnection.addStanzaAcknowledgedListener(new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException {
// TODO Acknowledgement
ChatMessage chatMessage = ChatMessageDAO.getChatMessageByStanzaId(packet.getStanzaId());
if (chatMessage != null) {
chatMessage.setAcknowledged(true);
chatMessage.save();
EventBus.getDefault().post(new MessageAcknowledgementEvent(chatMessage, chatMessage.getAcknowledged()));
}
}
});
SASLAuthentication.unregisterSASLMechanism("org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism");
SASLAuthentication.registerSASLMechanism(new CustomSCRAMSHA1Mechanism());
mConnection.addConnectionListener(connectionListener);
ServerPingWithAlarmManager.getInstanceFor(mConnection).setEnabled(true);
// ReconnectionManager.getInstanceFor(mConnection).enableAutomaticReconnection();
}
try {
if (!mConnection.isConnected() && !mConnection.isAuthenticated()) {
mConnection.connect();
} else if (mConnection.isConnected() && !mConnection.isAuthenticated()) {
mConnection.login();
}
} catch (Exception e) {
// e.printStackTrace();
}
}
use of org.jivesoftware.smack.packet.Stanza in project fcmxmppserverv2 by carlosCharz.
the class CcsClient method sendPacket.
/**
* Sends a downstream message to FCM with back off strategy
*/
public void sendPacket(String jsonRequest) {
final Stanza request = new FcmPacketExtension(jsonRequest).toPacket();
final BackOffStrategy backoff = new BackOffStrategy();
while (backoff.shouldRetry()) {
try {
connection.sendStanza(request);
backoff.doNotRetry();
} catch (NotConnectedException | InterruptedException e) {
logger.log(Level.INFO, "The packet could not be sent due to a connection problem. Packet: " + request.toXML());
backoff.errorOccured();
}
}
}
use of org.jivesoftware.smack.packet.Stanza in project Spark by igniterealtime.
the class TicTacToePlugin method initialize.
@Override
public void initialize() {
ClassLoader cl = getClass().getClassLoader();
buttonimg = new ImageIcon(cl.getResource("ttt.button.png"));
_currentInvitations = new HashSet<String>();
ProviderManager.addIQProvider(GameOfferPacket.ELEMENT_NAME, GameOfferPacket.NAMESPACE, new GameOfferPacket.Provider());
ProviderManager.addExtensionProvider(MovePacket.ELEMENT_NAME, MovePacket.NAMESPACE, new MovePacket.Provider());
ProviderManager.addExtensionProvider(InvalidMove.ELEMENT_NAME, InvalidMove.NAMESPACE, new InvalidMove.Provider());
// Add IQ listener to listen for incoming game invitations.
_gameOfferListener = new StanzaListener() {
public void processPacket(Stanza stanza) {
GameOfferPacket invitation = (GameOfferPacket) stanza;
if (invitation.getType() == IQ.Type.get) {
showInvitationAlert(invitation);
}
}
};
SparkManager.getConnection().addAsyncStanzaListener(_gameOfferListener, new StanzaTypeFilter(GameOfferPacket.class));
addButtonToToolBar();
}
Aggregations