2016-07-07 162 views
2

我試圖在我的集合環境中自動化一些東西。就像前幾天一樣,當我嘗試與Rally進行有效的休息交換以獲取有關某些Changesets的信息時,我遇到了這個問題,我似乎無法解決這個問題。這是使用Tomcat運行的,只是從另一臺服務器上偵聽。集合請求返回null

下面是一些代碼和一些日誌:

這些記錄器返回以下時,這是運行:

INFO - Result: <200 

OK,[email protected]c,{Date=[Thu, 07 Jul 2016 22:08:41 GMT], Content-Type=[application/json; charset=utf-8], Transfer-Encoding=[chunked], Connection=[keep-alive], Set-Cookie=[__cfduid=dc0b3ebf63634c86250efdedf10fd4ead1467929321; expires=Fri, 07-Jul-17 22:08:41 GMT; path=/; domain=.rallydev.com; HttpOnly, JSESSIONID=qs-app-111wgnt86c424tz1hwu48m187shg.qs-app-11;Path=/;Secure;HttpOnly, ZSESSIONID=CONFIDENTIAL;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly, SUBBUCKETID=0;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly, SERVERID=CONFIDENTIAL; path=/], Strict-Transport-Security=[max-age=31536000 ; includeSubDomains], X-XSS-Protection=[1; mode=block], RallyRequestID=[qs-app-111wgnt86c424tz1hwu48m187shg.qs-app-1128098501], Expires=[Thu, 01 Jan 1970 00:00:00 GMT], ETag=[W/"028b6add6cf4389520d5bdb5163a9a21c"], Vary=[Accept-Encoding], P3P=[CP="NON DSP COR CURa PSAa PSDa OUR NOR BUS PUR COM NAV STA"], Cache-Control=[private,max-age=0,must-revalidate], Server=[cloudflare-nginx], CF-RAY=[2bee9dd3697809b2-ORD]}> 
    2016-07-07 17:08:41,361 RestCallHelper      
    INFO - Result body:[email protected]c 

這裏是請求的結構,我怎麼把它設置...春天應該autopopulate所有這些值。

QueryResultWrapper 
--> QueryResult 
    --> Results[] 
     --> Changes 
      -->_ref 

當這種執行它說,它已經取得了GET請求,當我複製和過去,它在瀏覽器中,包含一個有效的JSON這樣的:

{"QueryResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "Warnings": [], "TotalResultCount": 1, "StartIndex": 1, "PageSize": 20, "Results": [{"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "_ref": "STUFF IS IN HERE", "_refObjectUUID": "9b96f131-f7a3-4615-b699-f793677836ba", "_objectVersion": "2", "_refObjectName": "Automate-web:057c595a52d0b39233bc4796d69cb09fb329d007", "CreationDate": "2016-07-07T18:45:31.240Z", "_CreatedAt": "today at 1:45 pm", "ObjectID": 58917491560, "ObjectUUID": "9b96f131-f7a3-4615-b699-f793677836ba", "VersionId": "2", "Subscription": {STUFF IS IN HERE}, "Workspace": {STUFF IS IN HERE }, "Artifacts": {STUFF IS IN HERE}, "Author": {STUFF IS IN HERE}, "Branch": null, "Builds": {STUFF IS IN HERE}, "Changes": {STUFF IS IN HERE}, "CommitTimestamp": "2016-07-07T18:44:16.000Z", "Message": "DE3333. Check for an agent on the agent lookup.", "Name": "CONFIDENTIAL", "Revision": "057c595a52d0b39233bc4796d69cb09fb329d007", "SCMRepository": {STUFF IS IN HERE}, "Uri": "STUFF IS IN HERE", "_type": "Changeset"}]}} 

現在爲什麼QueryResult回報null

回答

1

碰巧Jackson的Spring集成似乎並不喜歡QueryResultWrapper的外觀,也無法指定該變量。這是我對不使用傑克遜的以下更改。

public <T> T callRestfulAPIForRallyObjectMapper(String url, HttpMethod method, T obj) throws JsonParseException, JsonMappingException, IOException { 
    HttpHeaders headers = new HttpHeaders(); 
    headers.add("Authorization", RallyAuthKey); 
    headers.add("Content-Type", "application/json"); 
    headers.add("Accepts", "application/json"); 
    return callRestfulAPIObjectMapper(url, headers, method, obj); 
}  
private <T> T callRestfulAPIObjectMapper(String url, HttpHeaders headers, HttpMethod method, T obj) throws JsonParseException, JsonMappingException, IOException { 

RestTemplate restTemplate = new RestTemplate(); 

     SimpleClientHttpRequestFactory simpleFactory = new SimpleClientHttpRequestFactory(); 

     //Set timeout on connection to 20 seconds 
     simpleFactory.setConnectTimeout(20*1000); 

     restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(simpleFactory)); 
     ResponseEntity<String> result = restTemplate.exchange(url, method, new HttpEntity<String>(headers), new ParameterizedTypeReference<String>(){}); 

     ObjectMapper mapper = new ObjectMapper(); 
     @SuppressWarnings("unchecked") 
     T wrapper = (T) mapper.readValue(result.getBody(), obj.getClass()); 

     return wrapper; 
    } 

這是我在調用方法的代碼中所做的更改。

QueryResultWrapper changeSetsRequest = caller.callRestfulAPIForRallyObjectMapper(
          changesetRef.substring(1, changesetRef.length() - 1), httpmethod, 
          new QueryResultWrapper()); 
        QueryResult qr = changeSetsRequest.getQueryResult();