2016-04-25 128 views
0

我使用dropwizard和jersey2 REST客戶端,我得到jersey2無法返回響應對象

javax.ws.rs.BadRequestException: HTTP 400 Bad Request 

然而,當我打開日誌記錄我看到

DEBUG [2016-04-25 05:17:10,196] org.apache.http.wire: 
http-outgoing-0 << "{"apiVersion":"v1","timestamp":"April 24, 2016, 
10:17 pm","error":{"asiErrorCode":"12002","message":"A 
message","moreInfo":"http:\/\/bar.foo.net"}}" INFO [2016-04-25 
05:17:10,197] unknown.jul.logger: 1 * Client response received on 
thread main 1 < 400 1 < Access-Control-Allow-Headers: Accept, 
Content-Type, Authorization 1 < Access-Control-Allow-Methods: GET, 
POST, PUT, DELETE 1 < Access-Control-Allow-Origin: * 1 < Allow: 
OPTIONS,GET,POST,PUT,DELETE 1 < Cache-Control: no-cache, no-store, 
must-revalidate 1 < Connection: close 1 < Content-Length: 265 1 < 
Content-Type: application/json 1 < Date: Mon, 25 Apr 2016 05:17:10 
GMT 1 < Expires: 0 1 < Pragma: no-cache 1 < Server: Apache/2.4.12 
(Win32) OpenSSL/1.0.1m mod_jk/1.2.40 PHP/5.6.14 
{"apiVersion":"v1","timestamp":"April 24, 2016, 10:17 
pm","error":{"asiErrorCode":"12002","message":"A 
message","moreInfo":"http:\/\/foo.bar.net"}} 

我如何反序列化該響應而不是隻有400?

我的代碼看起來像

return client.target(URL).get(AsiAccounts.class); 

而且AsiAccounts基本上是空的

@JsonIgnoreProperties 
public class AsiAccounts 

} 

我加apiVerson,時間戳和錯誤AsiAccounts,但它仍然無法正常工作。任何幫助表示讚賞。

回答

-1

您可以用這種方式

Response.status(200).entity(asiAccount).build(); 
+0

謝謝,你介意提供更多細節?我不知道我的理解 – user2395365

+0

請訪問此: http://kielczewski.eu/2013/05/developing-restful-web-services-using-dropwizard-part-ii/ –