2

I am trying to create a service with rest template to consume List data from other url but when i try to communicate to other url it is throwing following error before the other method is called.

org.springframework.web.client.HttpClientErrorException: 406 null
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)

Caller method:

@RequestMapping(value = "/customer/User/getUserlist", method = RequestMethod.POST,headers="Accept=application/json")
    public ResponseEntity<List<User>> getUserList(@RequestBody UserInformation UserInformation) 
    {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
            map.add("UserCode", UserInformation.getUserCode());
            map.add("emailID", UserInformation.getCustomerEmailID());

            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

            final HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>(map ,
                    headers);
            JSONObject jsonObject = null;

            try {
                RestTemplate restTemplate = new RestTemplate();
                if(responseEntity.getBody().equals("true"))
                {
                       ResponseEntity<List<User>> responseEntity1 = restTemplate.exchange(
                                UserURL+"getUserlist", HttpMethod.POST, entity,
                                List<User>.class);
                        List l=responseEntity1.getBody();
                       return l;
                }
                else
                {
                    return null;
                }
              }  
              catch (Exception e) 
                {
                    e.printstacktrace();
                }
        }

Called method:

    @RequestMapping(value = "/order/getorderlist", method = RequestMethod.POST,headers="Accept=application/x-www-form-urlencoded")
            public List<User> getOrderList(@RequestParam String UserCode,
@requestparam String emailID) throws Exception 
            {
                List<User> l=new ArrayList<User>();
                // the method will fetch value from db and append it to list
                l=orderServiceImpl.getAllOrder(emailID,UserCode);
                return l;
            }
James Z
  • 12,209
  • 10
  • 24
  • 44
SrikR
  • 231
  • 9
  • 17

0 Answers0