Search in sources :

Example 6 with TargetCookie

use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.

the class TargetTestDeliveryRequestUtils method getTestCookies.

public static List<TargetCookie> getTestCookies() {
    int timeNow = (int) (System.currentTimeMillis() / 1000);
    Optional<TargetCookie> targetCookie = CookieUtils.createTargetCookie(TEST_SESSION_ID, TEST_TNT_ID);
    String visitorValue = "-1330315163%7CMCIDTS%7C18145%7CMCMID%7C" + TargetDeliveryRequestTest.TEST_MCID + "%7CMCAAMLH-1567731426%7C9%7CMCAAMB-1568280923%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xz" + "PWQmdj0y%7CMCOPTOUT-1567683323s%7CNONE%7CMCAID%7CNONE%7CMCCIDH%7C1806392961";
    TargetCookie visitorCookie = null;
    try {
        visitorCookie = new TargetCookie("AMCV_" + URLEncoder.encode(TEST_ORG_ID, "UTF-8"), visitorValue, timeNow + SESSION_ID_COOKIE_MAX_AGE);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    List<TargetCookie> cookies = new ArrayList<>();
    Collections.addAll(cookies, targetCookie.get(), visitorCookie);
    return cookies;
}
Also used : TargetCookie(com.adobe.target.edge.client.model.TargetCookie) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with TargetCookie

use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.

the class CookieUtils method getSessionId.

public static String getSessionId(final Map<String, TargetCookie> parseCookies) {
    final TargetCookie cookie = parseCookies.get(SESSION_ID_COOKIE_NAME);
    String sessionId;
    if (cookie != null && !isEmpty(cookie.getValue())) {
        sessionId = cookie.getValue();
    } else {
        sessionId = UUID.randomUUID().toString().replaceAll("-", "");
    }
    return sessionId;
}
Also used : TargetCookie(com.adobe.target.edge.client.model.TargetCookie)

Example 8 with TargetCookie

use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.

the class CookieUtils method createTargetCookie.

public static Optional<TargetCookie> createTargetCookie(String sessionId, String deviceId) {
    final int nowInSeconds = getNowInSeconds();
    final StringBuilder targetCookieValue = new StringBuilder();
    int expires = 0;
    expires = createSessionId(sessionId, nowInSeconds, targetCookieValue, expires);
    expires = createDeviceId(deviceId, nowInSeconds, targetCookieValue, expires);
    TargetCookie targetCookie = null;
    String cookieValue = targetCookieValue.toString();
    int maxAge = expires == 0 ? 0 : expires - nowInSeconds;
    if (isNotEmpty(cookieValue)) {
        targetCookie = new TargetCookie(COOKIE_NAME, cookieValue, maxAge);
    }
    return Optional.ofNullable(targetCookie);
}
Also used : TargetCookie(com.adobe.target.edge.client.model.TargetCookie)

Example 9 with TargetCookie

use of com.adobe.target.edge.client.model.TargetCookie in project target-java-sdk by adobe.

the class CookieUtils method getDeviceId.

public static String getDeviceId(final Map<String, TargetCookie> parseCookies) {
    String returnValue = null;
    final TargetCookie cookie = parseCookies.get(DEVICE_ID_COOKIE_NAME);
    if (cookie != null) {
        returnValue = cookie.getValue();
    }
    return returnValue;
}
Also used : TargetCookie(com.adobe.target.edge.client.model.TargetCookie)

Aggregations

TargetCookie (com.adobe.target.edge.client.model.TargetCookie)9 CustomerState (com.adobe.experiencecloud.ecid.visitor.CustomerState)2 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)2 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)2 Test (org.junit.jupiter.api.Test)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1