Commit f0640d42 authored by Matija Obreza's avatar Matija Obreza

Avoid AIOBE errors

parent bd1b593b
......@@ -124,32 +124,38 @@ public class RepositoryDownloadController extends BaseController {
downloadFile(path, uuid, ext, response);
}
/**
* Return repository object metadata
*/
@RequestMapping(value = "/repository/d/**", method = RequestMethod.GET, params= { "metadata" }, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody RepositoryFile getMetadata(final HttpServletRequest request)
throws IOException, NoSuchRepositoryFileException {
@RequestMapping(value = "/repository/d/**", method = RequestMethod.GET, params = { "metadata" }, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody RepositoryFile getMetadata(final HttpServletRequest request) throws IOException, NoSuchRepositoryFileException {
final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
if (LOG.isTraceEnabled()) {
LOG.trace("Fullname: " + fullpath);
}
final String ext = fullpath.substring(fullpath.lastIndexOf("."));
final String uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/") + 1);
if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext);
String path;
String uuid;
String ext;
try {
ext = fullpath.substring(fullpath.lastIndexOf("."));
uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/") + 1);
if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext);
}
} catch (ArrayIndexOutOfBoundsException e) {
// fullpath.lastIndexOf may return -1, causing AIOBE
throw new ResourceNotFoundException("No such resource " + fullpath);
}
final RepositoryFile repositoryFile = this.repositoryService.getFile(UUID.fromString(uuid));
sanityCheck(path, ext, repositoryFile);
return repositoryFile;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment