This line seems awfully dependent on a particular buggy behavior (namely, it's assuming that the URL will end with ?service or the like).  Have you determined what's causing that behavior?  This could be a problem in a particular version of rubycas-client, for example.