log.trace("resolveIRIAuth('" + iriAuth + "', flags: " + flags + ")");
XRDS xrdsOut = new XRDS();
if (flags.isSaml()) {
XRD err = createErrorXRD(iriAuth.toURINormalForm(),
Status.NOT_IMPLEMENTED,
"SAML is not supported for an IRI authority");
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}
// only use http for insecure and https for secure
String scheme = flags.isHttps() ? "https" : "http";
URI uri = null;
try {
uri = new URI(scheme, iriAuth.getIUserInfo(), iriAuth.getIHost(),
iriAuth.getPort(), null, null, null);
} catch (java.net.URISyntaxException e) {
XRD err = createErrorXRD(iriAuth.toURINormalForm(),
Status.INVALID_INPUT,
"Unable to construct URI to resolve IRI authority: "
+ e.getMessage());
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}
// now that we've constructed the new URI, try to return the stream from it
InputStream in = null;
try {
in = getDataFromURI(uri, uri.toString(), flags, state);
} catch (Exception e) {
XRD err = createErrorXRD(iriAuth.toURINormalForm(),
Status.NETWORK_ERROR,
"Network error occurred while resolving IRI authority: "
+ e.getMessage());
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}
if (in == null) {
throw new RuntimeException(
"resolveIRIAuth - getDataFromURI returned null");
}
// read the descriptors
try {
xrdsOut = readXRDS(in);
if (xrdsOut.getNumChildren() != 1) {
XRD err = createErrorXRD(iriAuth.toURINormalForm(),
Status.UNEXPECTED_RESPONSE,
"Expected 1 XRD from IRI authority, got "
+ xrdsOut.getNumChildren() + " instead");
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}
} catch (XRIResolutionException e) {
XRD err = createErrorXRD(iriAuth.toURINormalForm(),
Status.UNEXPECTED_RESPONSE,
"Error reading XRDS from server: " + e.getMessage());
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}
// add the descriptor, but only if is is valid
XRD xrd = xrdsOut.getDescriptorAt(0);
if (!xrd.isValid()) {
XRD err = createErrorXRD(iriAuth.toURINormalForm(),
Status.UNEXPECTED_XRD, "XRD is invalid");
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}