0
votes

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 `

1
What features do you have in the server.xml? Make sure you have mpRestClient-1.x feature or microProfile-3.x. - Gas
@Gas yes it is included - Randi
fix that catch with e.printStackTrace() and add details of the exception to the question. - Gas
@Gas it fixed. But raclient is still null - Randi
so what is full stack trace? Also do you have any other messages during server startup? Maybe injection not fully works. - Gas

1 Answers

0
votes
  Logger.getLogger(MyClientFunctionsImpl.class.getName()).log(Level.SEVERE, null, e.getMessage());

This method call is wrong. Turns out if you tell a logger to log "null", it will then log "null", which is generally not very helpful. Try this:

Logger.getLogger(MyClientFunctionsImpl.class.getName()).log(Level.SEVERE, "Error while creating remote user", e);

Then, you will get an actual error message.