Let's write a REST client to invoke the GET organization API. This is similar to what we wrote in the getToken() function.
The getOrg() function takes the jwt token as an input parameter, which will be passed as a request header in the /identity/organization/{orgId} API. AuthFilter checks for the validity of the token. We then create a Jersey client instance, invoke the API and return the response, as shown in the following code:
fun getOrg(jwt: String):JSONObject {
val client = Client.create()
val orgId: UUID = "9dc30f1e-fb0f-48c1-bccb-f6d89f5e1108"
val webResource = client
.resource("http://localhost:8090/identity-service/identity/organization/orgId")
val response = webResource
.accept("application/json")
.header("Authorization", "Bearer $jwt")
.get<ClientResponse>(ClientResponse::class.java)
val responseBody= response.getEntity(String::class.java)
return JSONObject(responseBody)
}