Package org.gcube.idm.client.clients
Class IdmRestClient
- java.lang.Object
-
- org.gcube.idm.client.clients.IdmRestClient
-
public class IdmRestClient extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringAUTHORIZATION_HEADERprotected URIBASE_URLprotected static org.slf4j.Loggerlogger
-
Constructor Summary
Constructors Constructor Description IdmRestClient(String base_url)IdmRestClient(URI base_url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringbearerAuth(String token)URIgetBASE_URL()static HashMap<String,String>getHeadersWithAuth(String auth_token, HashMap<String,String> headers)static StringgetStreamedContentAsString(HttpURLConnection response)Gets the streamed content as a string, if possible.URIgetUri(String extraPath)URLgetUrl(String extraPath)<T> ResponseBean<T>performGetRequest(String relativeUrl, String auth_token, Class<T> classtype)perform a get request.<T> ResponseBean<T>performGetRequest(String relativeUrl, String auth_token, org.gcube.com.fasterxml.jackson.databind.JavaType objectsType)perform a get request.<T> ResponseBean<T>performGetRequest(String relativeUrl, Map<String,String> headers, Map<String,String> params, Class<T> classtype)<T> ResponseBean<T>performGetRequest(String relativeUrl, Map<String,String> headers, Map<String,String> params, org.gcube.com.fasterxml.jackson.databind.JavaType objectsType)<T> ResponseBean<T>performPostRequest(String relativeUrl, Map<String,String> headers, Map<String,List<String>> params, Class<T> classtype)static org.gcube.common.gxrest.request.GXHTTPStringRequestprepareGetRequest(URL url, Map<String,String> headers, Map<String,String> params)static org.gcube.common.gxrest.request.GXHTTPStringRequestpreparePostRequest(URL url, Map<String,String> headers, Map<String,List<String>> params)static voidsafeSetAsExternalCallForOldAPI(org.gcube.common.gxrest.request.GXHTTPStringRequest request)voidsetBASE_URL(URI bASE_URL)static <T> TtryConvertStreamedContentFromJson(HttpURLConnection response, Class<T> classtype)Tries to convert the content from its Json serialization, if possible.static <T> TtryConvertStreamedContentFromJson(HttpURLConnection response, org.gcube.com.fasterxml.jackson.databind.JavaType objectType)static <T> TtryConvertStreamedContentFromJson(org.gcube.common.gxrest.response.inbound.GXInboundResponse response, Class<T> classtype)static <T> TtryConvertStreamedContentFromJson(org.gcube.common.gxrest.response.inbound.GXInboundResponse response, org.gcube.com.fasterxml.jackson.databind.JavaType objectType)
-
-
-
Field Detail
-
logger
protected static org.slf4j.Logger logger
-
AUTHORIZATION_HEADER
protected static final String AUTHORIZATION_HEADER
- See Also:
- Constant Field Values
-
BASE_URL
protected URI BASE_URL
-
-
Constructor Detail
-
IdmRestClient
public IdmRestClient(String base_url) throws URISyntaxException
- Throws:
URISyntaxException
-
IdmRestClient
public IdmRestClient(URI base_url)
-
-
Method Detail
-
getBASE_URL
public URI getBASE_URL()
-
setBASE_URL
public void setBASE_URL(URI bASE_URL)
-
getUrl
public URL getUrl(String extraPath) throws URISyntaxException, MalformedURLException
-
getUri
public URI getUri(String extraPath) throws URISyntaxException, MalformedURLException
-
getHeadersWithAuth
public static HashMap<String,String> getHeadersWithAuth(String auth_token, HashMap<String,String> headers)
-
performGetRequest
public <T> ResponseBean<T> performGetRequest(String relativeUrl, String auth_token, Class<T> classtype)
perform a get request. argument type as classtype (TheClass.class)- Type Parameters:
T-- Parameters:
relativeUrl-auth_token-classtype-- Returns:
-
performGetRequest
public <T> ResponseBean<T> performGetRequest(String relativeUrl, Map<String,String> headers, Map<String,String> params, Class<T> classtype) throws jakarta.ws.rs.NotAuthorizedException, jakarta.ws.rs.BadRequestException
- Throws:
jakarta.ws.rs.NotAuthorizedExceptionjakarta.ws.rs.BadRequestException
-
performGetRequest
public <T> ResponseBean<T> performGetRequest(String relativeUrl, String auth_token, org.gcube.com.fasterxml.jackson.databind.JavaType objectsType) throws jakarta.ws.rs.NotAuthorizedException, jakarta.ws.rs.BadRequestException
perform a get request. argument type as JavaType ( => JavaType objectsType = JsonUtilsCustom.getObjectJT(TheClass.class) ) when you have a composed java tape from genrics (es HashMap) use the JsonUtilsCustom methods to obtain the relative JavaType - Parameters:
auth_token-headers- // null to create a new HashMap- Returns:
- Throws:
jakarta.ws.rs.NotAuthorizedExceptionjakarta.ws.rs.BadRequestException
-
performGetRequest
public <T> ResponseBean<T> performGetRequest(String relativeUrl, Map<String,String> headers, Map<String,String> params, org.gcube.com.fasterxml.jackson.databind.JavaType objectsType) throws jakarta.ws.rs.NotAuthorizedException, jakarta.ws.rs.BadRequestException
- Throws:
jakarta.ws.rs.NotAuthorizedExceptionjakarta.ws.rs.BadRequestException
-
performPostRequest
public <T> ResponseBean<T> performPostRequest(String relativeUrl, Map<String,String> headers, Map<String,List<String>> params, Class<T> classtype) throws jakarta.ws.rs.NotAuthorizedException, jakarta.ws.rs.BadRequestException
- Throws:
jakarta.ws.rs.NotAuthorizedExceptionjakarta.ws.rs.BadRequestException
-
safeSetAsExternalCallForOldAPI
public static void safeSetAsExternalCallForOldAPI(org.gcube.common.gxrest.request.GXHTTPStringRequest request)
-
getStreamedContentAsString
public static String getStreamedContentAsString(HttpURLConnection response) throws IOException
Gets the streamed content as a string, if possible.- Returns:
- the content
- Throws:
IOException- if unable to read the content
-
tryConvertStreamedContentFromJson
public static <T> T tryConvertStreamedContentFromJson(HttpURLConnection response, Class<T> classtype) throws IOException, Exception
Tries to convert the content from its Json serialization, if possible.- Type Parameters:
T- the type of the desired object- Returns:
- an object of type T from the content
- Throws:
IOExceptionException- if the deserialization fails
-
tryConvertStreamedContentFromJson
public static <T> T tryConvertStreamedContentFromJson(HttpURLConnection response, org.gcube.com.fasterxml.jackson.databind.JavaType objectType) throws IOException, Exception
- Throws:
IOExceptionException
-
tryConvertStreamedContentFromJson
public static <T> T tryConvertStreamedContentFromJson(org.gcube.common.gxrest.response.inbound.GXInboundResponse response, org.gcube.com.fasterxml.jackson.databind.JavaType objectType) throws IOException, Exception- Throws:
IOExceptionException
-
tryConvertStreamedContentFromJson
public static <T> T tryConvertStreamedContentFromJson(org.gcube.common.gxrest.response.inbound.GXInboundResponse response, Class<T> classtype) throws IOException, Exception- Throws:
IOExceptionException
-
preparePostRequest
public static org.gcube.common.gxrest.request.GXHTTPStringRequest preparePostRequest(URL url, Map<String,String> headers, Map<String,List<String>> params) throws jakarta.ws.rs.BadRequestException
- Throws:
jakarta.ws.rs.BadRequestException
-
-