mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-09-27 18:19:33 +02:00
4c76f2652d
Because of OSGi, no subproject of Smack (which is the same as a OSGi bundle) must export a package that is already exported by another subproject. Therefore it was necessary to move the TCP and BOSH code into their own packages: org.jivesoftware.smack.(tcp|bosh). OSGi classloader restrictions also made it necessary to create a Declarative Service for smack-extensions, smack-experimental and smack-lagacy (i.e. smack subprojects which should be initialized), in order to initialize them accordingly, as smack-core is, when used in a OSGi environment, unable to load and initialize classes from other smack bundles. OSGi's "Service Component Runtime" (SCR) will now take care of running the initialization code of the particular Smack bundle by activating its Declarative Service. That is also the reason why most initialization related method now have an additional classloader argument. Note that due the refactoring, some ugly changes in XMPPTCPConnection and its PacketReader and PacketWriter where necessary.
69 lines
2.1 KiB
Java
69 lines
2.1 KiB
Java
/**
|
|
*
|
|
* Copyright 2013-2014 Florian Schmaus
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package org.jivesoftware.smack.util.dns.dnsjava;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.jivesoftware.smack.util.dns.DNSResolver;
|
|
import org.jivesoftware.smack.util.dns.SRVRecord;
|
|
import org.xbill.DNS.Lookup;
|
|
import org.xbill.DNS.Record;
|
|
import org.xbill.DNS.TextParseException;
|
|
import org.xbill.DNS.Type;
|
|
|
|
/**
|
|
* This implementation uses the <a href="http://www.dnsjava.org/">dnsjava</a> implementation for resolving DNS addresses.
|
|
*
|
|
*/
|
|
public class DNSJavaResolver implements DNSResolver {
|
|
|
|
private static DNSJavaResolver instance = new DNSJavaResolver();
|
|
|
|
private DNSJavaResolver() {
|
|
}
|
|
|
|
public static DNSResolver getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
@Override
|
|
public List<SRVRecord> lookupSRVRecords(String name) throws TextParseException {
|
|
List<SRVRecord> res = new ArrayList<SRVRecord>();
|
|
|
|
Lookup lookup = new Lookup(name, Type.SRV);
|
|
Record recs[] = lookup.run();
|
|
if (recs == null)
|
|
return res;
|
|
|
|
for (Record record : recs) {
|
|
org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record;
|
|
if (srvRecord != null && srvRecord.getTarget() != null) {
|
|
String host = srvRecord.getTarget().toString();
|
|
int port = srvRecord.getPort();
|
|
int priority = srvRecord.getPriority();
|
|
int weight = srvRecord.getWeight();
|
|
|
|
SRVRecord r = new SRVRecord(host, port, priority, weight);
|
|
res.add(r);
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
}
|