2017-08-22 9 views
0

次のREST Webサービスを記述しました。Resttemplate Webサービスのcomsumingのレスポンスタイプの問題

ここでRestTemplateを使用してこのWebサービスを使用したいと思っています。しかし、restTemplate.exchange(?)の戻り値の型はどういうものかわかりません。

@RequestMapping(value = "/customercontact/transid/{brokerid}", method = RequestMethod.GET) 
     public ResponseEntity<HashMap<String, String>> getTransactionIdWithPublicKey(@PathVariable("brokerid") String brokerid){ 
     HashMap<String, String> transactionid = customerService.getTransactionid(brokerid); 
      if(transactionid != null) 
       return new ResponseEntity<HashMap<String, String>>(transactionid,HttpStatus.OK); 
      else 
       return new ResponseEntity<HashMap<String, String>>(HttpStatus.NOT_FOUND); 

     } 
public void doGet(HttpServletRequest request, 
          HttpServletResponse response) throws IOException 
     { 

RestTemplate restTemplate = new RestTemplate(); 
      HttpHeaders requestHeaders = new HttpHeaders(); 
      requestHeaders.add("SM_USER", "wbrokere"); 
      MultiValueMap<String, String> body = new LinkedMultiValueMap<String, String>(); 
      HttpEntity<?> httpEntity = new HttpEntity<Object>(body, requestHeaders); 
      ResponseEntity<String> responseobj = restTemplate.exchange("http://127.0.0.1:24000/webbroker/getusername", HttpMethod.GET, httpEntity,?); 
    } 

答えて

0

HashMap.class

ResponseEntity<HashMap> responseobj = `restTemplate.exchange("http://127.0.0.1:24000/webbroker/getusername", HttpMethod.GET, httpEntity,HashMap.class);` 
responseobj.getBody(); //To get the body of the response entity 

はのpom.xmlにJaksonの依存関係を追加するには、RESTサービスの中で使用したのと同じタイプ

<!-- Jackson for Rest Controller --> 
     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-core</artifactId> 
      <version>2.8.8</version> 
     </dependency> 
     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-databind</artifactId> 
      <version>2.8.8</version> 
     </dependency> 
     <dependency> 
      <groupId>com.fasterxml.jackson.dataformat</groupId> 
      <artifactId>jackson-dataformat-xml</artifactId> 
      <version>2.8.8</version> 
     </dependency> 
+0

ます( "APIを:" するSystem.out.printlnを使用することができます+ responseobj.getBody());結果を見る –

+0

レスポンスを抽出できませんでした:応答タイプ[java.util.HashMap ]およびコンテンツタイプ[application/json; charset = UTF-8]でHttpMessageConverterが見つかりません] このエラーが発生しました – jinal

+0

更新された回答 –

関連する問題