protected <T> T doExecute(ConnectionCallback<T> action, RpcRequest request) { Assert.notNull(action, "Callback object must not be null"); Connection c = null; ConnectionSpec auth = null; try { try { request = validateRequest(request); RpcHost host = request.getHost(); auth = createConnectionSpec(request); logger.debug("connect {}", RpcUriUtils.sanitize(request.getURI(), auth)); c = this.connectionFactory.getConnection(host, auth); } catch (RpcException e) { throw getExceptionTranslator() .translate("open", RpcUriUtils.sanitize(request.getURI(), auth), e); } try { return action.doInConnection(c); } catch (RpcException e) { throw getExceptionTranslator() .translate("callback", RpcUriUtils.sanitize(request.getURI(), auth), e); } } catch (DataAccessException e) { logger.error("error in " + RpcUriUtils.sanitize(request.getURI(), auth), e); throw e; } finally { try { if (c != null) c.close(); } catch (RpcException e) { throw getExceptionTranslator() .translate("close", RpcUriUtils.sanitize(request.getURI(), auth), e); } } }