private <T> T handleResponseWithAuthentication(int status,
                                                   InputStream responseStream,
                                                   Class<T> clz)
            throws AuthenticationException, ServiceException {
        try {
            switch (status) {
                case 200:
                    return xmlObjectUnmarshaller.unmarshal(responseStream, clz);
                case 401:
                    throw new AuthenticationException();
                default:
                    throw new UnexpectedStatusException(status);
            }
        } catch (Exception ex) {
            throw new ServiceException(ex);
        }
    }