private boolean requiresCredentials(RpcRequest request) {
   if (!StringUtils.hasText(request.getRpcContext())
       && XUS_INTRO_MSG.equals(request.getRpcName())) {
     return false;
   } else {
     return true;
   }
 }
 protected RpcRequest createRpcRequest(
     RpcHost host,
     String division,
     String accessCode,
     String verifyCode,
     String rpcContext,
     String rpcName,
     List params) {
   RpcRequest request =
       new RpcRequest(
           host,
           RpcUriUtils.toCredentials(division, accessCode, verifyCode),
           rpcContext,
           rpcName,
           params);
   if (getTimeout() > 0) request.setTimeout(getTimeout());
   return request;
 }
 protected RpcRequest validateRequest(RpcRequest request) {
   RpcHost host = request.getHost();
   if (host == null || host.getPort() == -1) {
     Assert.notNull(
         getHostResolver(),
         "[Assertion failed] - attempted to resolve ambiguous host, but hostResolver was null");
     host = getHostResolver().resolve(host != null ? host.getHostname() : null);
   }
   if (requiresCredentials(request)) {
     String credentials = request.getCredentials();
     if (!StringUtils.hasText(credentials)) {
       Assert.notNull(
           getCredentialsProvider(),
           "[Assertion failed] - attempted to provide credentials for RPC request without them, but credentialsProvider was null");
       credentials = getCredentialsProvider().getCredentials(host, credentials);
     }
     return request = new RpcRequest(host, credentials, request);
   } else {
     return request = new RpcRequest(host, null, request);
   }
 }
  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);
      }
    }
  }
 protected ConnectionSpec createConnectionSpec(RpcRequest request) {
   String credentials = request.getCredentials();
   if (StringUtils.hasText(credentials))
     return AccessVerifyConnectionSpec.create(request.getCredentials());
   else return new AnonymousConnectionSpec();
 }
 protected RpcRequest createRpcRequest(String uri, List params) {
   RpcRequest request = new RpcRequest(uri, params);
   if (getTimeout() > 0) request.setTimeout(getTimeout());
   return request;
 }