In my application I have 2 projects (services), I want to make an API call from one service to another. So I followed the Quarkus tutorial for Quarkus Restclient. But when I make the call the restclient returns a default model.
This is my Response class:
public class Response {
private int status;
private String statusVerbose;
private Object data;
//Getters
public int getStatus() {return this.status;}
public String getStatusVerbose() {return this.statusVerbose;}
public Object getData() {return this.data;}
public Response(){
this.SetStatusCode(404);
this.data = new JSONObject().put("error", "Not Found");
}
public Response(int statusCode){
this.SetStatusCode(statusCode);
}
public Response(int status, Object data){
this.SetStatusCode(status);
this.SetData(data);
}
public Response(int status, Object data, String statusVerbose){
this.SetStatusCode(status);
this.SetData(data);
this.SetStatusVerbose(statusVerbose);
}
public Response(int status, String statusVerbose){
this.SetStatusCode(status);
this.SetStatusVerbose(statusVerbose);
}
public void SetStatusCode(int status) {
this.status = status;
switch(status){
case 200:
statusVerbose = "OK";
break;
case 400:
statusVerbose = "BAD_REQUEST";
break;
case 404:
statusVerbose = "NOT_FOUND";
break;
case 500:
statusVerbose = "INTERNAL_SERVER_ERROR";
break;
case 401:
statusVerbose = "NOT_AUTHORIZED";
break;
case 403:
statusVerbose = "NOT_ALLOWED";
break;
}
}
public void SetStatusVerbose(String verbose){
statusVerbose = verbose;
}
public void SetData(Object data){
this.data = data;
}
}
This is the Response model that it being returned, I also have the RestClient receive this model. But RestClient gives me a Response object with the default constructor. Instead with the specific data.
public Response IsUserASupermarket(){
Response r = new Response(200);
JSONObject obj = new JSONObject();
obj.put("isSupermarket", true);
r.SetData(obj);
System.out.println(r.getData());
return r;
}
The interface where I receive this call:
@RegisterRestClient
public interface PortalAccountClient {
@GET
@Path("/portal/isSupermarket")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
Response IsUserASupermarket();
}
So I am getting an default constructor Response obj back.
Kind Regards, Bart