簡體   English   中英

包含Web服務的RestTemplate響應類型問題

[英]RestTemplate response type issue for comsuming web service

我已經編寫了以下REST Web服務。

現在我想使用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,?);
    }

與Rest Service 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依賴項

<!-- 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>

暫無
暫無

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

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