我在我的代码中使用供应商来调用 restTemplate 并在有异常时制作自定义消息..
但是,我的消息是,我需要通过我的 requestCall 获取信息,但是当我提出请求时,java thow 错误
...
我的代码:
public void execute() { HttpHeaders headers = buildDefaultHeaders(); UriBuilder uri = UriBuilder.fromUri(wdd3dGatewayEndpoint + API_URL); HttpEntity request = new HttpEntity(headers); this.executeRequest(() -> restTemplate.exchange(uri.build(), HttpMethod.DELETE, request, Void.class)); }
我的供应商
protected ResponseEntity executeRequest(Supplier<ResponseEntity> request) { try { ResponseEntity response = request.get(); updateSessionToken(response); return response; } catch (HttpClientErrorException | HttpServerErrorException e) { String msg = "WDD3D-Error in service communication<br>" + e.getResponseBodyAsString(); throw new MaestroException(msg); } }
现在,我尝试强制转换以获取 URL ...
protected ResponseEntity executeRequest(Supplier<ResponseEntity> request) { try { ResponseEntity response = request.get(); updateSessionToken(response); return response; } catch (HttpClientErrorException | HttpServerErrorException e) { //THROW EXEPTION HERE... PLEASE HELP... RequestEntity requestEntity = (RequestEntity) request; String url = requestEntity.getUrl().toString(); String msg = "WDD3D-Error in service communication<br>" + e.getResponseBodyAsString(); throw new MaestroException(msg); } }]