public String sendCommand(String command, String param) throws IOException {
   System.out.println("Client send: '" + command + ":" + param + "'");
   List<Object> params = new ArrayList<Object>();
   params.add(command);
   params.add(param);
   String result;
   try {
     result = (String) client.execute("Bank.handle", params);
     System.out.println("Client receive: '" + result + "'");
   } catch (XmlRpcException e) {
   }
   return (result.length() > 0 ? result : null);
 }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    try {
      Scanner scan = new Scanner(System.in);

      System.out.println("Ingrese el primer parámetro: ");
      int a = scan.nextInt();
      System.out.println("Ingrese el segundo parámetro: ");
      int b = scan.nextInt();

      // Creación de un cliente
      XmlRpcClient server = new XmlRpcClient(server_url);

      // Lista de parámetros
      Vector params = new Vector();
      params.addElement(a);
      params.addElement(b);

      // LLamada al servidor
      Hashtable result = (Hashtable) server.execute("calculadora.operaciones", params);
      int suma = ((Integer) result.get("suma")).intValue();
      int resta = ((Integer) result.get("resta")).intValue();
      int multiplicacion = ((Integer) result.get("multiplicacion")).intValue();

      // Imprimir el resultado
      System.out.println("Resultado");
      System.out.println("Suma: " + Integer.toString(suma));
      System.out.println("Resta: " + Integer.toString(resta));
      System.out.println("Multiplicacion: " + Integer.toString(multiplicacion));

    } catch (XmlRpcException exception) {
      System.err.println(
          "JavaClient: XML-RPC Fault #"
              + Integer.toString(exception.code)
              + ": "
              + exception.toString());
    } catch (IOException exception) {
      System.err.println("JavaClient: " + exception.toString());
    }
  }
Ejemplo n.º 3
0
  private PaymentAuthorizationDTO makeCall(Map<String, Object> data, boolean isCharge)
      throws XmlRpcException, MalformedURLException, PluggableTaskException {

    URL callURL = null;
    if ("true".equals(getOptionalParameter(PARAMETER_TEST.getName(), "false"))) {
      callURL = new URL(TEST_URL);
      log.debug("Running Atlas task in test mode!");
    } else {
      callURL = new URL(URL);
    }
    String merchantAccountCode = ensureGetParameter(PARAMETER_MERCHANT_ACCOUNT_CODE.getName());

    int merchantCode = Integer.parseInt(merchantAccountCode);
    merchantCode = merchantCode - (merchantCode % 1000);

    XmlRpcClient paymentProcessor = new XmlRpcClient();
    paymentProcessor.setTransportFactory(new XmlRpcCommonsTransportFactory(paymentProcessor));

    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(callURL);
    config.setEnabledForExtensions(true);
    config.setConnectionTimeout(CONNECTION_TIME_OUT);
    config.setReplyTimeout(REPLY_TIME_OUT);

    paymentProcessor.setConfig(config);

    List<Map<String, Object>> transactionRequestList = new ArrayList<Map<String, Object>>(1);
    transactionRequestList.add(data);

    Map<String, Object> configParam = new HashMap<String, Object>();
    if (isCharge) {
      configParam.put("waitConfirmation", "ignore");
    } else {
      configParam.put("waitConfirmation", "terminate");
    }

    Object[] params =
        new Object[] {
          String.valueOf(merchantCode),
          ensureGetParameter(PARAMETER_PASSWORD.getName()),
          transactionRequestList,
          configParam
        };

    Object[] resresponse = (Object[]) paymentProcessor.execute("XMLRPCGates.processRetail", params);

    Map<String, Object> transactionResponseMap = (Map<String, Object>) resresponse[0];

    log.debug("Got response:" + transactionResponseMap);

    boolean isCredit = "credit-response".equals(transactionResponseMap.get("type"));

    PaymentAuthorizationDTO dbRow = new PaymentAuthorizationDTO();
    if (!isCredit && "A01".equals(transactionResponseMap.get("responseCode"))) {
      dbRow.setCode1("1"); // code if 1 it is ok
    } else if (isCredit && "A02".equals(transactionResponseMap.get("responseCode"))) {
      dbRow.setCode1("1");
    } else if ('A' != ((String) transactionResponseMap.get("responseCode")).charAt(0)) {
      dbRow.setCode1("2");
    } else {
      dbRow.setCode1("0");
    }
    dbRow.setCode3((String) transactionResponseMap.get("responseCode"));
    dbRow.setResponseMessage((String) transactionResponseMap.get("responseMessage"));
    dbRow.setApprovalCode((String) transactionResponseMap.get("processorCode"));
    dbRow.setAvs((String) transactionResponseMap.get("avsResultCode"));
    dbRow.setTransactionId((String) transactionResponseMap.get("referenceNumber"));
    dbRow.setProcessor("Intrannuity");
    return dbRow;
  }