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());
}
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;
});
}
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());
});
}
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;
}
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;
}
}
Aggregations