Class RestUtils
- java.lang.Object
-
- com.redhat.parodos.examples.utils.RestUtils
-
public final class RestUtils extends Object
RestUtils is a utility class. All its methods must be declared as static so they can't be overridden.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.springframework.http.ResponseEntity<String>executeGet(String urlString)Execute the GET HTTP method to the given URLstatic org.springframework.http.ResponseEntity<String>executePost(String urlString, String payload)Create a new resource by POSTing the given payload to the URL, and returns the response as ResponseEntity.static org.springframework.http.ResponseEntity<String>executePost(String urlString, org.springframework.http.HttpEntity<?> requestEntity)Create a new resource by POSTing the given requestEntity to the URL, and returns the response as String.static <T,E>
org.springframework.http.ResponseEntity<E>executePost(String urlString, T requestDto, String username, String password, Class<E> responseType)static StringgetBase64Creds(String username, String password)Generates a Base64 encoding of username:password stringstatic org.springframework.http.HttpEntity<String>getRequestWithHeaders(String username, String password)Creates a new HttpHeader and set the Authorization object according to @see getBase64Credsstatic <T> org.springframework.http.HttpEntity<T>getRequestWithHeaders(T request, String username, String password)Creates a new HttpHeader with request and set the Authorization object according to @see getBase64Credsstatic org.springframework.http.ResponseEntity<String>restExchange(String urlString, String username, String password)Execute the GET HTTP method to the given URL, writing the given request entity to the request, and returns the response as ResponseEntity.static <E> org.springframework.http.ResponseEntity<E>restExchange(String urlString, String username, String password, Class<E> responseType)
-
-
-
Method Detail
-
executePost
public static org.springframework.http.ResponseEntity<String> executePost(String urlString, String payload)
Create a new resource by POSTing the given payload to the URL, and returns the response as ResponseEntity.- Parameters:
urlString- the URLpayload- object to post- Returns:
- See Also:
RestTemplate.postForEntity(URI, Object, Class),ResponseEntity
-
executePost
public static org.springframework.http.ResponseEntity<String> executePost(String urlString, org.springframework.http.HttpEntity<?> requestEntity)
Create a new resource by POSTing the given requestEntity to the URL, and returns the response as String.- Parameters:
urlString- the URLrequestEntity- object to post- Returns:
- the response as string
- See Also:
RestTemplate.postForEntity(URI, Object, Class)
-
executePost
public static <T,E> org.springframework.http.ResponseEntity<E> executePost(String urlString, T requestDto, String username, String password, Class<E> responseType)
-
executeGet
public static org.springframework.http.ResponseEntity<String> executeGet(String urlString)
Execute the GET HTTP method to the given URL- Parameters:
urlString- the URL- Returns:
- HTTP response as string
-
restExchange
public static org.springframework.http.ResponseEntity<String> restExchange(String urlString, String username, String password)
Execute the GET HTTP method to the given URL, writing the given request entity to the request, and returns the response as ResponseEntity.- Parameters:
urlString- the URLusername- the usernamepassword- the password- Returns:
- See Also:
RestTemplate.exchange(String, HttpMethod, HttpEntity, Class, Object...),ResponseEntity
-
restExchange
public static <E> org.springframework.http.ResponseEntity<E> restExchange(String urlString, String username, String password, Class<E> responseType)
-
getRequestWithHeaders
public static org.springframework.http.HttpEntity<String> getRequestWithHeaders(String username, String password)
Creates a new HttpHeader and set the Authorization object according to @see getBase64Creds- Parameters:
username- the usernamepassword- the password- Returns:
- the @see org.springframework.http.HttpEntity
-
getRequestWithHeaders
public static <T> org.springframework.http.HttpEntity<T> getRequestWithHeaders(T request, String username, String password)Creates a new HttpHeader with request and set the Authorization object according to @see getBase64Creds- Parameters:
username- the usernamepassword- the password- Returns:
- the @see org.springframework.http.HttpEntity
-
-