Exact solution of the optical response of thick slabs in the discrete dipole approach