I Use the Supplier in my code to call restTemplate and make the custom Message when have exception..
But, im my message, i need get information by my requestCall, But when i cast the request the java thow error
...
My code:
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)); }
My Supplier
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); } }
Now, i try cast to get 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); } }]
You should use the
get()method of theSupplier, see more in the docs.