예제 #1
0
  protected CommandMessage sendOrder(CommandMessage message, ServiceRequest request) {
    CommandMessage result = null;

    String sessionId = message.getCorrelationID();

    try {
      message.setUserId(0);
      // message.setUserName(request.getUsername());
      message.setChannel(Constants.CHANNEL_WEB);

      // String requestContent = getRequest(sessionId, request);

      message.setRequestValue(ResponseConstants.SESSION_ID, sessionId);
      // message.setRequestValue(ResponseConstants.VALUE, requestContent);

      result = sendOrder(message, sessionId, 30000);
      // result = new CommandMessage();
      // result.setStatus(Constants.ORDER_STATUS_APPROVED);
      // result.setCause(Constants.SUCCESS);
      // Thread.sleep(1200);

    } catch (Exception e) {
      log.error(e);
    }

    if (result != null) {
      if (log.isDebugEnabled()) {
        // log.debug("response: " + result.toString());
      }
    } else {
      log.error("request with sessionId = " + sessionId + " has response is null");
    }

    return result;
  }
예제 #2
0
  public boolean getBalanceQuery(
      CommandInstance instance, ProvisioningCommand provisioningCommand, CommandMessage request)
      throws Exception {
    Connection connection = Database.getConnection();

    PreparedStatement stmtUsage = null;
    ResultSet rsUsage = null;

    PreparedStatement stmtBalance = null;
    ResultSet rsBalance = null;
    try {
      request.setCause("success");

      double balanceAmount = 0.0D;

      String SQL =
          "Select * From SubscriberBalance Where sourceAddress = ? and balanceType = 'LOYALTY' ";

      stmtBalance = connection.prepareStatement(SQL);
      stmtBalance.setString(1, request.getIsdn());

      rsBalance = stmtBalance.executeQuery();

      if (rsBalance.next()) {
        balanceAmount = rsBalance.getDouble("balanceAmount");
      } else {
        throw new AppException(NOT_REGISTERED);
      }

      SQL =
          "Select * From SubscriberRank Where cycleDate = ? and sourceAddress = ? and balanceType = 'LOYALTY'";

      stmtUsage = connection.prepareStatement(SQL);

      stmtUsage.setDate(1, new java.sql.Date(request.getCycleDate().getTime()));
      stmtUsage.setString(2, request.getIsdn());

      rsUsage = stmtUsage.executeQuery();

      String response = "";

      double totalAmount = 0.0D;

      RankEntry rankRule = null;

      String rankStartDate = "";
      String rankExpirationDate = "";

      if (rsUsage.next()) {
        request.setCause("success");

        if (rsUsage.getDate("expirationDate") == null) {
          request.setCause("not-exist");
        } else {
          rankRule = RankFactory.getCache().getRank(rsUsage.getLong("rankId"));
        }

        totalAmount = rsUsage.getDouble("totalAmount");

        SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
        if (rsUsage.getDate("startDate") != null) {
          rankStartDate = formatDate.format(rsUsage.getDate("startDate"));
        }
        if (rsUsage.getDate("expirationDate") != null) {
          rankExpirationDate = formatDate.format(rsUsage.getDate("expirationDate"));
        }
      } else {
        request.setCause(NOT_REGISTERED);
      }

      // response = ProductFactory.getCache().getProductMessage(request, "vni");

      if (rankRule != null) {
        response =
            response.replaceAll(
                "<totalAmount>", String.valueOf(new Double(totalAmount).longValue()));
        response =
            response.replaceAll(
                "<balanceAmount>", String.valueOf(new Double(balanceAmount).longValue()));
        response = response.replaceAll("<fromDate>", rankStartDate);
        response = response.replaceAll("<toDate>", rankExpirationDate);
        response = response.replaceAll("<rank>", rankRule.getTitle());
      }

      // instance.getDispatcher().sendSMS(request, request.getServiceAddress(), request.getIsdn(),
      // response);

      request.setStatus(0);
    } catch (AppException e) {
      request.setCause(e.getMessage());
    } catch (Exception e) {
      throw e;
    } finally {
      Database.closeObject(rsUsage);
      Database.closeObject(stmtUsage);
      Database.closeObject(rsBalance);
      Database.closeObject(stmtBalance);

      Database.closeObject(connection);
    }
    return true;
  }
예제 #3
0
  public void copyTo(CommandMessage destination) {
    if (destination == null) {
      return;
    }

    destination.setCorrelationID(correlationID);
    destination.setRequestTime(requestTime);
    destination.setResponseTime(responseTime);
    destination.setOrderId(orderId);
    destination.setOrderDate(orderDate);
    destination.setCycleDate(cycleDate);

    destination.setCompanyId(companyId);
    destination.setGroupId(groupId);
    destination.setUserId(userId);
    destination.setUserName(userName);
    destination.setMerchantId(merchantId);
    destination.setAgentId(agentId);

    destination.setSubscriberId(subscriberId);
    destination.setSubPackageId(subPackageId);
    destination.setSubProductId(subProductId);

    destination.setSegmentId(segmentId);
    destination.setCampaignId(campaignId);
    destination.setRankId(rankId);

    destination.setChannel(channel);
    destination.setServiceAddress(serviceAddress);
    destination.setKeyword(keyword);
    destination.setIsdn(isdn);
    destination.setSubscriberType(subscriberType);
    destination.setShipTo(shipTo);
    destination.setNumSMS(numSMS);

    destination.setActionType(actionType);
    destination.setProductId(productId);
    destination.setAssociateProductId(associateProductId);
    destination.setContentCode(contentCode);
    destination.setContentType(contentType);

    destination.setOfferPrice(offerPrice);
    destination.setPrice(price);
    destination.setQuantity(quantity);
    destination.setDiscount(discount);
    destination.setAmount(amount);
    destination.setScore(score);
    destination.setFullOfCharge(fullOfCharge);

    destination.setProvisioningId(provisioningId);
    destination.setProvisioningType(provisioningType);
    destination.setCommandId(commandId);

    destination.setPaid(paid);

    destination.setFullOfCharge(fullOfCharge);
    destination.setRouteId(routeId);
    destination.setCompletedCommands(completedCommands);
    destination.setParameters(parameters);

    destination.setTimeout(timeout);
    destination.setContent(content);
    destination.setChargeMode(chargeMode);
    destination.setDeliveryWapHref(deliveryWapHref);
    destination.setDeliveryWapTitle(deliveryWapTitle);
    destination.setSecretCode(secretCode);
    destination.setSerial(serial);
    destination.setBalanceType(balanceType);
  }
예제 #4
0
  public CommandMessage sendOrder(Object request, String correlationId, long timeout)
      throws Exception {
    if (timeout <= 0) {
      timeout = 30000;
    }

    long startTime = System.currentTimeMillis();

    QueueSession session = null;
    MessageProducer producer = null;
    Message message = null;
    Message callBack = null;

    CommandMessage response = null;

    if (request instanceof CommandMessage) {
      response = (CommandMessage) request;
    } else {
      response = new CommandMessage();
    }

    try {
      Queue sendQueue = QueueFactory.getQueue(QueueFactory.ORDER_REQUEST_QUEUE);
      session = QueueFactory.getSession();
      message = QueueFactory.createObjectMessage(session, request);
      producer = session.createProducer(sendQueue);

      try {
        long beforeSend = System.currentTimeMillis();
        producer.send(message);
        long afterSend = System.currentTimeMillis();
        log.info(
            "Send:"
                + (afterSend - beforeSend)
                + ((afterSend - beforeSend) > 20 ? "|high" : "|low")
                + "|SessionId:"
                + correlationId);
      } catch (Exception ex) {
        log.info("Send message error");
        throw ex;
      } finally {
        QueueFactory.closeQueue(producer);
        QueueFactory.closeQueue(session);
      }
      if (!correlationId.equals("")) {
        startTime = System.currentTimeMillis();
        long beforeReceive = System.currentTimeMillis();

        QueueFactory.callbackListerner.put(message.getJMSCorrelationID(), message);
        synchronized (message) {
          try {
            message.wait(timeout);
          } catch (Exception e) {

          } finally {
            callBack = (Message) QueueFactory.callbackOrder.remove(message.getJMSCorrelationID());
            QueueFactory.callbackListerner.remove(message.getJMSCorrelationID());
          }
        }

        long afterReceive = System.currentTimeMillis();

        log.info(
            "Receive:"
                + (afterReceive - beforeReceive)
                + ((afterReceive - beforeReceive) > 300 ? "|high " : "|low")
                + "|SessionId:'"
                + correlationId);
      }
      if (callBack == null) {
        throw new AppException("time-out");
      }
      Object content = QueueFactory.getContentMessage(callBack);

      if (content != null) {
        if (content instanceof CommandMessage) {
          response = (CommandMessage) content;
        } else {
          response.setStatus(Constants.ORDER_STATUS_DENIED);
          response.setCause(Constants.ERROR);
        }
      } else {
        response.setStatus(Constants.ORDER_STATUS_DENIED);
        response.setCause(Constants.ERROR_TIMEOUT);
      }

      log.info(
          "Cost time:" + (System.currentTimeMillis() - startTime) + "|sessionId:" + correlationId);
    } catch (Exception e) {
      log.info(e);
      response.setStatus(Constants.ORDER_STATUS_DENIED);
      response.setCause(Constants.ERROR_RESOURCE_BUSY);
      throw e;
    } finally {
    }

    if ((response != null) && (response.getStatus() == Constants.ORDER_STATUS_DENIED)) {
      log.error("sessionId = " + correlationId + ", timeout = " + timeout + " : " + response);
    }

    return response;
  }
예제 #5
0
  public CommandMessage parser(
      OrderRoutingInstance instance, ProductRoute orderRoute, CommandMessage order)
      throws Exception {
    Exception error = null;

    try {
      // check SMS syntax
      if (order.getChannel().equals("SMS")) {
        smsParser(instance, orderRoute, order);
      }

      if (order.getStatus() != Constants.ORDER_STATUS_DENIED) {
        order.setCause(orderRoute.getKeyword());

        order.setStatus(Constants.ORDER_STATUS_APPROVED);

        SubscriberCampaignImpl.createCampaignEvent(
            order.getUserId(),
            order.getUserName(),
            order.getOrderId(),
            order.getOrderDate(),
            order.getSubscriberId(),
            order.getSubProductId(),
            order.getIsdn(),
            order.getSubscriberType(),
            order.getProductId(),
            order.getServiceAddress(),
            order.getKeyword(),
            order.getCampaignId(),
            order.getSegmentId(),
            null,
            Constants.DEFAULT_ID,
            "",
            Constants.ORDER_STATUS_PENDING);
      }
    } catch (Exception e) {
      error = e;
    }

    if (error != null) {
      order.setStatus(Constants.ORDER_STATUS_DENIED);

      if (error instanceof AppException) {
        order.setCause(error.getMessage());
      } else {
        order.setDescription(error.getMessage());
      }
    }

    if ((error != null) && !(error instanceof AppException)) {
      throw error;
    }

    return order;
  }
예제 #6
0
  // //////////////////////////////////////////////////////
  // process session
  // Author : ThangPV
  // Created Date : 16/09/2004
  // //////////////////////////////////////////////////////
  public void doProcessSession() throws Exception {
    try {

      long startIsdn = Long.parseLong(isdn);
      long maxIsdn = startIsdn;
      if (!endIsdn.equals("")) {
        maxIsdn = Long.parseLong(endIsdn);
      }

      if (maxIsdn <= startIsdn) maxIsdn = startIsdn;

      int count = 0;
      long currentIsdn = startIsdn;

      logMonitor("Begin to send message.");

      while (currentIsdn <= maxIsdn && isAvailable()) {
        for (int i = 0; i < batchSize && currentIsdn <= maxIsdn && isAvailable(); i++) {
          CommandMessage order = new CommandMessage();

          order.setChannel(channel);

          if (channel.equals(Constants.CHANNEL_SMS)) {
            order.setProvisioningType("SMSC");
          }

          order.setUserId(0);
          if (deliveryUser.equals("")) order.setUserName("system");
          else order.setUserName(deliveryUser);

          order.setServiceAddress(serviceAddress);
          order.setIsdn(String.valueOf(currentIsdn));
          order.setShipTo(shipTo);
          order.setTimeout(orderTimeout * 1000);

          order.setKeyword(keyword);

          MQConnection connection = null;
          try {
            connection = getMQConnection();
            connection.sendMessage(
                order,
                "",
                0,
                queueWorking,
                orderTimeout * 1000,
                new String[] {"SystemID"},
                new Object[] {new String(order.getUserName())});
          } finally {
            returnMQConnection(connection);
          }

          // if (displayDebug)
          logMonitor(order.toLogString());

          currentIsdn++;
          count++;
        }
        logMonitor("message count: " + count);
        Thread.sleep(timeBetweenLoop);
      }
    } catch (Exception e) {
      throw e;
    }
  }
  @Override
  public void checkPromotion(
      OrderRoutingInstance instance, ProductRoute orderRoute, CommandMessage order)
      throws Exception {
    if (order.getActionType().equals(Constants.ACTION_REGISTER)) {
      String strSQL_Select =
          "select statis_list_id, status "
              + " from max_sms_promotion_eligible "
              + " where 1 = 1 "
              + "       and isdn = ? "
              + "       and status = ? ";

      String strISDN = order.getIsdn();

      Connection connection = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      try {
        connection = Database.getConnection();
        stmt = connection.prepareStatement(strSQL_Select);
        stmt.setString(1, strISDN);
        stmt.setInt(2, Constants.STATUS_INACTIVE);
        rs = stmt.executeQuery();
        if (!rs.next()) {
          throw new AppException(Constants.ERROR_INVALID_PROMOTION);
        } else {
          int iStatus = rs.getInt(2);
          if (iStatus == Constants.STATUS_ACTIVE || iStatus == Constants.STATUS_CANCEL) {
            throw new AppException(Constants.ERROR_REGISTERED);
          }
          String primaryKey = rs.getString(1);
          order.setResponseValue("primaryKey", primaryKey);
        }
      } finally {
        Database.closeObject(stmt);
        Database.closeObject(rs);
        Database.closeObject(connection);
      }
    } else if (order.getActionType().equals(Constants.ACTION_UNREGISTER)) {
      String strSQL_Select =
          "select to_char(expirationdate,'dd/mm/yyyy hh24:mi:ss')"
              + "             from subscriberproduct "
              + "             where 1 = 1 "
              + "                   and sysdate < expirationdate "
              + "                   and productid = ? and isdn = ?";

      Connection connection = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      try {
        connection = Database.getConnection();
        stmt = connection.prepareStatement(strSQL_Select);
        stmt.setLong(1, order.getProductId());
        stmt.setString(2, order.getIsdn());
        rs = stmt.executeQuery();
        if (!rs.next()) {
          throw new AppException(Constants.ERROR_INVALID_PROMOTION);
        }
      } finally {
        Database.closeObject(stmt);
        Database.closeObject(rs);
        Database.closeObject(connection);
      }
    }
  }