Skip to content

Commit 4bb3c5a

Browse files
authored
Use new addCookie API with 'isHostOnly=true' when available
1 parent 69b7a51 commit 4bb3c5a

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/DeepLinkModule/javasource/deeplink/implementation/handler/SessionHandler.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22

33
import com.mendix.core.Core;
44
import com.mendix.m2ee.api.IMxRuntimeResponse;
5+
import com.mendix.core.conf.RuntimeVersion;
56
import com.mendix.systemwideinterfaces.core.ISession;
7+
import java.lang.reflect.Method;
8+
import java.lang.reflect.InvocationTargetException;
69

710
public class SessionHandler {
811

912
private static final String XAS_ID = "XASID";
1013

1114
public static ISession GetFreshGuestSession(IMxRuntimeResponse response) throws Exception {
12-
1315
ISession session = Core.initializeGuestSession();
1416
setCookies(response, session);
1517

1618
return session;
1719
}
1820

19-
private static void setCookies(IMxRuntimeResponse response, ISession session) {
20-
response.addCookie(Core.getConfiguration().getSessionIdCookieName(), session.getId().toString(), "/", "", -1, true);
21-
response.addCookie(XAS_ID, "0."+Core.getXASId(),"/", "", -1, true);
21+
private static void setCookies(IMxRuntimeResponse response, ISession session) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
22+
String[] mxVersion = RuntimeVersion.getInstance().toString().split("\\.");
23+
if (Integer.parseInt(mxVersion[0]) >=9 && Integer.parseInt(mxVersion[1]) >= 20) {
24+
// use reflection to call the addCookie method with the 7th parameter for 'isHostOnly', which was added in 9.20
25+
@SuppressWarnings("rawtypes")
26+
Class[] methodSignature = {String.class, String.class, String.class, String.class, int.class, boolean.class, boolean.class};
27+
Method addCookie = response.getClass().getMethod("addCookie", methodSignature);
28+
addCookie.invoke(response, Core.getConfiguration().getSessionIdCookieName(), session.getId().toString(), "/", "", -1, true, true);
29+
} else {
30+
response.addCookie(Core.getConfiguration().getSessionIdCookieName(), session.getId().toString(), "/", "", -1, true);
31+
}
2232
}
23-
33+
2434
}

0 commit comments

Comments
 (0)