softRestTemplate 2

@SuppressWarnings("unchecked")
    public User getUser(String id,String name) {
        SoftReference<RestTemplate> softRestTemplate = new SoftReference<RestTemplate>(restTemplate);
        String url = null;
        HashMap<String, String> uriVariables = new HashMap<String, String>();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_XML);
        HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
        ResponseEntity<User> response=null;
        Leaguer body=null;
        try {
            uriVariables.put("id", id);
            uriVariables.put("name", name);           
            response = softRestTemplate.get().exchange(url,HttpMethod.GET, requestEntity, User.class, uriVariables);
            body=response.getBody();
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            softRestTemplate = null;
        }
        return body;
    }

posted @ 2014-06-27 13:57  pretty flower  阅读(255)  评论(0)    收藏  举报