Search in sources :

Example 1 with TimingTool

use of com.adobe.target.edge.client.utils.TimingTool in project target-java-sdk by adobe.

the class DefaultTargetService method executeNotification.

@Override
public ResponseStatus executeNotification(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    NotificationService.setBeaconToFalse(deliveryRequest.getDeliveryRequest());
    TargetDeliveryResponse targetDeliveryResponse;
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    ResponseWrapper response = callDeliveryApi(deliveryRequest);
    targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
    telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
    return new ResponseStatus(response.getHttpResponse().getStatus(), response.getHttpResponse().getStatusText());
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) ResponseStatus(com.adobe.target.edge.client.http.ResponseStatus) ResponseWrapper(com.adobe.target.edge.client.http.ResponseWrapper) Telemetry(com.adobe.target.delivery.v1.model.Telemetry)

Example 2 with TimingTool

use of com.adobe.target.edge.client.utils.TimingTool in project target-java-sdk by adobe.

the class DefaultTargetService method executeRequestAsync.

@Override
public CompletableFuture<TargetDeliveryResponse> executeRequestAsync(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    CompletableFuture<ResponseWrapper<DeliveryResponse>> responseCompletableFuture = callDeliveryApiAsync(deliveryRequest);
    return responseCompletableFuture.thenApply(response -> {
        TargetDeliveryResponse targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
        telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
        return targetDeliveryResponse;
    });
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) ResponseWrapper(com.adobe.target.edge.client.http.ResponseWrapper) Telemetry(com.adobe.target.delivery.v1.model.Telemetry)

Example 3 with TimingTool

use of com.adobe.target.edge.client.utils.TimingTool in project target-java-sdk by adobe.

the class DefaultTargetService method executeNotificationAsync.

@Override
public CompletableFuture<ResponseStatus> executeNotificationAsync(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    NotificationService.setBeaconToFalse(deliveryRequest.getDeliveryRequest());
    Telemetry telemetry = telemetryService.getTelemetry();
    if (!telemetry.getEntries().isEmpty()) {
        deliveryRequest.getDeliveryRequest().setTelemetry(telemetry);
    }
    CompletableFuture<ResponseWrapper<DeliveryResponse>> responseCompletableFuture = callDeliveryApiAsync(deliveryRequest);
    return responseCompletableFuture.thenApply(response -> {
        TargetDeliveryResponse targetDeliveryResponse = getTargetDeliveryResponse(deliveryRequest, response.getHttpResponse());
        telemetryService.addTelemetry(deliveryRequest, timer, targetDeliveryResponse, response.getParsingTime(), response.getResponseSize());
        return new ResponseStatus(response.getHttpResponse().getStatus(), response.getHttpResponse().getStatusText());
    });
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) ResponseStatus(com.adobe.target.edge.client.http.ResponseStatus) ResponseWrapper(com.adobe.target.edge.client.http.ResponseWrapper) Telemetry(com.adobe.target.delivery.v1.model.Telemetry)

Example 4 with TimingTool

use of com.adobe.target.edge.client.utils.TimingTool in project target-java-sdk by adobe.

the class OnDeviceDecisioningService method executeRequest.

public TargetDeliveryResponse executeRequest(TargetDeliveryRequest deliveryRequest) {
    TimingTool timer = new TimingTool();
    timer.timeStart(TIMING_EXECUTE_REQUEST);
    DeliveryRequest delivRequest = deliveryRequest.getDeliveryRequest();
    String requestId = delivRequest.getRequestId();
    if (requestId == null) {
        requestId = UUID.randomUUID().toString();
    }
    OnDeviceDecisioningRuleSet ruleSet = this.ruleLoader.getLatestRules();
    if (ruleSet == null) {
        DeliveryResponse deliveryResponse = new DeliveryResponse().client(clientConfig.getClient()).requestId(requestId).id(delivRequest.getId()).status(HttpStatus.SC_SERVICE_UNAVAILABLE);
        return new TargetDeliveryResponse(deliveryRequest, deliveryResponse, HttpStatus.SC_SERVICE_UNAVAILABLE, "Local-decisioning rules not available");
    }
    Map<String, Object> requestContext = new HashMap<>(timeParamsCollator.collateParams(deliveryRequest, null));
    geoLookupIfNeeded(deliveryRequest, ruleSet.isGeoTargetingEnabled());
    collateParams(requestContext, REQUEST_PARAMS_COLLATORS, deliveryRequest, null);
    TraceHandler traceHandler = null;
    if (delivRequest.getTrace() != null) {
        traceHandler = new TraceHandler(this.clientConfig, this.ruleLoader, this.mapper, ruleSet, deliveryRequest);
    }
    Set<String> responseTokens = new HashSet<>(ruleSet.getResponseTokens());
    TargetDeliveryResponse targetResponse = buildDeliveryResponse(deliveryRequest, requestId);
    String visitorId = getOrCreateVisitorId(deliveryRequest, targetResponse);
    List<RequestDetails> prefetchRequests = detailsFromPrefetch(delivRequest);
    handleDetails(prefetchRequests, requestContext, deliveryRequest, visitorId, responseTokens, traceHandler, ruleSet, targetResponse.getResponse().getPrefetch(), null, null);
    List<RequestDetails> executeRequests = detailsFromExecute(delivRequest);
    List<Notification> notifications = new ArrayList<>();
    handleDetails(executeRequests, requestContext, deliveryRequest, visitorId, responseTokens, traceHandler, ruleSet, null, targetResponse.getResponse().getExecute(), notifications);
    telemetryService.addTelemetry(deliveryRequest, timer, targetResponse);
    notificationService.buildNotifications(deliveryRequest, targetResponse, notifications);
    if (this.clientConfig.isLogRequests()) {
        logger.debug(targetResponse.toString());
    }
    return targetResponse;
}
Also used : TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) DeliveryRequest(com.adobe.target.delivery.v1.model.DeliveryRequest) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) DeliveryResponse(com.adobe.target.delivery.v1.model.DeliveryResponse) RequestDetails(com.adobe.target.delivery.v1.model.RequestDetails) Notification(com.adobe.target.delivery.v1.model.Notification) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse)

Example 5 with TimingTool

use of com.adobe.target.edge.client.utils.TimingTool in project target-java-sdk by adobe.

the class DefaultRuleLoader method loadRules.

// For unit test mocking
protected boolean loadRules(ClientConfig clientConfig) {
    try {
        TargetExceptionHandler handler = clientConfig.getExceptionHandler();
        GetRequest request = generateRequest(clientConfig);
        TimingTool timer = new TimingTool();
        timer.timeStart(TIMING_EXECUTE_REQUEST);
        HttpResponse<OnDeviceDecisioningRuleSet> response = executeRequest(request);
        double artifactDownloadTime = timer.timeEnd(TIMING_EXECUTE_REQUEST);
        double artifactDownloadTimeRounded = MathUtils.roundDouble(artifactDownloadTime, 2);
        this.telemetryService.addTelemetry(artifactDownloadTimeRounded);
        if (response.getStatus() != 200) {
            if (response.getStatus() == 304) {
                // Not updated, skip
                return true;
            }
            String message = "Received invalid HTTP response while getting local-decisioning rule set: " + response.getStatus() + " : " + response.getStatusText() + " from " + getLocalDecisioningUrl(clientConfig);
            logger.warn(message);
            if (handler != null) {
                handler.handleException(new TargetClientException(message));
            }
            return false;
        }
        OnDeviceDecisioningRuleSet ruleSet = response.getBody();
        String invalidMessage = invalidRuleSetMessage(ruleSet, response);
        if (invalidMessage == null) {
            setLatestETag(response.getHeaders().getFirst("ETag"));
            setLatestRules(ruleSet);
            OnDeviceDecisioningHandler localHandler = clientConfig.getOnDeviceDecisioningHandler();
            if (localHandler != null) {
                localHandler.artifactDownloadSucceeded(request == null ? null : request.asBytes().getBody());
            }
            logger.trace("rulesList={}", latestRules);
            return true;
        } else {
            logger.warn(invalidMessage);
            if (handler != null) {
                handler.handleException(new TargetClientException(invalidMessage));
            }
            return false;
        }
    } catch (Throwable t) {
        String message = "Hit exception while getting local-decisioning rule set from: " + getLocalDecisioningUrl(clientConfig);
        logger.warn(message, t);
        TargetExceptionHandler handler = clientConfig.getExceptionHandler();
        if (handler != null) {
            handler.handleException(new TargetClientException(message, t));
        }
        return false;
    }
}
Also used : TargetClientException(com.adobe.target.edge.client.exception.TargetClientException) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetExceptionHandler(com.adobe.target.edge.client.exception.TargetExceptionHandler) OnDeviceDecisioningHandler(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)

Aggregations

TimingTool (com.adobe.target.edge.client.utils.TimingTool)12 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)11 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)8 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)7 Context (com.adobe.target.delivery.v1.model.Context)6 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)6 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)6 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)6 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)6 Test (org.junit.jupiter.api.Test)6 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)5 Property (com.adobe.target.delivery.v1.model.Property)5 Telemetry (com.adobe.target.delivery.v1.model.Telemetry)5 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)4 ResponseWrapper (com.adobe.target.edge.client.http.ResponseWrapper)3 ResponseStatus (com.adobe.target.edge.client.http.ResponseStatus)2 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)2 DeliveryRequest (com.adobe.target.delivery.v1.model.DeliveryRequest)1 Notification (com.adobe.target.delivery.v1.model.Notification)1