Use instanceof check against AbstractFileResolvingResource instead of try/catch around resource.getFilename() call.