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); } } }
protected RpcResponse doExecute(RpcRequest request) { Connection c = null; AccessVerifyConnectionSpec auth = null; try { try { request = validateRequest(request); RpcHost host = request.getHost(); auth = AccessVerifyConnectionSpec.create(request.getCredentials().toString()); c = this.connectionFactory.getConnection(host, auth); } catch (RpcException e) { if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, e)); throw getExceptionTranslator() .translate("open", RpcUriUtils.sanitize(request.getURI(), auth), e); } try { logger.debug("executing {}", RpcUriUtils.sanitize(request.getURI(), auth)); RpcResponse response = c.send(request); logger.debug("received {}", RpcUriUtils.sanitize(request.getURI(), auth)); if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, response)); return response; } catch (RpcException e) { if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, e)); throw getExceptionTranslator() .translate("send", 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) { if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, e)); throw getExceptionTranslator() .translate("close", RpcUriUtils.sanitize(request.getURI(), auth), e); } } }