Esempio n. 1
0
 public SubmitThread(Channel channel) {
   setDaemon(true);
   this.channel = channel;
   if (null != channel.getSubmitRate()) {
     this.smgFlowLimit = channel.getSubmitRate();
   }
   this.queue = new LinkedBlockingDeque<SmQueue>(smgFlowLimit);
   this.watchDataThreadPool = new ScheduledThreadPoolExecutor(1);
   this.submitDataThreadPool = Executors.newFixedThreadPool(2);
   lastDrainToTime = System.currentTimeMillis();
 }
Esempio n. 2
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("utf-8");

    PrintWriter out = response.getWriter();

    String uri = request.getRequestURI();
    if (StringUtils.isNotEmpty(uri) && uri.equals("/sms")) {
      InputStream is = request.getInputStream();
      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
      StringBuilder sb = new StringBuilder();
      String line = null;
      try {
        while ((line = reader.readLine()) != null) {
          sb.append(line);
        }
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        try {
          is.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      String xmlStr = sb.toString();

      SYNCPacket syncPacket = JaxbUtils.converyToJavaBean(xmlStr, SYNCPacket.class);
      if (null != syncPacket) {
        ChannelLog.log(
            logger, "recv msg:" + syncPacket.toString(), LevelUtils.getSucLevel(channel.getId()));

        if (syncPacket.getType().intValue() == 1) {
          // 上行
          MtVo mtVo =
              new MtVo(
                  2,
                  channel.getId(),
                  syncPacket.getMobile(),
                  syncPacket.getMsg(),
                  channel.getAccount() + "#" + syncPacket.getPort());
          SmsCache.queue4.add(mtVo);
        }

        if (syncPacket.getType().intValue() == 4) {
          // 状态报告
          DelivVo delivVo =
              new DelivVo(
                  syncPacket.getCpmid(),
                  channel.getId(),
                  syncPacket.getMsg(),
                  sdf.format(new Date()));
          SmsCache.queue3.add(delivVo);
        }

        out.println(
            JaxbUtils.convertToXml(
                new SYNCResponse(syncPacket.getMid(), syncPacket.getCpmid(), "0"), "UTF-8"));
      }
    } else {
      out.println(
          "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
      out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
      out.println("<head>");
      out.println("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
      out.println("<title>Tips</title>");
      out.println("<body>");
      out.println("<h1>not support uri [" + uri + "]</h1>");
      out.println("</body>");
      out.println("</html>");
    }
  }
Esempio n. 3
0
  @Override
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("utf-8");

    PrintWriter out = response.getWriter();

    String uri = request.getRequestURI();
    if (StringUtils.isNotEmpty(uri) && uri.equals("/smsMsg")) {
      String status = request.getParameter("status");
      if (StringUtils.isNotEmpty(status)) {
        // 报告消息
        String msgid = request.getParameter("msgid");
        String reportTime = request.getParameter("reportTime");
        String mobile = request.getParameter("mobile");
        if (StringUtils.isNotEmpty(msgid)
            && StringUtils.isNotEmpty(reportTime)
            && StringUtils.isNotEmpty(mobile)) {
          Date date = new Date();
          String time = sdf.format(date);
          DelivVo delivVo = new DelivVo(Long.parseLong(msgid), channel.getId(), status, time);
          ChannelLog.log(
              logger,
              "receive report:msgId=" + msgid + ";state=" + status + ";time=" + time + ";",
              LevelUtils.getSucLevel(channel.getId()));
          SmsCache.queue3.add(delivVo);

          out.println("0");
        } else {
          out.println(
              "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
          out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
          out.println("<head>");
          out.println("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
          out.println("<title>Tips</title>");
          out.println("<body>");
          out.println("<h1>parameter is error</h1>");
          out.println("</body>");
          out.println("</html>");
        }
      } else {
        // 上行消息
        String msg = request.getParameter("msg");
        String destcode = request.getParameter("destcode");
        String moTime = request.getParameter("moTime");
        String mobile = request.getParameter("mobile");

        if (StringUtils.isNotEmpty(msg)
            && StringUtils.isNotEmpty(destcode)
            && StringUtils.isNotEmpty(moTime)
            && StringUtils.isNotEmpty(mobile)) {
          Date date = new Date();
          String time = sdf.format(date);
          MtVo mtVo =
              new MtVo(2, channel.getId(), mobile, msg, channel.getAccount() + "#" + destcode);
          ChannelLog.log(
              logger,
              "receive deliver:phone="
                  + mobile
                  + ";expid="
                  + destcode
                  + ";content="
                  + msg
                  + ";time="
                  + time
                  + ";",
              LevelUtils.getSucLevel(channel.getId()));
          SmsCache.queue4.add(mtVo);

          out.println("0");
        } else {
          out.println(
              "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
          out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
          out.println("<head>");
          out.println("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
          out.println("<title>Tips</title>");
          out.println("<body>");
          out.println("<h1>parameter is error</h1>");
          out.println("</body>");
          out.println("</html>");
        }
      }
    } else {
      out.println(
          "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
      out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
      out.println("<head>");
      out.println("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
      out.println("<title>Tips</title>");
      out.println("<body>");
      out.println("<h1>not support uri [" + uri + "]</h1>");
      out.println("</body>");
      out.println("</html>");
    }
  }