I have created a simple eclipse microprofile service runs in openliberty. My client file is like this.
@RegisterRestClient(configKey = "ra-api")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface MyClient extends AutoCloseable {
@POST
@Path("/user")
CompletionStage<JsonObject>createUser(String userInfo);
}
Then I am calling this from my service class like this.
@Stateless(name="MyClientFunctions")
public class MyClientFunctionsImpl implements MyClientFunctions {
@Inject
@RestClient
protected MyClient raClient;
@Override
public Map<String, Object> createRemoteUser(final Map<String, Object> parameters, final Connection connection) {
String body = Json.createObjectBuilder()
.add("name", guid)
.add("email", userEmail)
.add("role", "User")
.add("invite", false)
.add("send_email", false)
.add("license", "expert")
.add("username", guid).build().toString();
try {
CompletionStage<JsonObject> userInfoFuture = raClient.createUser(body);
jsonResult = ((CompletableFuture<JsonObject>) userInfoFuture).join();
retMap.put("UserInfo", jsonResult);
}
catch (Exception e) {
Logger.getLogger(MyClientFunctionsImpl.class.getName()).log(Level.SEVERE, null, e.getMessage());
}
And after CompletionStage<JsonObject> userInfoFuture = raClient.createUser(body);
line it directly goes to the catch
and prints
[ERROR ] null
and when I check raClient
also null. what is the reason for this?
Please help me.
Thanks
`