Add a method optionalQueryParam(String, Optional) to the UriBuilder interface.

The implementation adds the query parameter contained by the optional to the URL. If the optional is empty then no action is taken; specifically the query parameter name is not added to the URL.

This PR replaces #25925 and #25950.