rename util to common
Some checks failed
deploy / deploy (push) Failing after 1m19s

This commit is contained in:
Lee
2024-04-08 19:47:20 +01:00
parent a57f660461
commit fd16476143
12 changed files with 14 additions and 14 deletions

View File

@ -0,0 +1,41 @@
package cc.fascinated.common;
import lombok.experimental.UtilityClass;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClient;
@UtilityClass
public class WebRequest {
/**
* The web client.
*/
private static final RestClient CLIENT = RestClient.builder()
.requestFactory(new HttpComponentsClientHttpRequestFactory())
.build();
/**
* Gets a response from the given URL.
*
* @param url the url
* @return the response
* @param <T> the type of the response
*/
public static <T> T getAsEntity(String url, Class<T> clazz) {
try {
ResponseEntity<T> profile = CLIENT.get()
.uri(url)
.retrieve()
.toEntity(clazz);
if (profile.getStatusCode().isError()) {
return null;
}
return profile.getBody();
} catch (HttpClientErrorException ex) {
return null;
}
}
}