// and it was true even for userSupportedVersion being null (ie. not user agent string supplied!)!!!
final boolean remoteCall = request.getRequestContext().containsKey(AccessManager.REQUEST_REMOTE_ADDRESS);
final String userAgent = (String) request.getRequestContext().get(AccessManager.REQUEST_AGENT);
if (remoteCall && null != userAgent) {
final Version userSupportedVersion = getClientSupportedVersion(userAgent);
// we still can make up our mind here, we do this only if we know: this request is about metadata,
// the client's metadata version is known and it is not the latest one
if (M2ArtifactRecognizer.isMetadata(request.getRequestPath()) && userSupportedVersion != null
&& !ModelVersionUtility.LATEST_MODEL_VERSION.equals(userSupportedVersion)) {
// metadata checksum files are calculated and cached as side-effect
// of doRetrieveMetadata.
final StorageFileItem mdItem;
if (M2ArtifactRecognizer.isChecksum(request.getRequestPath())) {
String path = request.getRequestPath();
if (request.getRequestPath().endsWith(".md5")) {
path = path.substring(0, path.length() - 4);
}
else if (request.getRequestPath().endsWith(".sha1")) {
path = path.substring(0, path.length() - 5);
}
// we have to keep original reqest's flags: localOnly and remoteOnly are strange ones, so
// we do a hack here
// second, since we initiate a request for different path within a context of this request,
// we need to be careful about it
ResourceStoreRequest mdRequest =
new ResourceStoreRequest(path, request.isRequestLocalOnly(), request.isRequestRemoteOnly());
mdRequest.getRequestContext().setParentContext(request.getRequestContext());
mdItem = (StorageFileItem) super.retrieveItem(false, mdRequest);
}
else {
mdItem = (StorageFileItem) super.doRetrieveItem(request);
}
try {
Metadata metadata;
try (final InputStream inputStream = mdItem.getInputStream()) {
metadata = MetadataBuilder.read(inputStream);
}
Version requiredVersion = getClientSupportedVersion(userAgent);
Version metadataVersion = ModelVersionUtility.getModelVersion(metadata);
if (requiredVersion == null || requiredVersion.equals(metadataVersion)) {
return super.doRetrieveItem(request);
}