RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Authorization", "1234");
List<AdhocRequestParameters> list = new ArrayList<>();
AdhocRequestParameters AdhocRequestParameters = new AdhocRequestParameters("partitionCode","GG",AdhocRequestParameterType.STRING);
list.add(AdhocRequestParameters);
AdhocParameters params = new AdhocParameters("3301",list);
HttpEntity<Object> entity = new HttpEntity<Object>(params,headers);
//ResponseEntity<String> httpResponse = restTemplate.postForEntity(hURL,entity, String.class);
//ResponseEntity<String> httpResponse = restTemplate.exchange(hURL,HttpMethod.POST,entity, String.class);
ResponseEntity<String> httpResponse = restTemplate.postForEntity(hURL,entity, String.class);
错误:
org.springframework.web.client.HttpClientErrorException: 400 null
控制器:
@RequestMapping(value="/invokeAdhocJob/", method=RequestMethod.POST,produces={"application/json","application/xml"})
public ResponseEntity<String> submitAdhocJob(@RequestHeader(value="Accept") String acceptMediaType,@RequestHeader(value="Authorization") String userId,
@RequestBody AdhocParameters adhocParameters)
{
System.out.println(adhocParameters.getJobId());
System.out.println(adhocParameters.getList());
System.out.println(userId);
System.out.println(acceptMediaType);
return new ResponseEntity<>(jobInvoked,HttpStatus.OK);
}