ACCELERATION OF ULTRA-HIGH-ENERGY COSMIC RAYS IN THE COLLIDING SHELLS OF BLAZARS AND GAMMA-RAY BURSTS: CONSTRAINTS FROM THE FERMI GAMMA-RAY SPACE TELESCOPE