Fix several bugs for RestController

Resolve several bugs in RestController that occur when the URL ends in
a trailing slash.

Change-Id: I6439ee9e45b715b0bea57e9af9124675376d0c9d
Fixes-bug: 1250566