簡體   English   中英

嘗試為Java RESTful服務構建Response對象

[英]trying to build a Response object for a Java RESTful service

我正在嘗試使用從數據庫中獲取的信息來構建Response對象。 我返回的信息在Change對象中:

返回的change.getDocument()是:

{"testSolution":false,"solutionId":333,"clientId":4018593,"firewall":false,"pod":"pod3.dmy3","networkPolicy":{"speed":"1","subnets":{"nat":{"vlan":3004,"cidr":["110.168.0.0/24"]},"private":{"vlan":3004,"cidr":["15.10.1.128/25"]}}}}

所以我正在創建這樣的響應:

 return Response.status(422).location(location).entity(changeRequest).build();

在單元測試中,我這樣做:

    String responseJson = response.readEntity(String.class);
    System.out.println("The response is: " + responseJson);

為了測試,但我得到了以下結果:

The response is: {"object_id" : 333,"object_type" : "class com.entities.Solution", "operation" : "", "revision" : 0, "remote_user" : "",   "remote_host" : "", "created" : "", "published" : "", "comment" : "HTTP Status Code 422", "error" : "HTTP Status Code 422, there is a pending change request for this Solution. Replying with pending ChangeRequest",  "document" : {} }

一切都按預期進行,但是文檔節點不包含任何信息。 我是否正確構建Response對象?

嘗試以這種方式返回它:

Response.status(Status.OK).type(MediaType.APPLICATION_JSON)
                .entity(changeRequest).build();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM