Since you want this in your error logs along with (or close to) stacktrace, you probably need Filter .
Implement the doFilter() method to check and register the calling URL for each request. I have provided some code examples below.
Once you access the HttpServletRequest object, you can call any of its methods. Take a look at getRequestURI() and getMethod() which you need.
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException { HttpServletRequest hsr = (HttpServletRequest) request; String incomingUrl=hsr.getRequestURI();
I assume you have a logger in place and you can send the output to the log file you want.
Map this Filter to a url pattern, for example /mywebservice in web.xml so that it is not called on other requests, but only on the web service.
<filter> <filter-name>Logging_URL_Filter</filter-name> <filter-class>com.mysite.URLFilter</filter-class> </filter> <filter-mapping> <filter-name>Logging_URL_Filter</filter-name> <url-pattern>/mywebservice</url-pattern> </filter-mapping>
source share