diff --git a/Service/src/main/java/org/gusdb/wdk/service/PageViewLogger.java b/Service/src/main/java/org/gusdb/wdk/service/PageViewLogger.java index 30336ab99..e8c57c1f6 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/PageViewLogger.java +++ b/Service/src/main/java/org/gusdb/wdk/service/PageViewLogger.java @@ -9,11 +9,44 @@ public class PageViewLogger { private static final Logger LOG = Logger.getLogger(PageViewLogger.class); - public static void logPageView(String projectId, User user, String pagePath) { + private static final String CLIENT_PREFIX = "/web-client"; + + public static void logPageView(String projectId, User user, String submittedPath) { LOG.info( TAB + user.getUserId() + TAB + (user.isGuest() ? "guest" : "registered") + TAB + projectId + - TAB + pagePath); + TAB + trimWebappAndClientApp(submittedPath)); + } + + // a -> a + // a/ -> a + // webapp/app -> /web-client + // webapp/app/ -> /web-client + // webapp/app/blah -> /web-client/blah + private static String trimWebappAndClientApp(String submittedPath) { + String[] segments = submittedPath.split("/"); + switch (segments.length) { + case 0: + // unrecognized path; don't legitimize with client prefix + return "/"; + case 1: + // unrecognized path; don't legitimize with client prefix + return "/" + segments[0]; + default: + // start with base URL of the webapp, then add remaining segments + String newPath = CLIENT_PREFIX; + for (int i = 2; i < segments.length; i++) { + newPath += "/" + segments[i]; + } + return newPath; + } + } + + public static void main(String[] args) { + String[] tests = new String[] { "a", "a/", "webapp/app", "webapp/app/", "webapp/app/blah" }; + for (String test : tests) { + System.out.println(test + " = " + trimWebappAndClientApp(test)); + } } } diff --git a/Service/src/main/java/org/gusdb/wdk/service/service/SystemService.java b/Service/src/main/java/org/gusdb/wdk/service/service/SystemService.java index 4a2ab032e..51449a094 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/service/SystemService.java +++ b/Service/src/main/java/org/gusdb/wdk/service/service/SystemService.java @@ -129,8 +129,6 @@ public StreamingOutput getMetrics() { @Path("/metrics/count-page-view/{clientPath:.+}") @Produces(MediaType.APPLICATION_JSON) public Response registerVisit(@PathParam("clientPath") String clientPath) { - clientPath = "/" + clientPath; // reprepend '/' - LOG.trace("Registered visit to " + clientPath); PageViewLogger.logPageView(getWdkModel().getProjectId(), getRequestingUser(), clientPath); return Response.noContent().build(); }