Skip to content
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,80 +21,32 @@

package com.microsoft.applicationinsights.web.internal.cookies;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.http.Cookie;
import com.microsoft.applicationinsights.internal.util.DateTimeUtils;

/**
* Created by yonisha on 2/4/2015.
*/
public class SessionCookie extends com.microsoft.applicationinsights.web.internal.cookies.Cookie {

// 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;

// endregion Consts

// 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

// 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) throws Exception {
parseCookie(cookie);
public SessionCookie(Cookie cookie) {
this(parseCookie(cookie));
}

/**
* Constructs new SessionCookie with the given session ID.
* @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

// region Public

/**
* Gets the session id.
* @return The session id.
Expand All @@ -103,99 +55,18 @@ 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

/**
* 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.toString());

// TODO: dedicated exception
throw new Exception(errorMessage);
private static String parseCookie(Cookie cookie) {
String value = cookie.getValue();
int idx = value.indexOf(RAW_COOKIE_DELIMITER);
if (idx >= 0) {
return value.substring(0, idx);
} else {
return value;
}
}

/**
* 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 {
return new Date(Long.parseLong(dateStr));
} catch (NumberFormatException e) {
return DateTimeUtils.parseRoundTripDateString(dateStr);
}
}

// endregion Private
}
}
Loading