Germany survive Chile onslaught to win Confederations Cup