mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +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") {
|
project(":$name") {
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
|
|
|
@ -29,6 +29,7 @@ task dnsJar(type: Jar) {
|
||||||
from sourceSets.main.output
|
from sourceSets.main.output
|
||||||
include('org/jivesoftware/smack/util/dns/**')
|
include('org/jivesoftware/smack/util/dns/**')
|
||||||
include('org/jivesoftware/smack/util/DNSUtil.class')
|
include('org/jivesoftware/smack/util/DNSUtil.class')
|
||||||
|
include('org/jivesoftware/smack/initializer/**')
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.jivesoftware.smack.util.dns.javax;
|
package org.jivesoftware.smack.util.dns.javax;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ import javax.naming.directory.Attributes;
|
||||||
import javax.naming.directory.DirContext;
|
import javax.naming.directory.DirContext;
|
||||||
import javax.naming.directory.InitialDirContext;
|
import javax.naming.directory.InitialDirContext;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.initializer.SmackInitializer;
|
||||||
import org.jivesoftware.smack.util.DNSUtil;
|
import org.jivesoftware.smack.util.DNSUtil;
|
||||||
import org.jivesoftware.smack.util.dns.DNSResolver;
|
import org.jivesoftware.smack.util.dns.DNSResolver;
|
||||||
import org.jivesoftware.smack.util.dns.SRVRecord;
|
import org.jivesoftware.smack.util.dns.SRVRecord;
|
||||||
|
@ -37,7 +39,7 @@ import org.jivesoftware.smack.util.dns.SRVRecord;
|
||||||
* @author Florian Schmaus
|
* @author Florian Schmaus
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class JavaxResolver implements DNSResolver {
|
public class JavaxResolver implements DNSResolver, SmackInitializer {
|
||||||
|
|
||||||
private static JavaxResolver instance;
|
private static JavaxResolver instance;
|
||||||
private static DirContext dirContext;
|
private static DirContext dirContext;
|
||||||
|
@ -52,24 +54,28 @@ public class JavaxResolver implements DNSResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set this DNS resolver as primary one
|
// 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()) {
|
if (instance == null && isSupported()) {
|
||||||
instance = new JavaxResolver();
|
instance = new JavaxResolver();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSupported() {
|
public static boolean isSupported() {
|
||||||
return dirContext != null;
|
return dirContext != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setup() {
|
||||||
|
DNSUtil.setDNSResolver(getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SRVRecord> lookupSRVRecords(String name) throws NamingException {
|
public List<SRVRecord> lookupSRVRecords(String name) throws NamingException {
|
||||||
List<SRVRecord> res = new ArrayList<SRVRecord>();
|
List<SRVRecord> res = new ArrayList<SRVRecord>();
|
||||||
|
@ -93,4 +99,15 @@ public class JavaxResolver implements DNSResolver {
|
||||||
}
|
}
|
||||||
return res;
|
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