Beispiel #1
0
  protected RpcResponse doExecute(RpcRequest request) {
    Connection c = null;
    ConnectionSpec auth = null;
    try {
      try {
        outputRequestInfo("doExecute: Before validateRequest...", request);
        request = validateRequest(request);
        outputRequestInfo("doExecute: After validateRequest...", request);
        RpcHost host = request.getHost();
        auth = createConnectionSpec(request);
        outputAuthInfo(auth);
        c = this.connectionFactory.getConnection(host, auth);
      } catch (RpcException e) {
        logger.error("doExecute: RpcException occurred.  Error: " + e.getMessage(), e);
        fireRpcExceptionEvent(request, e);
        throw getExceptionTranslator()
            .translate("open", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
      try {
        logger.debug("executing {}", RpcUriUtils.sanitize(request.getUriString(), auth));

        RpcResponse response = c.send(request);

        logger.debug("received  {}", response.toString());

        fireRpcResponseEvent(request, response);

        return response;
      } catch (RpcException e) {
        fireRpcExceptionEvent(request, e);
        throw getExceptionTranslator()
            .translate("send", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
    } catch (DataAccessException e) {
      if (e instanceof PermissionDeniedDataAccessException) {
        logger.debug(
            "permission denied in " + RpcUriUtils.sanitize(request.getUriString(), auth), e);
      } else {
        logger.error("error in  " + RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
      throw e;
    } finally {
      try {
        if (c != null) c.close();
      } catch (RpcException e) {
        fireRpcExceptionEvent(request, e);
        throw getExceptionTranslator()
            .translate("close", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
    }
  }
Beispiel #2
0
  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.getUriString(), auth));
        c = this.connectionFactory.getConnection(host, auth);
      } catch (RpcException e) {
        throw getExceptionTranslator()
            .translate("open", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
      try {
        return action.doInConnection(c);
      } catch (RpcException e) {
        throw getExceptionTranslator()
            .translate("callback", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
    } catch (DataAccessException e) {
      if (e instanceof PermissionDeniedDataAccessException) {
        logger.debug(
            "permission denied in " + RpcUriUtils.sanitize(request.getUriString(), auth), e);
      } else {
        logger.error("error in  " + RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
      throw e;
    } finally {
      try {
        if (c != null) c.close();
      } catch (RpcException e) {
        throw getExceptionTranslator()
            .translate("close", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
    }
  }