Ejemplo n.º 1
0
 private boolean requiresCredentials(RpcRequest request) {
   if (!StringUtils.hasText(request.getRpcContext())
       && XUS_INTRO_MSG.equals(request.getRpcName())) {
     return false;
   } else {
     return true;
   }
 }
Ejemplo n.º 2
0
 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, null, null),
           rpcContext,
           rpcName,
           params);
   if (getTimeout() > 0) request.setTimeout(getTimeout());
   return request;
 }
Ejemplo n.º 3
0
 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);
   }
 }
Ejemplo n.º 4
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);
      }
    }
  }
Ejemplo n.º 5
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);
      }
    }
  }
Ejemplo n.º 6
0
 protected RpcRequest createRpcRequest(String uri, List params) {
   RpcRequest request = new RpcRequest(uri, params);
   if (getTimeout() > 0) request.setTimeout(getTimeout());
   return request;
 }
Ejemplo n.º 7
0
  private void outputRequestInfo(String sMessage, RpcRequest request) {
    String sCRLF = System.getProperty("line.separator");
    StringBuffer sbText = new StringBuffer();
    sbText.append(sMessage + sCRLF);
    sbText.append("RpcTemplate: Dumping contents of request: " + sCRLF + sCRLF);
    sbText.append(
        "Got here by the following trace: "
            + Arrays.toString(Thread.currentThread().getStackTrace())
            + sCRLF
            + sCRLF);

    if (request != null) {
      sbText.append("    credentials: " + request.getCredentials() + sCRLF);
      sbText.append("    rpcContext: " + request.getRpcContext() + sCRLF);
      sbText.append("    rpcName: " + request.getRpcName() + sCRLF);
      sbText.append("    rpcVersion: " + request.getRpcVersion() + sCRLF);
      sbText.append("    timeout: " + request.getTimeout() + sCRLF);
      sbText.append("    uriString: " + request.getUriString() + sCRLF);

      if ((request.getParams() != null) && (request.getParams().size() > 0)) {
        int i = 0;
        for (RpcParam oRpcParam : request.getParams()) {
          sbText.append("    rpcParam[" + i + "]:" + sCRLF);
          sbText.append("        type: " + oRpcParam.getType() + sCRLF);
          sbText.append("        value: " + oRpcParam.getValue() + sCRLF);
          i++;
        }
      }

      if (request.getHost() != null) {
        sbText.append("    host:" + sCRLF);
        sbText.append("        hostname: " + request.getHost().getHostname() + sCRLF);
        sbText.append("        port: " + request.getHost().getPort() + sCRLF);
        sbText.append("        scheme: " + request.getHost().getScheme() + sCRLF);
      }
    } else {
      sbText.append("    request was null" + sCRLF);
    }

    logger.debug(sbText.toString());
  }
Ejemplo n.º 8
0
 protected ConnectionSpec createConnectionSpec(RpcRequest request) {
   return ConnectionSpecFactory.create(request.getCredentials());
 }