Skip to content

Commit

Permalink
rest mantionf of Kentico
Browse files Browse the repository at this point in the history
  • Loading branch information
Simply007 committed Oct 3, 2022
1 parent e8d6dae commit 13dfec3
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 121 deletions.
4 changes: 2 additions & 2 deletions delivery-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ You need to instantiate the Delivery client with the constructor that disables t
DeliveryClient client = new DeliveryClient(new DeliveryOptions(AppConfig.KONTENT_PROJECT_ID), null);
```

See it [used in a sample app](../sample-app-android/src/main/java/com/github/kentico/delivery_android_sample/data/source/DeliveryClientProvider.java)).
See it [used in a sample app](../sample-app-android/src/main/java/kontent/ai/delivery_android_sample/data/source/DeliveryClientProvider.java)).

### 2. Register strongly-typed models

Android applications must register the models using the `registerType` method. See a usage example in [DeliveryClientProvider.java](../sample-app-android/src/main/java/com/github/kentico/delivery_android_sample/data/source/DeliveryClientProvider.java).
Android applications must register the models using the `registerType` method. See a usage example in [DeliveryClientProvider.java](../sample-app-android/src/main/java/kontent/ai/delivery_android_sample/data/source/DeliveryClientProvider.java).

You can still use the [model generator](../delivery-sdk-generators/README.md) for generating the models.

Expand Down
2 changes: 1 addition & 1 deletion delivery-sdk/src/main/java/kontent/ai/delivery/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void setDescription(String description) {
/**
* Absolute URL for the asset
*
* @return URL for the asset, hosted by Kentico
* @return URL for the asset, hosted by Kontent.ai
*/
public String getUrl() {
return url;
Expand Down
50 changes: 25 additions & 25 deletions delivery-sdk/src/main/java/kontent/ai/delivery/DeliveryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private <T> CompletionStage<T> executeRequest(final String url, Class<T> tClass)


if (skipCache) {
return retrieveFromKentico(request, url, tClass, 0);
return retrieveFromKontent(request, url, tClass, 0);
} else {
return cacheManager.get(url).thenApply(jsonNode -> {
try {
Expand All @@ -423,20 +423,20 @@ private <T> CompletionStage<T> executeRequest(final String url, Class<T> tClass)
}
return objectMapper.treeToValue(jsonNode, tClass);
} catch (JsonProcessingException e) {
log.error("JsonProcessingException parsing Kentico object: {}", e.toString());
log.error("JsonProcessingException parsing Kontent.ai object: {}", e.toString());
}
return null;
}).thenCompose(result -> {
if (result != null) {
return CompletableFuture.completedFuture(result);
} else {
return retrieveFromKentico(request, url, tClass, 0);
return retrieveFromKontent(request, url, tClass, 0);
}
});
}
}

private <T> CompletionStage<T> retrieveFromKentico(Request request, final String url, Class<T> tClass, int retryTurn) {
private <T> CompletionStage<T> retrieveFromKontent(Request request, final String url, Class<T> tClass, int retryTurn) {
return send(request)
.thenApply(this::logResponseInfo)
.thenApply(this::handleErrorIfNecessary)
Expand Down Expand Up @@ -471,16 +471,16 @@ private <T> CompletionStage<T> retrieveFromKentico(Request request, final String
if (error instanceof CompletionException) {
Throwable cause = error.getCause();

// Don't retry when when not KenticoException or not set to retry
boolean retry = cause instanceof KenticoException && ((KenticoException) cause).shouldRetry();
// Don't retry when when not KontentException or not set to retry
boolean retry = cause instanceof KontentException && ((KontentException) cause).shouldRetry();

if (!retry) {
throw (CompletionException) error;
}
}

if (counter.incrementAndGet() > deliveryOptions.getRetryAttempts()) {
KenticoRetryException ex = new KenticoRetryException(deliveryOptions.getRetryAttempts());
KontentRetryException ex = new KontentRetryException(deliveryOptions.getRetryAttempts());
ex.initCause(error.getCause());
throw ex;
}
Expand All @@ -494,15 +494,15 @@ private <T> CompletionStage<T> retrieveFromKentico(Request request, final String
return CompletableFuture.supplyAsync(
() -> {
try {
return retrieveFromKentico(request, url, tClass, counter.get())
return retrieveFromKontent(request, url, tClass, counter.get())
.toCompletableFuture().get();
} catch (InterruptedException e) {
log.error(String.format("InterruptedException have been raised on retial no. %d", counter.get()));
throw new CompletionException(e);
} catch (ExecutionException e) {
log.error(String.format("ExecutionException have been raised on retrial no. %d", counter.get()));
if (e.getCause() instanceof KenticoRetryException) {
KenticoRetryException exception = new KenticoRetryException(((KenticoRetryException) e.getCause()).getMaxRetryAttempts());
if (e.getCause() instanceof KontentRetryException) {
KontentRetryException exception = new KontentRetryException(((KontentRetryException) e.getCause()).getMaxRetryAttempts());
exception.initCause(error.getCause());
throw exception;
}
Expand All @@ -518,8 +518,8 @@ private <T> CompletionStage<T> retrieveFromKentico(Request request, final String
throw new CompletionException(e);
} catch (ExecutionException e) {
log.error("ExecutionException have been raised for timeout");
if (e.getCause() instanceof KenticoRetryException) {
KenticoRetryException exception = new KenticoRetryException(((KenticoRetryException) e.getCause()).getMaxRetryAttempts());
if (e.getCause() instanceof KontentRetryException) {
KontentRetryException exception = new KontentRetryException(((KontentRetryException) e.getCause()).getMaxRetryAttempts());
exception.initCause(error.getCause());
throw exception;
}
Expand All @@ -529,33 +529,33 @@ private <T> CompletionStage<T> retrieveFromKentico(Request request, final String
});
}

private Response handleErrorIfNecessary(Response response) throws KenticoIOException, KenticoErrorException {
private Response handleErrorIfNecessary(Response response) throws KontentIOException, KontentErrorException {
final int status = response.code();
if (RETRY_STATUSES.contains(status)) {
log.error("Kentico API retry status returned: {} (one of {})", status, RETRY_STATUSES.toString());
log.error("Kontent.ai API retry status returned: {} (one of {})", status, RETRY_STATUSES.toString());
try {
KenticoError kenticoError = objectMapper.readValue(response.body().bytes(), KenticoError.class);
throw new KenticoErrorException(kenticoError, true);
KontentError kontentError = objectMapper.readValue(response.body().bytes(), KontentError.class);
throw new KontentErrorException(kontentError, true);
} catch (IOException e) {
log.error("IOException when trying to parse the error response body: {}", e.toString());
throw new KenticoIOException(String.format("Kentico API retry status returned: %d (one of %s)", status, RETRY_STATUSES.toString()), true);
throw new KontentIOException(String.format("Kontent.ai API retry status returned: %d (one of %s)", status, RETRY_STATUSES.toString()), true);
}
} else if (status >= 500) {
log.error("Kentico API server error, status: {}", status);
log.error("Kontent.ai API server error, status: {}", status);
log.info("Request URL: ", response.request().url().toString());
String message =
String.format(
"Unknown error with Kentico API. Kentico is likely suffering site issues. Status: %s",
"Unknown error with Kontent.ai API. Kontent.ai is likely suffering site issues. Status: %s",
status);
throw new CompletionException(new KenticoIOException(message, false));
throw new CompletionException(new KontentIOException(message, false));
} else if (status >= 400) {
log.error("Kentico API server error, status: {}", status);
log.error("Kontent.ai API server error, status: {}", status);
try {
KenticoError kenticoError = objectMapper.readValue(response.body().bytes(), KenticoError.class);
throw new CompletionException(new KenticoErrorException(kenticoError, false));
KontentError kontentError = objectMapper.readValue(response.body().bytes(), KontentError.class);
throw new CompletionException(new KontentErrorException(kontentError, false));
} catch (IOException e) {
log.error("IOException connecting to Kentico: {}", e.toString());
throw new CompletionException(new KenticoIOException(e, false));
log.error("IOException connecting to Kontent.ai: {}", e.toString());
throw new CompletionException(new KontentIOException(e, false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ public DeliveryParameterBuilder excludeLinkedItems() {
*
* @param language The language variant to return.
* @return This DeliveryParameterBuilder with the added operator.
* @see <a href="https://docs.kontent.ai/tutorials/set-up-projects/set-up-languages/localization-in-kentico-kontent">More on Localization</a>
* @see <a href="https://docs.kontent.ai/tutorials/set-up-projects/set-up-languages/localization-in-kentico-kontent#section-language-fallbacks">
* @see <a href="https://kontent.ai/learn/tutorials/manage-kontent-ai/projects/set-up-languages/">More on Localization</a>
* @see <a href=https://kontent.ai/learn/tutorials/manage-kontent-ai/projects/set-up-languages/#section-language-fallbacks">
* Language fallbacks</a>
*/
public DeliveryParameterBuilder language(String language) {
Expand All @@ -620,8 +620,8 @@ public DeliveryParameterBuilder language(String language) {
*
* @param language The language variant to return.
* @return This DeliveryParameterBuilder with the added operator.
* @see <a href="https://docs.kontent.ai/tutorials/set-up-projects/set-up-languages/localization-in-kentico-kontent">More on Localization</a>
* @see <a href="https://docs.kontent.ai/tutorials/set-up-projects/set-up-languages/localization-in-kentico-kontent#section-language-fallbacks">
* @see <a href="https://kontent.ai/learn/tutorials/manage-kontent-ai/projects/set-up-languages/">More on Localization</a>
* @see <a href="https://kontent.ai/learn/tutorials/manage-kontent-ai/projects/set-up-languages/#section-language-fallbacks">
* Language fallbacks</a>
*/
public DeliveryParameterBuilder language(Locale language) {
Expand Down
2 changes: 1 addition & 1 deletion delivery-sdk/src/main/java/kontent/ai/delivery/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Image {
* Absolute URL for the image
*
* @param url Sets the url of this
* @return An absolute URL image hosted by Kentico
* @return An absolute URL image hosted by Kontent.ai
*/
@JsonProperty("url")
String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Kentico error response
* Kontent.ai error response
* <p>
* Kontent returns standard HTTP status codes to indicate success or failure of a request. In general, codes in
* the 2xx range indicate a successful request, codes in the 4xx range indicate errors caused by an incorrect input
Expand All @@ -46,19 +46,19 @@
@lombok.ToString
@lombok.EqualsAndHashCode
@lombok.NoArgsConstructor
public class KenticoError implements java.io.Serializable {
public class KontentError implements java.io.Serializable {

/**
* Returns the error message provided by Kentico detailing the error.
* Returns the error message provided by Kontent.ai detailing the error.
*
* @param message Sets the message of this.
* @return The error message from Kentico.
* @return The error message from Kontent.ai.
*/
@JsonProperty("message")
String message;

/**
* Returns a unique ID that can be provided to Kentico for support in relation to the error.
* Returns a unique ID that can be provided to Kontent.ai for support in relation to the error.
*
* @param requestId Sets the request ID of this.
* @return The unique ID for this error
Expand All @@ -67,7 +67,7 @@ public class KenticoError implements java.io.Serializable {
String requestId;

/**
* Returns the HTTP error code returned by Kentico.
* Returns the HTTP error code returned by Kontent.ai.
* <table>
* <caption>HTTP error codes</caption>
* <tr><td>400 - Bad Request</td><td>The request was not understood. Check for a missing required parameter, or an
Expand All @@ -86,10 +86,10 @@ public class KenticoError implements java.io.Serializable {
int errorCode;

/**
* Returns the specific code returned by the Kentico error response.
* Returns the specific code returned by the Kontent.ai error response.
*
* @param specificCode Sets the specific code of this.
* @return The specific code returned by the Kentico error response.
* @return The specific code returned by the Kontent.ai error response.
*/
@JsonProperty("specific_code")
int specificCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@
package kontent.ai.delivery;

/**
* Thrown to indicate failure of a Kentico request.
* Thrown to indicate failure of a Kontent.ai request.
*
* @see KenticoError
* @see KontentError
*/
public class KenticoErrorException extends RuntimeException implements KenticoException {
public class KontentErrorException extends RuntimeException implements KontentException {

private final KenticoError kenticoError;
private final KontentError kontentError;
private boolean shouldRetry;

/**
* Thrown to indicate failure of a Kentico request
* Thrown to indicate failure of a Kontent.ai request
*
* @param kenticoError The original KenticoError
* @param kontentError The original KontentError
*/
public KenticoErrorException(KenticoError kenticoError, boolean shouldRetry) {
super(kenticoError.getMessage());
this.kenticoError = kenticoError;
public KontentErrorException(KontentError kontentError, boolean shouldRetry) {
super(kontentError.getMessage());
this.kontentError = kontentError;
this.shouldRetry = shouldRetry;
}

/**
* Returns the original error provided by Kentico. Useful for debugging.
* Returns the original error provided by Kontent.ai. Useful for debugging.
*
* @return The original KenticoError
* @see KenticoError
* @return The original KontentError
* @see KontentError
*/
public KenticoError getKenticoError() {
return kenticoError;
public KontentError getKontentError() {
return kontentError;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package kontent.ai.delivery;

public interface KenticoException {
public interface KontentException {
boolean shouldRetry();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@

/**
* Thrown when an {@link IOException} is thrown when executing against the Kontent API. Generally means
* connectivity problems with Kentico of problem parsing {@link KenticoError} from body.
* connectivity problems with Kontent.ai of problem parsing {@link KontentError} from body.
*/
public class KenticoIOException extends RuntimeException implements KenticoException {
public class KontentIOException extends RuntimeException implements KontentException {

private boolean shouldRetry;

KenticoIOException(String message, boolean shouldRetry) {
KontentIOException(String message, boolean shouldRetry) {
super(message);
this.shouldRetry = shouldRetry;
}

KenticoIOException(IOException cause, boolean shouldRetry) {
KontentIOException(IOException cause, boolean shouldRetry) {
super(cause);
this.shouldRetry = shouldRetry;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2020
* Copyright (c) 2022 Kontent s.r.o.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,13 +26,13 @@

/**
* Thrown when retry attempts are is thrown when executing against the Kontent API. Generally means
* connectivity problems with Kentico.
* connectivity problems with Kontent.ai.
*/
public class KenticoRetryException extends RuntimeException implements KenticoException {
public class KontentRetryException extends RuntimeException implements KontentException {

private final int maxRetryAttempts;

KenticoRetryException(int maxRetryAttempts) {
KontentRetryException(int maxRetryAttempts) {
super(String.format("Retry attempty reached max retry attempts (%d) ", maxRetryAttempts));
this.maxRetryAttempts = maxRetryAttempts;
}
Expand Down
Loading

0 comments on commit 13dfec3

Please sign in to comment.