Skip to content

Commit

Permalink
Merge pull request #39 from shinusuresh/38-handling-timeouts-in-api
Browse files Browse the repository at this point in the history
#38 - Default timeout settings
  • Loading branch information
shinusuresh authored Sep 12, 2023
2 parents 8ca7fbf + 65e5c8d commit 68f5a98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

/**
* Autoconfiguration class for ProductsUp client.
*/
Expand Down Expand Up @@ -56,6 +59,7 @@ public PlatformApiClient platformApiClient() {
.build();
var factory = HttpServiceProxyFactory
.builder(WebClientAdapter.forClient(webClient))
.blockTimeout(Duration.of(productsUpProperties.getTimeout(), ChronoUnit.SECONDS))
.build();
return factory.createClient(PlatformApiClient.class);
}
Expand Down Expand Up @@ -84,6 +88,7 @@ public StreamApiClient streamApiClient() {
.build();
var factory = HttpServiceProxyFactory
.builder(WebClientAdapter.forClient(webClient))
.blockTimeout(Duration.of(productsUpProperties.getTimeout(), ChronoUnit.SECONDS))
.build();
return factory.createClient(StreamApiClient.class);
}
Expand Down Expand Up @@ -113,6 +118,7 @@ public StreamApiUploadClient streamApiUploadClient() {
.build();
var factory = HttpServiceProxyFactory
.builder(WebClientAdapter.forClient(webClient))
.blockTimeout(Duration.of(productsUpProperties.getTimeout(), ChronoUnit.SECONDS))
.build();
return factory.createClient(StreamApiUploadClient.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,90 +1,41 @@
package io.github.shinusuresh.productsup.client.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* Products up related configurations.
*/
@ConfigurationProperties("productsup")
@Getter
@Setter
public class ProductsUpProperties {

private String token;

private String authorizationToken;

private String platformEndpoint = "https://platform-api.productsup.io/platform/v2";

private String streamEndpoint = "https://stream-api.productsup.com/";

/**
* Returns platform endpoint.
*
* @return platform endpoint url
*/
public String getPlatformEndpoint() {
return platformEndpoint;
}

/**
* Sets platform endpoint.
*
* @param platformEndpoint - endpoint for platform calls.
* Token for platform api calls
*/
public void setPlatformEndpoint(String platformEndpoint) {
this.platformEndpoint = platformEndpoint;
}

private String token;

/**
* Returns Products up token configured for a client.
*
* @return token
* Timeout for API calls.
*/
public String getToken() {
return token;
}
private long timeout = 5L;

/**
* Sets token
* @param token - token for the client.
* Authorization token for Stream api calls.
*/
public void setToken(String token) {
this.token = token;
}
private String authorizationToken;

/**
* Returns stream endpoint.
*
* @return Stream api endpoint.
*/
public String getStreamEndpoint() {
return streamEndpoint;
}

/**
* Sets stream endpoint.
*
* @param streamEndpoint - stream endpoint.
* Platform endpoint.
*/
public void setStreamEndpoint(String streamEndpoint) {
this.streamEndpoint = streamEndpoint;
}
private String platformEndpoint = "https://platform-api.productsup.io/platform/v2";

/**
* Returns authorization token for Stream api calls.
*
* @return authorization token
* Stream api endpoint.
*/
public String getAuthorizationToken() {
return authorizationToken;
}
private String streamEndpoint = "https://stream-api.productsup.com/";

/**
* Sets authorization token for stream api calls.
*
* @param authorizationToken - Authorization token.
*/
public void setAuthorizationToken(String authorizationToken) {
this.authorizationToken = authorizationToken;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/productsup-application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
productsup:
#Timeout in seconds
timeout: 5
token: "client_id:client_secret"
stream:
enabled: false

0 comments on commit 68f5a98

Please sign in to comment.