throws IOException, RepositoryException, MalformedQueryException, UnauthorizedException
{
// Specify which formats we support using Accept headers
Set<BooleanQueryResultFormat> booleanFormats = BooleanQueryResultParserRegistry.getInstance().getKeys();
if (booleanFormats.isEmpty()) {
throw new RepositoryException("No boolean query result parsers have been registered");
}
for (BooleanQueryResultFormat format : booleanFormats) {
// Determine a q-value that reflects the user specified preference
int qValue = 10;
if (preferredBQRFormat != null && !preferredBQRFormat.equals(format)) {
// Prefer specified format over other formats
qValue -= 2;
}
for (String mimeType : format.getMIMETypes()) {
String acceptParam = mimeType;
if (qValue < 10) {
acceptParam += ";q=0." + qValue;
}
method.addRequestHeader(ACCEPT_PARAM_NAME, acceptParam);
}
}
int httpCode = httpClient.executeMethod(method);
if (httpCode == HttpURLConnection.HTTP_OK) {
String mimeType = getResponseMIMEType(method);
try {
BooleanQueryResultFormat format = BooleanQueryResultFormat.matchMIMEType(mimeType, booleanFormats);
BooleanQueryResultParser parser = QueryResultIO.createParser(format);
return parser.parse(method.getResponseBodyAsStream());
}
catch (UnsupportedQueryResultFormatException e) {
throw new RepositoryException("Server responded with an unsupported file format: " + mimeType);
}
catch (QueryResultParseException e) {
throw new RepositoryException("Malformed query result from server", e);
}
}
else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new UnauthorizedException();
}
else {
ErrorInfo errInfo = getErrorInfo(method);
// Throw appropriate exception
if (errInfo.getErrorType() == ErrorType.MALFORMED_QUERY) {
throw new MalformedQueryException(errInfo.getErrorMessage());
}
else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_QUERY_LANGUAGE) {
throw new UnsupportedQueryLanguageException(errInfo.getErrorMessage());
}
else {
throw new RepositoryException(method.getStatusText());
}
}
}