从Java服务调用Controller我有这个问题
org.springframework.web.HttpMediaTypeNotSupportedException:Content type' application / json; charset = UTF-8'不支持
我不明白我的Java代码有什么问题
String url3 = "http://localhost:8889/galian/S/S/S/claimsWS/getContract1";
ContractDto contractDto = new ContractDto("Test", "20161111", "idTest");
RestTemplate restTemplate3 = null;
try {
restTemplate3 = getRestTemplate(new URI(url3));
}
catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
//headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ContractDto> requestEntity = new HttpEntity<ContractDto>(contractDto, headers);
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
Object responseEntity = restTemplate3.postForObject(url3, requestEntity, Object.class);
Map<String, Object> responseObject3 = restTemplate.postForObject(url3, contractDto, Map.class);
DTO
public class ContractDto implements Serializable {
private static final long serialVersionUID = -7597862463769066562L;
protected String contractId;
protected String claimDate;
protected String insuredObjectIdentifier;
public ContractDto() {
}
public ContractDto(String contractId, String claimDate, String insuredObjectIdentifier) {
this.contractId = contractId;
this.claimDate = claimDate;
this.insuredObjectIdentifier = insuredObjectIdentifier;
}
public String getContractId() {
return contractId;
}
public void setContractId(String contractId) {
this.contractId = contractId;
}
public String getClaimDate() {
return claimDate;
}
public void setClaimDate(String claimDate) {
this.claimDate = claimDate;
}
public String getInsuredObjectIdentifier() {
return insuredObjectIdentifier;
}
public void setInsuredObjectIdentifier(String insuredObjectIdentifier) {
this.insuredObjectIdentifier = insuredObjectIdentifier;
}
}
控制器
@Controller
@Lazy
@RequestMapping("/claimsWS")
@Transactional
public class ClaimsController {
...
@RequestMapping(value = "/getContract1", method = RequestMethod.POST)
public void getContract1(@RequestBody ClaimContractCriteriaDto contractCriteriaDto, HttpServletResponse response) throws IOException {
....
writeResult(response, contratBean);
}