コード例 #1
0
  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);
      }
    }
  }
コード例 #2
0
 protected ConnectionSpec createConnectionSpec(RpcRequest request) {
   String credentials = request.getCredentials();
   if (StringUtils.hasText(credentials))
     return AccessVerifyConnectionSpec.create(request.getCredentials());
   else return new AnonymousConnectionSpec();
 }