This is an automated email from the ASF dual-hosted git repository. shuber pushed a commit to branch unomi-1.5.x in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 1bad997aae5c7e39b3f04e48feb16c263f701b81 Author: Shir <[email protected]> AuthorDate: Tue Jul 7 16:59:37 2020 +0300 Add profileId to the ContextRequest, and create profile with this id if provided (cherry picked from commit 749a52ff9345bb21ece54a1cc6efb44984387c77) --- .../java/org/apache/unomi/api/ContextRequest.java | 18 ++++++++++++++++++ .../java/org/apache/unomi/web/ContextServlet.java | 20 ++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/org/apache/unomi/api/ContextRequest.java b/api/src/main/java/org/apache/unomi/api/ContextRequest.java index 6a6c79a..1a59dde 100644 --- a/api/src/main/java/org/apache/unomi/api/ContextRequest.java +++ b/api/src/main/java/org/apache/unomi/api/ContextRequest.java @@ -64,6 +64,7 @@ public class ContextRequest { private Profile profileOverrides; private Map<String, Object> sessionPropertiesOverrides; private String sessionId; + private String profileId; /** * Retrieves the source of the context request. @@ -242,4 +243,21 @@ public class ContextRequest { public void setSessionId(String sessionId) { this.sessionId = sessionId; } + + /** + * Retrieve the profileId passed along with the request. All events will be processed with this profileId as a + * default + * @return the identifier for the profile + */ + public String getProfileId() { + return profileId; + } + + /** + * Sets the profileId in the request. + * @param profileId an unique identifier for the profile + */ + public void setProfileId(String profileId) { + this.profileId = profileId; + } } diff --git a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java index 3604162..1557f5a 100644 --- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java +++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java @@ -107,6 +107,7 @@ public class ContextServlet extends HttpServlet { ContextRequest contextRequest = null; String scope = null; String sessionId = null; + String profileId = null; String stringPayload = HttpUtils.getPayload(request); if (stringPayload != null) { ObjectMapper mapper = CustomObjectMapper.getObjectMapper(); @@ -122,18 +123,21 @@ public class ContextServlet extends HttpServlet { scope = contextRequest.getSource().getScope(); } sessionId = contextRequest.getSessionId(); + profileId = contextRequest.getProfileId(); } if (sessionId == null) { sessionId = request.getParameter("sessionId"); } - // Get profile id from the cookie - String cookieProfileId = ServletCommon.getProfileIdCookieValue(request, profileIdCookieName); + if (profileId == null) { + // Get profile id from the cookie + profileId = ServletCommon.getProfileIdCookieValue(request, profileIdCookieName); + } - if (cookieProfileId == null && sessionId == null && personaId == null) { + if (profileId == null && sessionId == null && personaId == null) { ((HttpServletResponse)response).sendError(HttpServletResponse.SC_BAD_REQUEST, "Check logs for more details"); - logger.error("Couldn't find cookieProfileId, sessionId or personaId in incoming request! Stopped processing request. See debug level for more information"); + logger.error("Couldn't find profileId, sessionId or personaId in incoming request! Stopped processing request. See debug level for more information"); if (logger.isDebugEnabled()) { logger.debug("Request dump: {}", HttpUtils.dumpRequestInfo(request)); } @@ -147,16 +151,16 @@ public class ContextServlet extends HttpServlet { boolean invalidateProfile = request.getParameter("invalidateProfile") != null ? new Boolean(request.getParameter("invalidateProfile")) : false; - if (cookieProfileId == null || invalidateProfile) { + if (profileId == null || invalidateProfile) { // no profileId cookie was found or the profile has to be invalidated, we generate a new one and create the profile in the profile service profile = createNewProfile(null, response, timestamp); profileCreated = true; } else { - profile = profileService.load(cookieProfileId); + profile = profileService.load(profileId); if (profile == null) { // this can happen if we have an old cookie but have reset the server, // or if we merged the profiles and somehow this cookie didn't get updated. - profile = createNewProfile(null, response, timestamp); + profile = createNewProfile(profileId, response, timestamp); profileCreated = true; } else { Changes changesObject = checkMergedProfile(response, profile, session); @@ -324,7 +328,7 @@ public class ContextServlet extends HttpServlet { } private Changes handleRequest(ContextRequest contextRequest, Session session, Profile profile, ContextResponse data, - ServletRequest request, ServletResponse response, Date timestamp) { + ServletRequest request, ServletResponse response, Date timestamp) { Changes changes = ServletCommon.handleEvents(contextRequest.getEvents(), session, profile, request, response, timestamp, privacyService, eventService); data.setProcessedEvents(changes.getProcessedItems());
