use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class XmppConnectionManager method getConnectedMainConnectionFor.
private AbstractXMPPConnection getConnectedMainConnectionFor(AccountNum accountNum) throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
String middlefix;
String accountUsername;
String accountPassword;
switch(accountNum) {
case One:
accountUsername = sinttestConfiguration.accountOneUsername;
accountPassword = sinttestConfiguration.accountOnePassword;
middlefix = "one";
break;
case Two:
accountUsername = sinttestConfiguration.accountTwoUsername;
accountPassword = sinttestConfiguration.accountTwoPassword;
middlefix = "two";
break;
case Three:
accountUsername = sinttestConfiguration.accountThreeUsername;
accountPassword = sinttestConfiguration.accountThreePassword;
middlefix = "three";
break;
default:
throw new IllegalStateException();
}
// Note that it is perfectly fine for account(Username|Password) to be 'null' at this point.
final String finalAccountUsername = StringUtils.isNullOrEmpty(accountUsername) ? USERNAME_PREFIX + '-' + middlefix + '-' + testRunId : accountUsername;
final String finalAccountPassword = StringUtils.isNullOrEmpty(accountPassword) ? StringUtils.insecureRandomString(16) : accountPassword;
if (sinttestConfiguration.isAccountRegistrationPossible()) {
registerAccount(finalAccountUsername, finalAccountPassword);
}
AbstractXMPPConnection mainConnection = defaultConnectionDescriptor.construct(sinttestConfiguration, builder -> {
try {
builder.setUsernameAndPassword(finalAccountUsername, finalAccountPassword).setResource(middlefix + '-' + testRunId);
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
});
connections.put(mainConnection, defaultConnectionDescriptor);
mainConnection.connect();
mainConnection.login();
return mainConnection;
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class SmackIntegrationTestXmppConnectionManagerTest method simpleXmppConnectionDescriptorTest.
@Test
public void simpleXmppConnectionDescriptorTest() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, KeyManagementException, NoSuchAlgorithmException, XmppStringprepException, InstantiationException {
XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> descriptor = XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class).applyExtraConfguration(b -> b.removeAllModules().addModule(XmppTcpTransportModuleDescriptor.class)).build();
Configuration sinttestConfiguration = Configuration.builder().setService("example.org").build();
ModularXmppClientToServerConnection connection = descriptor.construct(sinttestConfiguration);
assertEquals("example.org", connection.getXMPPServiceDomain().toString());
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class RTPBridge method getPublicIP.
/**
* Get Public Address from the Server.
*
* @param xmppConnection TODO javadoc me please
* @return public IP String or null if not found
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
*/
public static String getPublicIP(XMPPConnection xmppConnection) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
if (!xmppConnection.isConnected()) {
return null;
}
RTPBridge rtpPacket = new RTPBridge(RTPBridge.BridgeAction.publicip);
DomainBareJid jid;
try {
jid = JidCreate.domainBareFrom(RTPBridge.NAME + "." + xmppConnection.getXMPPServiceDomain());
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
rtpPacket.setTo(jid);
rtpPacket.setType(Type.set);
// LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
RTPBridge response = xmppConnection.sendIqRequestAndWaitForResponse(rtpPacket);
if (response == null)
return null;
if (response.getIp() == null || response.getIp().equals(""))
return null;
Enumeration<NetworkInterface> ifaces = null;
try {
ifaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
while (ifaces != null && ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
while (iaddresses.hasMoreElements()) {
InetAddress iaddress = iaddresses.nextElement();
if (!iaddress.isLoopbackAddress())
if (iaddress.getHostAddress().indexOf(response.getIp()) >= 0)
return null;
}
}
return response.getIp();
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class STUN method getSTUNServer.
/**
* Get a new STUN Server Address and port from the server.
* If a error occurs or the server don't support STUN Service, null is returned.
*
* @param connection TODO javadoc me please
* @return the STUN server address
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
*/
public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
if (!connection.isConnected()) {
return null;
}
STUN stunPacket = new STUN();
DomainBareJid jid;
try {
jid = JidCreate.domainBareFrom(DOMAIN + "." + connection.getXMPPServiceDomain());
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
stunPacket.setTo(jid);
STUN response = connection.sendIqRequestAndWaitForResponse(stunPacket);
return response;
}
use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class SignalOmemoStoreConnector method loadSession.
@Override
public SessionRecord loadSession(SignalProtocolAddress signalProtocolAddress) {
OmemoDevice device;
try {
device = asOmemoDevice(signalProtocolAddress);
} catch (XmppStringprepException e) {
throw new AssertionError(e);
}
SessionRecord record;
try {
record = omemoStore.loadRawSession(getOurDevice(), device);
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (record != null) {
return record;
} else {
return new SessionRecord();
}
}
Aggregations