示例#1
0
  @Override
  public void dispatch(String o, final Callback callback) {
    ContainerRoot model = modelService.getCurrentModel().getModel();
    Channel thisChan = (Channel) model.findByPath(context.getPath());
    Set<String> outputPaths = Helper.getRequiredPortsPath(thisChan, context.getNodeName());

    // create a list of destination paths
    Set<String> destPaths = new HashSet<>();
    // process remote paths in order to add _<chanName> to the paths
    // (WsMsgBroker protocol)
    // add processed remote path to dest
    destPaths.addAll(
        channelContext
            .getRemotePortPaths()
            .stream()
            .map(remotePath -> remotePath + "_" + context.getInstanceName())
            .collect(Collectors.toList()));
    // add local connected inputs to dest
    Set<String> providedPaths =
        Helper.getProvidedPortsPath(thisChan, context.getNodeName())
            .stream()
            .map(s -> s + "_" + context.getInstanceName())
            .collect(Collectors.toSet());

    destPaths.addAll(providedPaths);
    // create the array that will store the dest
    String[] dest = new String[destPaths.size()];
    // convert list to array
    destPaths.toArray(dest);

    for (final String outputPath : outputPaths) {
      WSMsgBrokerClient client = this.clients.get(outputPath + "_" + context.getInstanceName());
      if (client != null) {
        if (callback != null) {
          client.send(
              o,
              dest,
              (from, o1) -> {
                CallbackResult result = new CallbackResult();
                result.setPayload(o1.toString());
                result.setOriginChannelPath(context.getPath());
                result.setOriginPortPath(outputPath);
                callback.onSuccess(result);
              });
        } else {
          client.send(o, dest);
        }
      } else {
        createInputClient(outputPath + "_" + context.getInstanceName());
      }
    }
  }
  /**
   * Process public call back request from payment gateway.
   *
   * @param operation
   * @param privateCallBackParameters get/post parameters
   * @return true in case in payment was ok, false in case if payment failed
   */
  public Payment createPaymentPrototype(
      final String operation, final Map privateCallBackParameters) {

    final Payment payment = new PaymentImpl();

    final Map<String, String> params =
        HttpParamsUtils.createSingleValueMap(privateCallBackParameters);

    payment.setTransactionReferenceId(params.get("x_trans_id"));
    payment.setTransactionAuthorizationCode(params.get("x_auth_code"));

    final CallbackResult res = getExternalCallbackResult(params);

    payment.setPaymentProcessorResult(res.getStatus());
    payment.setPaymentProcessorBatchSettlement(res.isSettled());
    payment.setTransactionOperationResultCode(params.get("x_response_code"));
    payment.setTransactionOperationResultMessage(
        params.get("x_response_reason_code") + " " + params.get("x_response_reason_text"));
    payment.setCardNumber(params.get("x_account_number"));
    payment.setShopperIpAddress(params.get(PaymentMiscParam.CLIENT_IP));

    return payment;
  }