CryptoMessage v1.3.2版本的 MD5 值为:66c611ce56a11450659dc23697562928
以下内容为反编译后的 HttpLookupMethod.java 源代码,内容仅作参考
package org.jivesoftware.smack.altconnections;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.xhtmlim.XHTMLText;
import org.jxmpp.jid.DomainBareJid;
public final class HttpLookupMethod {
private static final String XRD_NAMESPACE = "http://docs.oasis-open.org/ns/xri/xrd-1.0";
public enum LinkRelation {
BOSH("urn:xmpp:alt-connections:xbosh"),
WEBSOCKET("urn:xmpp:alt-connections:websocket");
private final String attribute;
LinkRelation(String str) {
this.attribute = str;
}
}
public static List<URI> lookup(DomainBareJid domainBareJid, String str) throws IOException, XmlPullParserException, URISyntaxException {
InputStream xrdStream = getXrdStream(domainBareJid);
try {
List<URI> parseXrdLinkReferencesFor = parseXrdLinkReferencesFor(PacketParserUtils.getParserFor(xrdStream), str);
if (xrdStream != null) {
xrdStream.close();
}
return parseXrdLinkReferencesFor;
} catch (Throwable th) {
try {
throw th;
} catch (Throwable th2) {
if (xrdStream != null) {
try {
xrdStream.close();
} catch (Throwable th3) {
th.addSuppressed(th3);
}
}
throw th2;
}
}
}
public static List<URI> lookup(DomainBareJid domainBareJid, LinkRelation linkRelation) throws IOException, XmlPullParserException, URISyntaxException {
return lookup(domainBareJid, linkRelation.attribute);
}
public static InputStream getXrdStream(DomainBareJid domainBareJid) throws IOException {
return new URL("https://" + ((Object) domainBareJid) + "/.well-known/host-meta").openConnection().getInputStream();
}
public static List<URI> parseXrdLinkReferencesFor(XmlPullParser xmlPullParser, String str) throws IOException, XmlPullParserException, URISyntaxException {
ParserUtils.forwardToStartElement(xmlPullParser);
ArrayList arrayList = new ArrayList();
int depth = xmlPullParser.getDepth();
while (true) {
int i = AnonymousClass1.$SwitchMap$org$jivesoftware$smack$xml$XmlPullParser$TagEvent[xmlPullParser.nextTag().ordinal()];
if (i == 1) {
String name = xmlPullParser.getName();
String namespace = xmlPullParser.getNamespace();
String attributeValue = xmlPullParser.getAttributeValue("rel");
if (namespace.equals(XRD_NAMESPACE) && name.equals("Link") && attributeValue.equals(str)) {
arrayList.add(new URI(xmlPullParser.getAttributeValue(XHTMLText.HREF)));
}
} else if (i == 2 && xmlPullParser.getDepth() == depth) {
return arrayList;
}
}
}
public static class AnonymousClass1 {
static final int[] $SwitchMap$org$jivesoftware$smack$xml$XmlPullParser$TagEvent;
static {
int[] iArr = new int[XmlPullParser.TagEvent.values().length];
$SwitchMap$org$jivesoftware$smack$xml$XmlPullParser$TagEvent = iArr;
try {
iArr[XmlPullParser.TagEvent.START_ELEMENT.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$org$jivesoftware$smack$xml$XmlPullParser$TagEvent[XmlPullParser.TagEvent.END_ELEMENT.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
public static List<URI> parseXrdLinkReferencesFor(XmlPullParser xmlPullParser, LinkRelation linkRelation) throws IOException, XmlPullParserException, URISyntaxException {
return parseXrdLinkReferencesFor(xmlPullParser, linkRelation.attribute);
}
}