0

私のアプリケーションには 2 つのプロジェクト (サービス) があり、あるサービスから別のサービスへの API 呼び出しを行いたいと考えています。そこで、Quarkus Restclient の Quarkus チュートリアルに従いました。しかし、呼び出しを行うと、restclient はデフォルトのモデルを返します。

これは私の応答クラスです:

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;
}
}

これが返される Response モデルです。RestClient にもこのモデルを受け取ってもらいます。しかし、RestClient は、デフォルトのコンストラクターを持つ Response オブジェクトを提供してくれます。代わりに特定のデータを使用します。

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;
    }

この呼び出しを受け取るインターフェイス:

@RegisterRestClient
public interface PortalAccountClient {

    @GET
    @Path("/portal/isSupermarket")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    Response IsUserASupermarket();
}

したがって、デフォルトのコンストラクター Response obj を取得しています。

よろしく、バート

4

2 に答える 2