use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class FillableForm method setAnswer.
public void setAnswer(String fieldName, Collection<? extends CharSequence> answers) {
FormField blankField = getFieldOrThrow(fieldName);
FormField.Type type = blankField.getType();
FormField filledFormField;
switch(type) {
case list_multi:
case text_multi:
filledFormField = createMultiKindFieldbuilder(fieldName, type).addValues(answers).build();
break;
case jid_multi:
List<Jid> jids = new ArrayList<>(answers.size());
List<XmppStringprepException> exceptions = new ArrayList<>();
JidUtil.jidsFrom(answers, jids, exceptions);
if (!exceptions.isEmpty()) {
// TODO: Report all exceptions here.
throw new IllegalArgumentException(exceptions.get(0));
}
filledFormField = FormField.jidMultiBuilder(fieldName).addValues(jids).build();
break;
default:
throw new IllegalArgumentException("");
}
write(filledFormField);
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class SignalOmemoStoreConnector method deleteAllSessions.
@Override
public void deleteAllSessions(String s) {
BareJid jid;
try {
jid = JidCreate.bareFrom(s);
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
omemoStore.removeAllRawSessionsOf(getOurDevice(), jid);
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class SignalOmemoStoreConnector method deleteSession.
@Override
public void deleteSession(SignalProtocolAddress signalProtocolAddress) {
OmemoDevice device;
try {
device = asOmemoDevice(signalProtocolAddress);
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
omemoStore.removeRawSession(getOurDevice(), device);
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class AbstractXMPPConnection method onStreamOpen.
/**
* Must be called when a XMPP stream open tag is encountered. Sets values like the stream ID and the incoming stream
* XML environment.
* <p>
* This method also returns a matching stream close tag. For example if the stream open is {@code <stream …>}, then
* {@code </stream>} is returned. But if it is {@code <stream:stream>}, then {@code </stream:stream>} is returned.
* Or if it is {@code <foo:stream>}, then {@code </foo:stream>} is returned.
* </p>
*
* @param parser an XML parser that is positioned at the start of the stream open.
* @return a String representing the corresponding stream end tag.
*/
protected String onStreamOpen(XmlPullParser parser) {
assert StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE.equals(parser.getNamespace()) : parser.getNamespace() + " is not " + StreamOpen.ETHERX_JABBER_STREAMS_NAMESPACE;
assert StreamOpen.UNPREFIXED_ELEMENT.equals(parser.getName());
streamId = parser.getAttributeValue("id");
incomingStreamXmlEnvironment = XmlEnvironment.from(parser);
String reportedServerDomainString = parser.getAttributeValue("from");
// in c2s connections is required or not.
if (reportedServerDomainString != null) {
DomainBareJid reportedServerDomain;
try {
reportedServerDomain = JidCreate.domainBareFrom(reportedServerDomainString);
DomainBareJid configuredXmppServiceDomain = config.getXMPPServiceDomain();
if (!configuredXmppServiceDomain.equals(reportedServerDomain)) {
LOGGER.warning("Domain reported by server '" + reportedServerDomain + "' does not match configured domain '" + configuredXmppServiceDomain + "'");
}
} catch (XmppStringprepException e) {
LOGGER.log(Level.WARNING, "XMPP service domain '" + reportedServerDomainString + "' as reported by server could not be transformed to a valid JID", e);
}
}
String prefix = parser.getPrefix();
if (StringUtils.isNotEmpty(prefix)) {
return "</" + prefix + ":stream>";
}
return "</stream>";
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class XmppConnectionManager method disconnectAndCleanup.
void disconnectAndCleanup() throws InterruptedException {
int successfullyDeletedAccountsCount = 0;
for (AbstractXMPPConnection connection : connections.keySet()) {
if (sinttestConfiguration.accountRegistration == AccountRegistration.inBandRegistration) {
// Note that we use the account manager from the to-be-deleted connection.
AccountManager accountManager = AccountManager.getInstance(connection);
try {
accountManager.deleteAccount();
successfullyDeletedAccountsCount++;
} catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
}
}
connection.disconnect();
if (sinttestConfiguration.accountRegistration == AccountRegistration.serviceAdministration) {
String username = connection.getConfiguration().getUsername().toString();
Localpart usernameAsLocalpart;
try {
usernameAsLocalpart = Localpart.from(username);
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
EntityBareJid connectionAddress = JidCreate.entityBareFrom(usernameAsLocalpart, sinttestConfiguration.service);
try {
adminManager.deleteUser(connectionAddress);
successfullyDeletedAccountsCount++;
} catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
}
}
}
if (sinttestConfiguration.isAccountRegistrationPossible()) {
int unsuccessfullyDeletedAccountsCount = connections.size() - successfullyDeletedAccountsCount;
if (unsuccessfullyDeletedAccountsCount == 0) {
LOGGER.info("Successfully deleted all created accounts ✔");
} else {
LOGGER.warning("Could not delete all created accounts, " + unsuccessfullyDeletedAccountsCount + " remainaing");
}
}
connections.clear();
if (accountRegistrationConnection != null) {
accountRegistrationConnection.disconnect();
}
}
Aggregations