ResolverState state) throws PartialResolutionException {
log.trace("resolveViaProxy('" + qxri + ", serviceType=" + serviceType
+ ", serviceMediaType=" + serviceMediaType + ", flags: "
+ flags + ")");
XRDS xrdsOut = new XRDS();
// build the new URI for the proxy
URI newURI = null;
try {
StringBuffer query = new StringBuffer();
if (serviceType != null) {
query.append("_xrd_t=");
query.append(URLEncoder.encode(serviceType, "UTF-8"));
query.append('&');
}
if (serviceMediaType != null) {
query.append("_xrd_m=");
query.append(URLEncoder.encode(serviceMediaType, "UTF-8"));
query.append('&');
}
query.append("_xrd_r=");
query.append(Tags.CONTENT_TYPE_XRDS);
query.append(';');
query.append(flags.getTrustParameters());
query.append(";sep=");
query.append(sepSelect);
query.append(";ref=");
query.append(flags.isRefs());
query.append('&');
if (proxyURI.getQuery() != null) {
query.append(proxyURI.getQuery());
}
StringBuffer uriBuf = new StringBuffer();
uriBuf.append(proxyURI.getScheme());
uriBuf.append("://");
uriBuf.append(proxyURI.getAuthority());
uriBuf.append(proxyURI.getPath());
if (uriBuf.charAt(uriBuf.length() - 1) != '/')
uriBuf.append('/');
StringBuffer qxriNoQuery = new StringBuffer(qxri.getAuthorityPath().toIRINormalForm());
if (sepSelect) {
qxriNoQuery.append(qxri.getXRIPath().toURINormalForm());
}
uriBuf.append(URLEncoder.encode(qxriNoQuery.toString(), "UTF-8"));
uriBuf.append('?');
uriBuf.append(query);
log.trace("resolveViaProxy - constructed proxy query URI '"
+ uriBuf + "'");
newURI = new URI(uriBuf.toString());
} catch (java.net.URISyntaxException oEx) {
XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
Status.INVALID_INPUT,
"Unable to construct URI to access proxy resolution service");
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
} catch (UnsupportedEncodingException e) {
// thrown from URLEncoder.encode() - this should never happen since the
// US-ASCII encoding should be supported on every computer or so we hope :)
XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
Status.INVALID_INPUT, "Charset not supported");
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
} catch (Exception e) {
XRD err = createErrorXRD(qxri.getAuthorityPath().toURINormalForm(),
Status.PERM_FAIL,
"Unexpected error while constructing proxy URI: "
+ e.getMessage());
xrdsOut.add(err);
throw new PartialResolutionException(xrdsOut);
}
InputStream in = null;
try {
// try to get the data from it
in = getDataFromURI(newURI, qxri.toURINormalForm(), flags, state);
XRDS xrds = readXRDS(in);
XRD finalXRD = xrds.getFinalXRD();
String code = finalXRD.getStatusCode();
if ((flags.isRefs() && !code.equals(Status.SUCCESS) && !code
.equals(Status.REF_NOT_FOLLOWED))
|| !code.equals(Status.SUCCESS)) {