use of org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure in project Smack by igniterealtime.
the class RemoteXmppTcpConnectionEndpointsTest method testConnectionException.
@Test
public void testConnectionException() {
List<RemoteConnectionException<? extends RemoteConnectionEndpoint>> connectionExceptions = new ArrayList<>();
{
A aRr = new A("1.2.3.4");
UInt16 port = UInt16.from(1234);
String host = "example.org";
IpTcpRemoteConnectionEndpoint<A> remoteConnectionEndpoint = new IpTcpRemoteConnectionEndpoint<>(host, port, aRr);
Exception exception = new Exception("Failed for some reason");
RemoteConnectionException<IpTcpRemoteConnectionEndpoint<A>> remoteConnectionException = RemoteConnectionException.from(remoteConnectionEndpoint, exception);
connectionExceptions.add(remoteConnectionException);
}
{
A aRr = new A("1.3.3.7");
UInt16 port = UInt16.from(5678);
String host = "other.example.org";
IpTcpRemoteConnectionEndpoint<A> remoteConnectionEndpoint = new IpTcpRemoteConnectionEndpoint<>(host, port, aRr);
Exception exception = new Exception("Failed for some other reason");
RemoteConnectionException<IpTcpRemoteConnectionEndpoint<A>> remoteConnectionException = RemoteConnectionException.from(remoteConnectionEndpoint, exception);
connectionExceptions.add(remoteConnectionException);
}
List<RemoteConnectionEndpointLookupFailure> lookupFailures = Collections.emptyList();
SmackException.EndpointConnectionException endpointConnectionException = SmackException.EndpointConnectionException.from(lookupFailures, connectionExceptions);
String message = endpointConnectionException.getMessage();
assertEquals("The following addresses failed: " + "'RFC 6120 A/AAAA Endpoint + [example.org:1234] (/1.2.3.4:1234)' failed because: java.lang.Exception: Failed for some reason, " + "'RFC 6120 A/AAAA Endpoint + [other.example.org:5678] (/1.3.3.7:5678)' failed because: java.lang.Exception: Failed for some other reason", message);
}
use of org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure in project Smack by igniterealtime.
the class WebSocketRemoteConnectionEndpointLookup method lookup.
public static Result lookup(DomainBareJid domainBareJid) {
List<RemoteConnectionEndpointLookupFailure> lookupFailures = new ArrayList<>(1);
List<URI> rcUriList = null;
try {
// Look for remote connection endpoints by making use of http lookup method described inside XEP-0156.
rcUriList = HttpLookupMethod.lookup(domainBareJid, LinkRelation.WEBSOCKET);
} catch (IOException | XmlPullParserException | URISyntaxException e) {
lookupFailures.add(new RemoteConnectionEndpointLookupFailure.HttpLookupFailure(domainBareJid, e));
return new Result(lookupFailures);
}
List<SecureWebSocketRemoteConnectionEndpoint> discoveredSecureEndpoints = new ArrayList<>(rcUriList.size());
List<InsecureWebSocketRemoteConnectionEndpoint> discoveredInsecureEndpoints = new ArrayList<>(rcUriList.size());
for (URI webSocketUri : rcUriList) {
WebSocketRemoteConnectionEndpoint wsRce = WebSocketRemoteConnectionEndpoint.from(webSocketUri);
if (wsRce instanceof SecureWebSocketRemoteConnectionEndpoint) {
SecureWebSocketRemoteConnectionEndpoint secureWsRce = (SecureWebSocketRemoteConnectionEndpoint) wsRce;
discoveredSecureEndpoints.add(secureWsRce);
} else if (wsRce instanceof InsecureWebSocketRemoteConnectionEndpoint) {
InsecureWebSocketRemoteConnectionEndpoint insecureWsRce = (InsecureWebSocketRemoteConnectionEndpoint) wsRce;
discoveredInsecureEndpoints.add(insecureWsRce);
} else {
// WebSocketRemoteConnectionEndpoint.from() must return an instance which type is one of the above.
throw new AssertionError();
}
}
return new Result(discoveredSecureEndpoints, discoveredInsecureEndpoints, lookupFailures);
}
use of org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure in project Smack by igniterealtime.
the class DNSJavaResolver method lookupSrvRecords0.
@Override
protected List<SRV> lookupSrvRecords0(DnsName name, List<RemoteConnectionEndpointLookupFailure> lookupFailures, DnssecMode dnssecMode) {
Lookup lookup;
try {
lookup = new Lookup(name.ace, Type.SRV);
} catch (TextParseException e) {
RemoteConnectionEndpointLookupFailure failure = new RemoteConnectionEndpointLookupFailure.DnsLookupFailure(name, e);
lookupFailures.add(failure);
return null;
}
Record[] recs = lookup.run();
if (recs == null) {
// TODO: When does this happen? Do we want/need to record a lookup failure?
return null;
}
List<SRV> res = new ArrayList<>();
for (Record record : recs) {
org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
if (srvRecord != null && srvRecord.getTarget() != null) {
DnsName host = DnsName.from(srvRecord.getTarget().toString());
int port = srvRecord.getPort();
int priority = srvRecord.getPriority();
int weight = srvRecord.getWeight();
SRV r = new SRV(priority, weight, port, host);
res.add(r);
}
}
return res;
}
Aggregations