use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.
the class CookieUtils method createClusterCookie.
public static Optional<TargetCookie> createClusterCookie(String tntId) {
if (tntId == null) {
return Optional.empty();
}
TargetCookie targetCookie = null;
String locationHint = locationHintFromTntId(tntId);
if (locationHint != null) {
targetCookie = new TargetCookie(CLUSTER_COOKIE_NAME, locationHint, CLUSTER_LOCATION_HINT_MAX_AGE);
}
return Optional.ofNullable(targetCookie);
}
use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.
the class CookieUtils method parseTargetCookies.
public static Map<String, String> parseTargetCookies(String targetCookie) {
if (isEmpty(targetCookie)) {
return Collections.EMPTY_MAP;
}
int nowInSeconds = getNowInSeconds();
Map<String, String> internalTargetCookies = new HashMap<>();
final String[] rawInternalCookies = targetCookie.split(Pattern.quote(COOKIE_VALUE_SEPARATOR));
for (final String rawInternalCookie : rawInternalCookies) {
if (isEmpty(rawInternalCookie)) {
break;
}
final TargetCookie internalCookie = deserializeInternalCookie(rawInternalCookie);
if (internalCookie != null && internalCookie.getMaxAge() > nowInSeconds) {
internalTargetCookies.put(internalCookie.getName(), internalCookie.getValue());
}
}
return internalTargetCookies;
}
use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.
the class TargetDeliveryRequestTest method testTargetDeliveryRequestWithCookies.
@Test
void testTargetDeliveryRequestWithCookies() throws NoSuchFieldException {
setup(true);
Context context = getContext();
PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
ExecuteRequest executeRequest = getMboxExecuteRequest();
Map<String, CustomerState> customerIds = getCustomerIds();
List<Notification> mboxNotifications = getMboxNotifications();
List<TargetCookie> testCookies = getTestCookies();
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).customerIds(customerIds).notifications(mboxNotifications).trackingServer(TEST_TRACKING_SERVER).cookies(testCookies).thirdPartyId(TEST_THIRD_PARTY_ID).build();
assertEquals(TEST_SESSION_ID, targetDeliveryRequest.getSessionId());
assertEquals(prefetchRequest, targetDeliveryRequest.getDeliveryRequest().getPrefetch());
assertEquals(executeRequest, targetDeliveryRequest.getDeliveryRequest().getExecute());
assertEquals(context, targetDeliveryRequest.getDeliveryRequest().getContext());
assertEquals(mboxNotifications, targetDeliveryRequest.getDeliveryRequest().getNotifications());
verifyId(customerIds, targetDeliveryRequest);
verifyVisitorValues(targetDeliveryRequest);
verifyAnalyticsValues(targetDeliveryRequest);
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
verifyServerStateAndNewCookie(targetDeliveryResponse, TEST_SESSION_ID);
verifyVisitorState(targetDeliveryResponse, customerIds);
}
use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.
the class TargetDeliveryRequestTest method testTargetDeliveryRequestWithExpiredCookies.
@Test
void testTargetDeliveryRequestWithExpiredCookies() throws NoSuchFieldException {
setup(true);
Context context = getContext();
PrefetchRequest prefetchRequest = getPrefetchViewsRequest();
ExecuteRequest executeRequest = getMboxExecuteRequest();
Map<String, CustomerState> customerIds = getCustomerIds();
List<Notification> mboxNotifications = getMboxNotifications();
List<TargetCookie> expiredSessionCookie = getExpiredSessionCookie();
TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(context).prefetch(prefetchRequest).execute(executeRequest).customerIds(customerIds).notifications(mboxNotifications).trackingServer(TEST_TRACKING_SERVER).cookies(expiredSessionCookie).thirdPartyId(TEST_THIRD_PARTY_ID).build();
String newSessionId = targetDeliveryRequest.getSessionId();
assertNotEquals(TEST_SESSION_ID, newSessionId);
assertEquals(TEST_TNT_ID, targetDeliveryRequest.getDeliveryRequest().getId().getTntId());
assertEquals(prefetchRequest, targetDeliveryRequest.getDeliveryRequest().getPrefetch());
assertEquals(executeRequest, targetDeliveryRequest.getDeliveryRequest().getExecute());
assertEquals(context, targetDeliveryRequest.getDeliveryRequest().getContext());
assertEquals(mboxNotifications, targetDeliveryRequest.getDeliveryRequest().getNotifications());
assertEquals(prefetchRequest, targetDeliveryRequest.getDeliveryRequest().getPrefetch());
assertEquals(executeRequest, targetDeliveryRequest.getDeliveryRequest().getExecute());
assertEquals(context, targetDeliveryRequest.getDeliveryRequest().getContext());
assertEquals(mboxNotifications, targetDeliveryRequest.getDeliveryRequest().getNotifications());
verifyAnalyticsValues(targetDeliveryRequest);
TargetDeliveryResponse targetDeliveryResponse = targetJavaClient.getOffers(targetDeliveryRequest);
verifyServerStateAndNewCookie(targetDeliveryResponse, newSessionId);
verifyVisitorState(targetDeliveryResponse, customerIds);
}
use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.
the class TargetTestDeliveryRequestUtils method getExpiredSessionCookie.
public static List<TargetCookie> getExpiredSessionCookie() {
int timeNow = (int) (System.currentTimeMillis() / 1000);
int sessionExpirationTime = timeNow - 1;
int tntIdExpirationTime = timeNow + DEVICE_ID_COOKIE_MAX_AGE;
String cookieValue = "session#430a140336d545daacde53af9636eef5#" + sessionExpirationTime + "|PC#" + TEST_TNT_ID + "#" + tntIdExpirationTime;
TargetCookie targetCookie = new TargetCookie(COOKIE_NAME, cookieValue, timeNow);
List<TargetCookie> cookies = new ArrayList<>();
cookies.add(targetCookie);
return cookies;
}
Aggregations