From 7ccd568e5a4a2732a0738fa4632b662ae5978021 Mon Sep 17 00:00:00 2001 From: khrooick Date: Thu, 25 Jan 2018 11:57:31 +0100 Subject: [PATCH 1/9] fix miliseconds in date long string --- .../web/internal/cookies/SessionCookie.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java index 68ebb384d56..60ef870c515 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java @@ -22,8 +22,7 @@ package com.microsoft.applicationinsights.web.internal.cookies; import java.text.ParseException; -import java.util.Calendar; -import java.util.Date; +import java.util.*; import javax.servlet.http.Cookie; import com.microsoft.applicationinsights.internal.util.DateTimeUtils; @@ -191,8 +190,10 @@ private void parseCookie(Cookie cookie) throws Exception { */ private Date parseDateWithBackwardCompatibility(String dateStr) throws ParseException { try { - return new Date(Long.parseLong(dateStr)); - } catch (NumberFormatException e) { + Scanner s = new Scanner(dateStr); + s.useDelimiter("\\."); + return new Date(s.nextLong()); + } catch (NoSuchElementException e) { return DateTimeUtils.parseRoundTripDateString(dateStr); } } From a6cefd1b9c29a5d166a97feac41eaa8f129716b9 Mon Sep 17 00:00:00 2001 From: khrooick Date: Thu, 25 Jan 2018 14:27:04 +0100 Subject: [PATCH 2/9] add testCookieParsedSuccessfullyWithMiliseconds test --- .../internal/cookies/SessionCookieTests.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java index efa2b907e33..513f7e3af1d 100644 --- a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java +++ b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java @@ -166,11 +166,30 @@ public void testCookieParsedSuccessfullyWithBackwardCompatibilityForTimeFormats( SessionCookie sessionCookie = new SessionCookie(cookie); - Assert.assertEquals("Wrong session ID", sessionId, sessionCookie.getSessionId()); Assert.assertEquals("Wrong session acquisition time", expectedAcquisitionTime, DateTimeUtils.formatAsRoundTripDate(sessionCookie.getSessionAcquisitionDate())); Assert.assertEquals("Wrong session renewal time", expectedRenewalTime, DateTimeUtils.formatAsRoundTripDate(sessionCookie.getSessionRenewalDate())); } + + @Test + public void testCookieParsedSuccessfullyWithMiliseconds() throws Exception { + Date expectedAcquisitionTime = new Date(); + Date expectedRenewalTime = new Date(); + + String formattedCookie = SessionCookie.formatCookie(new String[] { + sessionId, + expectedAcquisitionTime.getTime() + ".10", + expectedRenewalTime.getTime() + ".99" + }); + + Cookie cookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); + + SessionCookie sessionCookie = new SessionCookie(cookie); + + Assert.assertEquals("Wrong session acquisition time", expectedAcquisitionTime, sessionCookie.getSessionAcquisitionDate()); + Assert.assertEquals("Wrong session renewal time", expectedRenewalTime, sessionCookie.getSessionRenewalDate()); + } + // endregion Tests // region Private From 3df399126c353ec75bf1636681788769ee954c6a Mon Sep 17 00:00:00 2001 From: khrooick Date: Thu, 25 Jan 2018 14:28:43 +0100 Subject: [PATCH 3/9] fixed testCorruptedSessionRenewalTimeValueThrowsExceptionOnCookieParsing --- .../web/internal/cookies/SessionCookieTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java index 513f7e3af1d..dab90a4d91e 100644 --- a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java +++ b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java @@ -117,8 +117,8 @@ public void testCorruptedSessionRenewalTimeValueThrowsExceptionOnCookieParsing() String formattedCookie = SessionCookie.formatCookie(new String[] { sessionId, - "corruptedAcquisitionTime", - String.valueOf(sessionRenewalTime.getTime()) + String.valueOf(sessionAcquisitionTime.getTime()), + "corruptedValue" }); createSessionCookie(formattedCookie); From 35683159a6ee4fdfa510b4645a3ea94b9d6c8fe5 Mon Sep 17 00:00:00 2001 From: khrooick Date: Fri, 26 Jan 2018 12:31:38 +0100 Subject: [PATCH 4/9] remove unused sessionAcquisitionTime and sessionRenewalTime alltogether --- .../internal/cookies/HttpCookieFactory.java | 8 +- .../web/internal/cookies/SessionCookie.java | 127 +----------------- .../internal/cookies/SessionCookieTests.java | 111 ++------------- 3 files changed, 20 insertions(+), 226 deletions(-) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java index 1eaf7df6d35..5603b6f0057 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java @@ -21,7 +21,6 @@ package com.microsoft.applicationinsights.web.internal.cookies; -import java.util.Date; import javax.servlet.http.Cookie; import com.microsoft.applicationinsights.extensibility.context.SessionContext; import com.microsoft.applicationinsights.internal.util.DateTimeUtils; @@ -46,12 +45,9 @@ public class HttpCookieFactory { */ public static Cookie generateSessionHttpCookie( RequestTelemetryContext context, SessionContext sessionContext, int sessionTimeoutInMinutes) { - Date renewalDate = DateTimeUtils.getDateTimeNow(); - + String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionContext.getId(), - String.valueOf(context.getSessionCookie().getSessionAcquisitionDate().getTime()), - String.valueOf(renewalDate.getTime()) + sessionContext.getId() }); Cookie cookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java index 60ef870c515..f056be7076b 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java @@ -21,10 +21,7 @@ package com.microsoft.applicationinsights.web.internal.cookies; -import java.text.ParseException; -import java.util.*; import javax.servlet.http.Cookie; -import com.microsoft.applicationinsights.internal.util.DateTimeUtils; /** * Created by yonisha on 2/4/2015. @@ -33,7 +30,6 @@ public class SessionCookie extends com.microsoft.applicationinsights.web.interna // region Consts - private static final int UPDATE_TIMEOUT_IN_MINUTES = 5; public static final String COOKIE_NAME = "ai_session"; public static final int SESSION_DEFAULT_EXPIRATION_TIMEOUT_IN_MINUTES = 30; @@ -42,22 +38,6 @@ public class SessionCookie extends com.microsoft.applicationinsights.web.interna // region Members private String sessionId; - private Date acquisitionDate; - private Date renewalDate; - - private enum CookieFields { - SESSION_ID(0), - SESSION_ACQUISITION_DATE(1), - SESSION_LAST_UPDATE_DATE(2); - - private final int value; - - CookieFields(int value) { - this.value = value; - } - - public int getValue() { return value; } - } // endregion Members @@ -68,8 +48,8 @@ private enum CookieFields { * @param cookie The http servlet cookie. * @throws Exception Thrown when the cookie information cannot be parsed. */ - public SessionCookie(Cookie cookie) throws Exception { - parseCookie(cookie); + public SessionCookie(Cookie cookie) { + this(parseCookie(cookie)); } /** @@ -77,17 +57,7 @@ public SessionCookie(Cookie cookie) throws Exception { * @param sessionId The session ID. */ public SessionCookie(String sessionId) { - String now = String.valueOf(System.currentTimeMillis()); - String[] cookieRawValues = new String[] { sessionId, now, now }; - String formattedCookie = SessionCookie.formatCookie(cookieRawValues); - - Cookie cookie = new Cookie(COOKIE_NAME, formattedCookie); - - try { - parseCookie(cookie); - } catch (Exception e) { - // This exception is not expected in any case. - } + this.sessionId = sessionId; } // endregion Ctor @@ -102,53 +72,6 @@ public String getSessionId() { return sessionId; } - /** - * Gets the session acquisition date. - * @return The session acquisition date. - */ - public Date getSessionAcquisitionDate() { - return acquisitionDate; - } - - /** - * Gets the session renewal date. - * @return The session renewal date. - */ - public Date getSessionRenewalDate() { - return renewalDate; - } - - /** - * Determines if the session has expired. - * @param sessionTimeoutInMinutes The session timeout in minutes. - * @return True if the session has expired, false otherwise. - */ - public boolean isSessionExpired(int sessionTimeoutInMinutes) { - Date expirationDate = DateTimeUtils.addToDate( - this.getSessionRenewalDate(), - Calendar.MINUTE, - sessionTimeoutInMinutes); - Date now = new Date(); - - return now.after(expirationDate); - } - - /** - * Returns a value indicating whether the session cookie is up-to-date. - * Session cookie is considered up-to-date when the last renewal time is less than - * {@literal UPDATE_TIMEOUT_IN_MINUTES} minutes. - * @return True if the session cookie up-to-date. - */ - public boolean isSessionCookieUpToDate() { - Date expectedRenewalTime = DateTimeUtils.addToDate( - this.getSessionRenewalDate(), - Calendar.MINUTE, - UPDATE_TIMEOUT_IN_MINUTES); - Date now = new Date(); - - return now.before(expectedRenewalTime); - } - // endregion Public // region Private @@ -156,47 +79,11 @@ public boolean isSessionCookieUpToDate() { /** * Parses the given cookie. * @param cookie The cookie contains the session information. - * @throws Exception Thrown when the cookie information cannot be parsed. + * @return sessionId */ - private void parseCookie(Cookie cookie) throws Exception { - String[] split = cookie.getValue().split(RAW_COOKIE_SPLIT_DELIMITER); - - if (split.length < CookieFields.values().length) { - - // TODO: dedicated exception - String errorMessage = String.format("Session cookie is not in the correct format: %s", cookie.getValue()); - - throw new Exception(errorMessage); - } - - try { - sessionId = split[CookieFields.SESSION_ID.getValue()]; - acquisitionDate = parseDateWithBackwardCompatibility(split[CookieFields.SESSION_ACQUISITION_DATE.getValue()]); - renewalDate = parseDateWithBackwardCompatibility(split[CookieFields.SESSION_LAST_UPDATE_DATE.getValue()]); - } catch (Exception e) { - String errorMessage = String.format("Failed to parse session cookie with exception: %s", e.getMessage()); - - // TODO: dedicated exception - throw new Exception(errorMessage); - } - } - - /** - * JavaScript SDK was changed to store dates as long, rather than a readable date string. - * For backward compatibility, we first try to parse with the new format (time represented by long) and then backward - * compatibility for time represented by a string. - * @param dateStr The date to parse. - * @return The parsed date. - */ - private Date parseDateWithBackwardCompatibility(String dateStr) throws ParseException { - try { - Scanner s = new Scanner(dateStr); - s.useDelimiter("\\."); - return new Date(s.nextLong()); - } catch (NoSuchElementException e) { - return DateTimeUtils.parseRoundTripDateString(dateStr); - } + private static String parseCookie(Cookie cookie) { + String[] split = cookie.getValue().split(RAW_COOKIE_SPLIT_DELIMITER, 2); + return split[0]; } - // endregion Private } diff --git a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java index dab90a4d91e..bc88db9d15f 100644 --- a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java +++ b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java @@ -21,17 +21,12 @@ package com.microsoft.applicationinsights.web.internal.cookies; -import java.util.Date; import java.util.concurrent.ConcurrentHashMap; import javax.servlet.http.Cookie; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import com.microsoft.applicationinsights.internal.util.LocalStringsUtils; -import com.microsoft.applicationinsights.internal.util.DateTimeUtils; -import com.microsoft.applicationinsights.web.utils.HttpHelper; import com.microsoft.applicationinsights.extensibility.context.SessionContext; import com.microsoft.applicationinsights.web.internal.RequestTelemetryContext; @@ -47,8 +42,6 @@ public class SessionCookieTests { private static Cookie defaultCookie; private static String sessionId; - private static Date sessionAcquisitionTime; - private static Date sessionRenewalTime; private static SessionContext sessionContext; private static RequestTelemetryContext requestTelemetryContextMock; @@ -57,13 +50,9 @@ public class SessionCookieTests { @BeforeClass public static void initialize() throws Exception { sessionId = LocalStringsUtils.generateRandomId(true); - sessionAcquisitionTime = new Date(); - sessionRenewalTime = new Date(sessionAcquisitionTime.getTime() + 1000); - + String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionId, - String.valueOf(sessionAcquisitionTime.getTime()), - String.valueOf(sessionRenewalTime.getTime()) + sessionId }); defaultCookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); @@ -77,62 +66,23 @@ public static void initialize() throws Exception { } // region Tests - @Rule - public ExpectedException thrown= ExpectedException.none(); - + @Test public void testCookieParsedSuccessfully() throws Exception { SessionCookie sessionCookie = new SessionCookie(defaultCookie); Assert.assertEquals("Wrong session ID", sessionId, sessionCookie.getSessionId()); - Assert.assertEquals("Wrong session acquisition time", sessionAcquisitionTime, sessionCookie.getSessionAcquisitionDate()); - Assert.assertEquals("Wrong session renewal time", sessionRenewalTime, sessionCookie.getSessionRenewalDate()); - } - - @Test - public void testCookieExpiration() throws Exception { - String expiredFormattedCookie = HttpHelper.getFormattedSessionCookie(true); - Cookie expiredCookie = new Cookie(SessionCookie.COOKIE_NAME, expiredFormattedCookie); - SessionCookie sessionCookie = new SessionCookie(expiredCookie); - - Assert.assertTrue("Expired session expected.", sessionCookie.isSessionExpired(SessionCookie.SESSION_DEFAULT_EXPIRATION_TIMEOUT_IN_MINUTES)); } @Test - public void testCorruptedSessionAcquisitionTimeValueThrowsExceptionOnCookieParsing() throws Exception { - thrown.expect(Exception.class); - - String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionId, - "corruptedAcquisitionTime", - String.valueOf(sessionRenewalTime.getTime()) - }); - - createSessionCookie(formattedCookie); - } - - @Test - public void testCorruptedSessionRenewalTimeValueThrowsExceptionOnCookieParsing() throws Exception { - thrown.expect(Exception.class); - - String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionId, - String.valueOf(sessionAcquisitionTime.getTime()), - "corruptedValue" - }); - - createSessionCookie(formattedCookie); - } - - @Test - public void testUnexpectedCookieValuesCountThrowsException() throws Exception { - thrown.expect(Exception.class); - + public void testSingleCookieValue() { String formattedCookie = SessionCookie.formatCookie(new String[]{ - "singleValueCookie" + sessionId }); - createSessionCookie(formattedCookie); + SessionCookie sessionCookie = createSessionCookie(formattedCookie); + + Assert.assertEquals("Wrong session ID", sessionId, sessionCookie.getSessionId()); } @Test @@ -151,52 +101,13 @@ public void testSessionHttpCookieSetMaxAge() { Assert.assertEquals(sessionTimeoutInMinutes * 60, cookie.getMaxAge()); } - @Test - public void testCookieParsedSuccessfullyWithBackwardCompatibilityForTimeFormats() throws Exception { - String expectedAcquisitionTime = DateTimeUtils.formatAsRoundTripDate(sessionAcquisitionTime); - String expectedRenewalTime = DateTimeUtils.formatAsRoundTripDate(sessionRenewalTime); - - String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionId, - expectedAcquisitionTime, - expectedRenewalTime - }); - - Cookie cookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); - - SessionCookie sessionCookie = new SessionCookie(cookie); - - Assert.assertEquals("Wrong session acquisition time", expectedAcquisitionTime, DateTimeUtils.formatAsRoundTripDate(sessionCookie.getSessionAcquisitionDate())); - Assert.assertEquals("Wrong session renewal time", expectedRenewalTime, DateTimeUtils.formatAsRoundTripDate(sessionCookie.getSessionRenewalDate())); - } - - - @Test - public void testCookieParsedSuccessfullyWithMiliseconds() throws Exception { - Date expectedAcquisitionTime = new Date(); - Date expectedRenewalTime = new Date(); - - String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionId, - expectedAcquisitionTime.getTime() + ".10", - expectedRenewalTime.getTime() + ".99" - }); - - Cookie cookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); - - SessionCookie sessionCookie = new SessionCookie(cookie); - - Assert.assertEquals("Wrong session acquisition time", expectedAcquisitionTime, sessionCookie.getSessionAcquisitionDate()); - Assert.assertEquals("Wrong session renewal time", expectedRenewalTime, sessionCookie.getSessionRenewalDate()); - } - // endregion Tests // region Private - private void createSessionCookie(String cookieValue) throws Exception { - Cookie corruptedCookie = new Cookie(SessionCookie.COOKIE_NAME, cookieValue); - new SessionCookie(corruptedCookie); + private SessionCookie createSessionCookie(String cookieValue) { + Cookie cookie = new Cookie(SessionCookie.COOKIE_NAME, cookieValue); + return new SessionCookie(cookie); } // endregion Private From 127de5f205c8e234bcf2331850e3890ee12a35a0 Mon Sep 17 00:00:00 2001 From: khrooick Date: Thu, 8 Feb 2018 09:33:46 +0100 Subject: [PATCH 5/9] use substring instead of split --- .../web/internal/cookies/SessionCookie.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java index f056be7076b..792287ceae1 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java @@ -82,8 +82,13 @@ public String getSessionId() { * @return sessionId */ private static String parseCookie(Cookie cookie) { - String[] split = cookie.getValue().split(RAW_COOKIE_SPLIT_DELIMITER, 2); - return split[0]; + String value = cookie.getValue(); + int idx = value.indexOf(RAW_COOKIE_DELIMITER); + if (idx >= 0) { + return value.substring(0, idx); + } else { + return value; + } } // endregion Private } From 63087770ce2687b207ba5b3682099f85f8d8b9c6 Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Fri, 23 Mar 2018 08:49:48 -0700 Subject: [PATCH 6/9] Fix build break - missing curly braces --- .../applicationinsights/web/internal/cookies/SessionCookie.java | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java index 03764214820..75d850eda24 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java @@ -88,6 +88,7 @@ private static String parseCookie(Cookie cookie) { return value.substring(0, idx); } else { return value; + } } // endregion Private } \ No newline at end of file From ced5fc28fbc32605208fb2aba6a1d2836ecf6e52 Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Fri, 23 Mar 2018 08:59:11 -0700 Subject: [PATCH 7/9] SessionCookie.java: remove unused constant + cleanup --- .../web/internal/cookies/SessionCookie.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java index 75d850eda24..889da5254e5 100644 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java +++ b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookie.java @@ -28,25 +28,12 @@ */ public class SessionCookie extends com.microsoft.applicationinsights.web.internal.cookies.Cookie { - // region Consts - public static final String COOKIE_NAME = "ai_session"; - public static final int SESSION_DEFAULT_EXPIRATION_TIMEOUT_IN_MINUTES = 30; - - // endregion Consts - - // region Members - private String sessionId; - // endregion Members - - // region Ctor - /** * Constructs new SessionCookie object from the given cookie. * @param cookie The http servlet cookie. - * @throws Exception Thrown when the cookie information cannot be parsed. */ public SessionCookie(Cookie cookie) { this(parseCookie(cookie)); @@ -60,10 +47,6 @@ public SessionCookie(String sessionId) { this.sessionId = sessionId; } - // endregion Ctor - - // region Public - /** * Gets the session id. * @return The session id. @@ -72,10 +55,6 @@ public String getSessionId() { return sessionId; } - // endregion Public - - // region Private - /** * Parses the given cookie. * @param cookie The cookie contains the session information. @@ -90,5 +69,4 @@ private static String parseCookie(Cookie cookie) { return value; } } - // endregion Private } \ No newline at end of file From fc433f75c72f3af82265478bb9b1bb2d2e6b4a14 Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Fri, 23 Mar 2018 09:13:44 -0700 Subject: [PATCH 8/9] Remove HttpFactory class as it's not used. --- .../internal/cookies/HttpCookieFactory.java | 91 ------------------- .../internal/cookies/SessionCookieTests.java | 16 ---- .../web/internal/cookies/UserCookieTests.java | 14 --- 3 files changed, 121 deletions(-) delete mode 100644 web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java diff --git a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java b/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java deleted file mode 100644 index 5603b6f0057..00000000000 --- a/web/src/main/java/com/microsoft/applicationinsights/web/internal/cookies/HttpCookieFactory.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.microsoft.applicationinsights.web.internal.cookies; - -import javax.servlet.http.Cookie; -import com.microsoft.applicationinsights.extensibility.context.SessionContext; -import com.microsoft.applicationinsights.internal.util.DateTimeUtils; -import com.microsoft.applicationinsights.web.internal.RequestTelemetryContext; - -/** - * Created by yonisha on 2/26/2015. - */ -public class HttpCookieFactory { - - private static final int COOKIE_VERSION = 1; - public static String COOKIE_PATH_ALL_URL = "/"; - - // region Public - - /** - * Generates session http cookie. - * @param context The context. - * @param sessionContext The request session context. - * @param sessionTimeoutInMinutes The session timeout in minutes. - * @return Session http cookie. - */ - public static Cookie generateSessionHttpCookie( - RequestTelemetryContext context, SessionContext sessionContext, int sessionTimeoutInMinutes) { - - String formattedCookie = SessionCookie.formatCookie(new String[] { - sessionContext.getId() - }); - - Cookie cookie = new Cookie(SessionCookie.COOKIE_NAME, formattedCookie); - - cookie.setMaxAge(sessionTimeoutInMinutes * 60); - - setCommonProperties(cookie); - - return cookie; - } - - /** - * Generates user http cookie. - * @param context The context. - * @return User http cookie. - */ - public static Cookie generateUserHttpCookie(RequestTelemetryContext context) { - String formattedCookie = UserCookie.formatCookie(new String[] { - context.getUserCookie().getUserId(), - DateTimeUtils.formatAsRoundTripDate(context.getUserCookie().getAcquisitionDate()) - }); - - Cookie cookie = new Cookie(UserCookie.COOKIE_NAME, formattedCookie); - cookie.setMaxAge(Integer.MAX_VALUE); - - setCommonProperties(cookie); - - return cookie; - } - - // endregion Public - - // region Private - - private static void setCommonProperties(Cookie cookie) { - cookie.setPath(COOKIE_PATH_ALL_URL); - cookie.setVersion(COOKIE_VERSION); - } - - // endregion Private -} diff --git a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java index bc88db9d15f..a70d98bf52e 100644 --- a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java +++ b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/SessionCookieTests.java @@ -85,22 +85,6 @@ public void testSingleCookieValue() { Assert.assertEquals("Wrong session ID", sessionId, sessionCookie.getSessionId()); } - @Test - public void testSessionHttpCookiePathSetForAllPages() { - Cookie cookie = HttpCookieFactory.generateSessionHttpCookie(requestTelemetryContextMock, sessionContext, 10); - - Assert.assertEquals("Path should catch all urls", HttpCookieFactory.COOKIE_PATH_ALL_URL, cookie.getPath()); - } - - @Test - public void testSessionHttpCookieSetMaxAge() { - final int sessionTimeoutInMinutes = 10; - - Cookie cookie = HttpCookieFactory.generateSessionHttpCookie(requestTelemetryContextMock, sessionContext, sessionTimeoutInMinutes); - - Assert.assertEquals(sessionTimeoutInMinutes * 60, cookie.getMaxAge()); - } - // endregion Tests // region Private diff --git a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/UserCookieTests.java b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/UserCookieTests.java index aeef732b4f4..e21ef411b8b 100644 --- a/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/UserCookieTests.java +++ b/web/src/test/java/com/microsoft/applicationinsights/web/internal/cookies/UserCookieTests.java @@ -102,20 +102,6 @@ public void testUnexpectedCookieValuesCountThrowsException() throws Exception { createUserCookie(formattedCookie); } - @Test - public void testUserHttpCookiePathSetForAllPages() { - Cookie cookie = HttpCookieFactory.generateUserHttpCookie(requestTelemetryContextMock); - - Assert.assertEquals("Path should catch all urls", HttpCookieFactory.COOKIE_PATH_ALL_URL, cookie.getPath()); - } - - @Test - public void testUserHttpCookieSetMaxAge() { - Cookie cookie = HttpCookieFactory.generateUserHttpCookie(requestTelemetryContextMock); - - Assert.assertEquals("Cookie age should be set to max value.", Integer.MAX_VALUE, cookie.getMaxAge()); - } - // endregion Tests // region Private From dad16e15c557efaca8756f54b54396ee8c229bcc Mon Sep 17 00:00:00 2001 From: Gustavo Lima Date: Fri, 23 Mar 2018 09:43:44 -0700 Subject: [PATCH 9/9] updated changelog --- CHANGELOG.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c6f6ae574..ae0025b5607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,21 +1,23 @@ # CHANGELOG ## Version 2.0.2 -- Fix #616, added a way to have real time SDK Logs when logging on File. -- Fix #609, fixes the inaccurate timestamp recorded with JMX Metrics. +- Fix [#577](https://github.com/Microsoft/ApplicationInsights-Java/issues/577), removed HttpFactory class as it was not being used. +- Fixed issue with sessionId not being set in request telemetry due to date parsing issues. +- Fix [#616](https://github.com/Microsoft/ApplicationInsights-Java/issues/616), added a way to have real time SDK Logs when logging on File. +- Fix [#609](https://github.com/Microsoft/ApplicationInsights-Java/issues/609), fixes the inaccurate timestamp recorded with JMX Metrics. - Added a way to configure MaxInstantRetries from XML. - Added the ability to have cold SDK initialization (no logs except critical logAlways messages) - Fix issue when dependency start time was not being recorded correctly. -- Fixed #533 HTTP Dependency Telemetry now matches with .NET SDK. +- Fixed [#533](https://github.com/Microsoft/ApplicationInsights-Java/issues/533) HTTP Dependency Telemetry now matches with .NET SDK. - Introduced public method `httpMethodFinishedWithPath(String identifier, String method, String path, String correlationId, String uri, String target, int result, long delta)` to support instrumentation of Path of URI in HTTP requests. - `httpMethodFinished(String identifier, String method, String correlationId, String uri, String target, int result, int delta)` is now marked as deprecated - Logger Messages now being pushed as custom dimension when reporting exceptions via Loggers. (#400) - Enhanced Log4j2 appender to support basic parameters including Filters, Layouts and includeException. (#348) - Fixed PageView telemetry data not being reported. -- Fixed Issue #526 (NPE in MapUtil.copy()) -- Fixed Issue #513 (Memory leak in SDKShutdownActivity). This fix upgrades our Servlet version from 2.5 to 3.0. The SDK must now be run on an application server supporting Servlet 3.0. -- Fixed Issue #504 (SDK initialization happens twice) to improve startup performance. +- Fixed Issue [#526](https://github.com/Microsoft/ApplicationInsights-Java/issues/526) (NPE in MapUtil.copy()) +- Fixed Issue [#513](https://github.com/Microsoft/ApplicationInsights-Java/issues/513) (Memory leak in SDKShutdownActivity). This fix upgrades our Servlet version from 2.5 to 3.0. The SDK must now be run on an application server supporting Servlet 3.0. +- Fixed Issue [#504](https://github.com/Microsoft/ApplicationInsights-Java/issues/504) (SDK initialization happens twice) to improve startup performance. ## Version 2.0.1 - Fix Inconsistency in artifact names in POM files