mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-25 15:52:06 +01:00
Make smack-resolver-javax an OSGi ServiceComponent
Fixes SMACK-576
This commit is contained in:
parent
a77adc018b
commit
298822eaef
4 changed files with 31 additions and 7 deletions
|
@ -200,7 +200,7 @@ subprojects {
|
|||
}
|
||||
}
|
||||
|
||||
['smack-extensions', 'smack-experimental', 'smack-legacy'].each { name ->
|
||||
['smack-resolver-javax', 'smack-extensions', 'smack-experimental', 'smack-legacy'].each { name ->
|
||||
project(":$name") {
|
||||
jar {
|
||||
manifest {
|
||||
|
|
|
@ -29,6 +29,7 @@ task dnsJar(type: Jar) {
|
|||
from sourceSets.main.output
|
||||
include('org/jivesoftware/smack/util/dns/**')
|
||||
include('org/jivesoftware/smack/util/DNSUtil.class')
|
||||
include('org/jivesoftware/smack/initializer/**')
|
||||
}
|
||||
|
||||
artifacts {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smack.util.dns.javax;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,6 +28,7 @@ import javax.naming.directory.Attributes;
|
|||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
|
||||
import org.jivesoftware.smack.initializer.SmackInitializer;
|
||||
import org.jivesoftware.smack.util.DNSUtil;
|
||||
import org.jivesoftware.smack.util.dns.DNSResolver;
|
||||
import org.jivesoftware.smack.util.dns.SRVRecord;
|
||||
|
@ -37,7 +39,7 @@ import org.jivesoftware.smack.util.dns.SRVRecord;
|
|||
* @author Florian Schmaus
|
||||
*
|
||||
*/
|
||||
public class JavaxResolver implements DNSResolver {
|
||||
public class JavaxResolver implements DNSResolver, SmackInitializer {
|
||||
|
||||
private static JavaxResolver instance;
|
||||
private static DirContext dirContext;
|
||||
|
@ -52,14 +54,14 @@ public class JavaxResolver implements DNSResolver {
|
|||
}
|
||||
|
||||
// Try to set this DNS resolver as primary one
|
||||
DNSUtil.setDNSResolver(getInstance());
|
||||
setup();
|
||||
}
|
||||
|
||||
private JavaxResolver() {
|
||||
public JavaxResolver() {
|
||||
|
||||
}
|
||||
|
||||
public static DNSResolver getInstance() {
|
||||
public static synchronized DNSResolver getInstance() {
|
||||
if (instance == null && isSupported()) {
|
||||
instance = new JavaxResolver();
|
||||
}
|
||||
|
@ -70,6 +72,10 @@ public class JavaxResolver implements DNSResolver {
|
|||
return dirContext != null;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
DNSUtil.setDNSResolver(getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SRVRecord> lookupSRVRecords(String name) throws NamingException {
|
||||
List<SRVRecord> res = new ArrayList<SRVRecord>();
|
||||
|
@ -93,4 +99,15 @@ public class JavaxResolver implements DNSResolver {
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> initialize() {
|
||||
return initialize(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> initialize(ClassLoader classLoader) {
|
||||
setup();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0"
|
||||
enabled="true" immediate="true" name="Smack Resolver JavaX API">
|
||||
<implementation
|
||||
class="org.jivesoftware.smack.util.dns.javax.JavaxResolver" />
|
||||
</scr:component>
|
Loading…
Reference in a new issue