예제 #1
0
 @Override
 public void contextInitialized(ServletContextEvent event) {
   try {
     // 初始化配置
     ConfigUtil.configure(
         event.getServletContext().getRealPath("/"),
         event.getServletContext().getRealPath("/WEB-INF/config/web-config.txt"));
     // 初始化日志
     PropertyConfigurator.configure(
         event.getServletContext().getRealPath("/WEB-INF/config/log4j.properties"));
     // 初始化Application
     Application.configure(event.getServletContext());
     // 初始化数据库
     HibernateSessionFactory.configure(
         event.getServletContext().getRealPath("/WEB-INF/config/hibernate.cfg.xml"));
     // 初始化业务线程池
     HttpServletThreadPoolExcutorContainer.configure(
         event.getServletContext(),
         "com.flower",
         new ThreadPoolConfig(
             ThreadPoolType.TIMER_THREADPOOL.name(),
             ThreadPoolKindEnum.SCHEDULE,
             1,
             0,
             new MyThreadFactory(ThreadPoolType.TIMER_THREADPOOL.name(), "时间线程", 1)),
         new ThreadPoolConfig(
             ThreadPoolType.LOGIC_THREADPOOL.name(),
             ThreadPoolKindEnum.FAIR,
             5,
             5,
             new MyThreadFactory(ThreadPoolType.LOGIC_THREADPOOL.name(), "逻辑线程", 5)));
   } catch (Exception e) {
     log.error("初始化Servlet容器异常", e);
   }
 }
예제 #2
0
 @Override
 public void contextDestroyed(ServletContextEvent event) {
   HttpServletThreadPoolExcutorContainer.shutdown();
   HibernateSessionFactory.shutdown();
   ScheduledExecutorService cleanSessionTimer =
       (ScheduledExecutorService)
           event
               .getServletContext()
               .getAttribute(ServletContextKeyEnum.USER_DEFINED_SESSION_CLEAN_TIMER);
   if (cleanSessionTimer != null) cleanSessionTimer.shutdown();
 }
예제 #3
0
 /**
  * 微信支付 异步通知商户支付结果
  *
  * @param request
  * @param response
  * @param out
  * @return
  * @throws Exception
  */
 @HttpListening(urlPattern = "/customer/async_inform.do", isCheckSession = true)
 public Response async_inform(
     HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception {
   // 请求返回的数据
   InputStream in = request.getInputStream();
   byte[] data1 = new byte[in.available()];
   in.read(data1);
   // 转成字符串
   String xml = new String(data1);
   log.info(" 微信返回信息 :" + xml);
   ReceiveXmlEntity xmlEntity = new ReceiveXmlProcess().getMsgEntity(xml);
   if ("FAIL".equals(xmlEntity.getReturn_code())) return Response.stationary("异步通知失败");
   StringBuilder sb = new StringBuilder("<xml>").append("\n");
   sb.append("<return_code><![CDATA[SUCCESS]]></return_code>");
   sb.append(" <return_msg><![CDATA[OK]]></return_msg>");
   sb.append("</xml>");
   // 查询此数据是否被接受处理过
   Session session = HibernateSessionFactory.getSession();
   Query query =
       session
           .createSQLQuery(
               "select * from "
                   + Transactionwx.class.getSimpleName()
                   + " where openid=? and out_trade_no=?")
           .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
           .setString(0, xmlEntity.getOpenid())
           .setString(1, xmlEntity.getOut_trade_no());
   List list = query.list();
   if (list != null || list.size() > 0) { // 被处理过的数据
     return Response.stationary(sb);
   }
   // 没有处理过存储数据       支付成功修改订单号
   if ("SUCCESS".equals(xmlEntity.getReturn_code())) {
     Transactionwx transaction = new Transactionwx();
     transaction.openid = xmlEntity.getOpenid();
     transaction.bank_type = xmlEntity.getBank_type();
     transaction.cash_fee = xmlEntity.getCash_fee();
     transaction.coupon_count = xmlEntity.getCoupon_count();
     transaction.coupon_fee = xmlEntity.getCoupon_fee();
     transaction.coupon_fee_$n = xmlEntity.getCoupon_fee_$n();
     transaction.out_trade_no = xmlEntity.getOut_trade_no();
     transaction.total_fee = xmlEntity.getTotal_fee();
     transaction.transaction_id = xmlEntity.getTransaction_id();
     Transaction t = session.beginTransaction();
     session.save(transaction);
     t.commit();
     // 修改订单状态
     String id = xmlEntity.getOut_trade_no();
     String _id = id.substring(0, 1);
     if ("j".equals(_id)) { // 竞价单  修改我的花仓
       // 得到竞价用户  和  商品实体id
       Map<String, Object> entityIdAndUid = CustomerGoodsAuctionBidHelper.getEntityIdAndUid(id);
       GoodsEntity goodEntity = new GoodsEntity();
       goodEntity.id = entityIdAndUid.get("goodsAcutionId").toString();
       goodEntity.uid = entityIdAndUid.get("uid").toString();
       t = session.beginTransaction();
       session.update(goodEntity);
       t.commit();
     }
     if ("o".equals(_id)) { // 修改订单单
       GoodsOrder order = new GoodsOrder();
       order.orderid = id;
       order.state = OrderState.getEnum(2);
       t = session.beginTransaction();
       session.update(order);
       t.commit();
     }
   }
   return Response.stationary(sb);
 }