prk68
prk68

Reputation: 176

How to get the URL of the calling application in my REST service?

I am trying to implement a google analytics like service. This service will be called by client side JS embedded in different applications.

In my service, I want to extract the URL of the caller application. Is there any way in which I can extract this information in my service rather than have the client side JS send it (client side is less preferable because of data safety issues) ?

Upvotes: 0

Views: 740

Answers (1)

Ritesh Kumar
Ritesh Kumar

Reputation: 157

I think you want something like this: URL of the caller

For this add HttpServletRequest request in API argument and try this

String uri = request.getScheme() + "://" +   // "http" + "://
             request.getServerName() +       // "localhost"
             ":" + request.getServerPort() + // ":" + "8080"
             request.getRequestURI() +       // "/employee"
            (request.getQueryString() != null ? "?" +
             request.getQueryString() : ""); // "?" + "lastname=Kumar&age=30"

Upvotes: 1

Related Questions