0

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 `

Randi
  • 639
  • 2
  • 6
  • 23
  • What features do you have in the `server.xml`? Make sure you have `mpRestClient-1.x` feature or `microProfile-3.x`. – Gas Jun 18 '20 at 09:16
  • @Gas yes it is included – Randi Jun 18 '20 at 09:58
  • fix that catch with `e.printStackTrace()` and add details of the exception to the question. – Gas Jun 18 '20 at 10:00
  • @Gas it fixed. But raclient is still null – Randi Jun 19 '20 at 11:02
  • so what is full stack trace? Also do you have any other messages during server startup? Maybe injection not fully works. – Gas Jun 19 '20 at 12:23
  • Have you configured a baseURI for the client in MP Config properties? That is required before injection of the client can occur. You may also want to try using the CDI "weld probe" to see if the client instance is getting creating or if there are some sort of CDI issue - more info here: https://developer.ibm.com/wasdev/blog/2016/06/30/beta-websphere-liberty-and-tools-july-2016/ – Andy McCright Jun 19 '20 at 18:05

1 Answers1

0
  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.