Java SpringREST异常处理程序返回XML格式
我正在处理项目中的一个异常 这是我的GET端点:Java SpringREST异常处理程序返回XML格式,java,xml,spring,exception-handling,Java,Xml,Spring,Exception Handling,我正在处理项目中的一个异常 这是我的GET端点: @RequestMapping(method = RequestMethod.GET) public ResponseEntity<V6SubnetRec> get(@RequestBody V6SubnetRequest requestBody) throws QIPException { Site site = getSite(requestBody.getOrganization()); V6SubnetRec
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<V6SubnetRec> get(@RequestBody V6SubnetRequest requestBody) throws QIPException {
Site site = getSite(requestBody.getOrganization());
V6SubnetRec wsSubnet = (V6SubnetRec) requestBody.getV6Subnet();
V6SubnetRec v6SubnetRec = null;
try {
v6SubnetRec = getQipService1().getV6Subnets(wsSubnet, site);
} catch (Exception e) {
log.error(Keys.QIP_CALLOUT_ERROR, e);
throw new RestException(e);
}
return new ResponseEntity<V6SubnetRec>(v6SubnetRec, HttpStatus.OK);
}
@ExceptionHandler(RestException.class)
public ResponseEntity rulesForRestException(RestException restEx){
return new ResponseEntity(restEx.getResponse().getContent(), restEx.getResponse().getStatus());
}
当我使用URL请求(使用JSON格式返回)时,它将返回HTTP状态代码404并包含内容。没关系。
但是,当我用URL(用XML格式返回)请求相同的请求时,它返回HTTP状态代码500,就像一个正常的异常一样,它不会作为JSON格式处理
我希望得到类似于请求JSON格式时的结果
谢谢。我已经解决了我的问题。这是唯一的改变
restEx.getResponse().getContent()
进入
restEx.getResponse().getContent()
restEx.getResponse().getContent().toString()