UrlSessionTracking extends BaseSessionTracking implements SessionTracking { @Override public IdAndSource retrieveId(RequestWithSession request) { String requestUri = ((HttpServletRequest)request).getRequestURI(); int sessionIdStart = requestUri.toLowerCase().lastIndexOf(sessionIdPathItem); if (sessionIdStart > -1) { sessionIdStart += sessionIdPathItem.length(); String sessionId = clean(requestUri.substring(sessionIdStart)); if (sessionId != null) { return new IdAndSource(sessionId, isCookieTracking()); } else { return null; } } if (this.nextSessionTracking != null) { return this.nextSessionTracking.retrieveId(request); } return null; }  @Override void configure(SessionConfiguration configuration); @Override IdAndSource retrieveId(RequestWithSession request); @Override void propagateSession(RequestWithSession request, Object response); @Override String encodeUrl(RequestWithSession request, String url); @Override boolean isCookieTracking();  }
@Test public void testRetrieveId() { SessionConfiguration sc = new SessionConfiguration(); sc.setSessionIdName("somesession"); sc.setAttribute("com.amadeus.session.id", "uuid"); urlSessionTracking.configure(sc); RequestWithSession request = mock(RequestWithSession.class, withSettings().extraInterfaces(HttpServletRequest.class)); HttpServletRequest hsr = (HttpServletRequest)request; UUID uuid = UUID.randomUUID(); when(hsr.getRequestURI()).thenReturn("/url;somesession="+uuid); SessionTracking.IdAndSource id = urlSessionTracking.retrieveId(request); assertNotNull(id); assertEquals(uuid.toString(), id.id); when(hsr.getRequestURI()).thenReturn("/url;SomeSession="+uuid); id = urlSessionTracking.retrieveId(request); assertNotNull("URL parameter case sensitivity test", id); assertEquals("URL parameter case sensitivity test", uuid.toString(), id.id); String sessionIdWithTimestamp = uuid.toString() + BaseSessionTracking.SESSION_ID_TIMESTAMP_SEPARATOR + System.currentTimeMillis(); String invalidSessionIdWithTimestamp = uuid.toString() + "-abcdefgh" + BaseSessionTracking.SESSION_ID_TIMESTAMP_SEPARATOR + System.currentTimeMillis(); String sessionIdWithoutTimestamp = uuid.toString(); when(hsr.getPathInfo()).thenReturn(";somesession="+sessionIdWithTimestamp); when(hsr.getRequestURI()).thenReturn("/url;somesession="+sessionIdWithTimestamp); assertNull(urlSessionTracking.retrieveId(request)); when(hsr.getPathInfo()).thenReturn(";somesession="+sessionIdWithoutTimestamp); when(hsr.getRequestURI()).thenReturn("/url;somesession="+sessionIdWithoutTimestamp); assertEquals(sessionIdWithoutTimestamp, urlSessionTracking.retrieveId(request).id); when(hsr.getPathInfo()).thenReturn(";somesession="+invalidSessionIdWithTimestamp); when(hsr.getRequestURI()).thenReturn("/url;somesession="+invalidSessionIdWithTimestamp); assertNull(urlSessionTracking.retrieveId(request)); sc.setTimestampSufix(true); urlSessionTracking.configure(sc); when(hsr.getPathInfo()).thenReturn(";somesession="+sessionIdWithTimestamp); when(hsr.getRequestURI()).thenReturn("/url;somesession="+sessionIdWithTimestamp); assertEquals(sessionIdWithTimestamp, urlSessionTracking.retrieveId(request).id); when(hsr.getPathInfo()).thenReturn(";somesession="+sessionIdWithoutTimestamp); when(hsr.getRequestURI()).thenReturn("/url;somesession="+sessionIdWithoutTimestamp); assertEquals(sessionIdWithoutTimestamp, urlSessionTracking.retrieveId(request).id); when(hsr.getPathInfo()).thenReturn(";somesession="+invalidSessionIdWithTimestamp); when(hsr.getRequestURI()).thenReturn("/url;somesession="+invalidSessionIdWithTimestamp); assertNull(urlSessionTracking.retrieveId(request)); }