/** * 超时测试 * * @param req * @param res */ public static void asyncTimeout(HttpServletRequest req, HttpServletResponse res) { IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); iAsyncMgntInt.setAsyncCall(true); // 标志异步调用 iAsyncMgntInt.setTimeout(10000); SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); try { int result = iAsyncMgntInt.select_sysOperators_timeout(holder, errMsg); // 获取响应结果 SSysOperatorsList list = holder.value; int size = list.size(); res.getWriter().println("<a href=\"./index.html\">返回首页</a><br>"); res.getWriter().println("<pre>"); for (int i = 0; i < size; i++) { SSysOperators opers = (SSysOperators) list.get(i); res.getWriter().println(i + ":" + opers.get_loginName()); } res.getWriter().println("<a href=\"./index.html\">返回首页</a><br>"); } catch (Exception e) { try { res.getWriter().println("<pre>"); e.printStackTrace(res.getWriter()); } catch (IOException e1) { e1.printStackTrace(); } } }
/** * 获取异步请求结果 * * @param req * @param res */ public static void asyncResult(HttpServletRequest req, HttpServletResponse res) { IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); iAsyncMgntInt.setAsyncCall(true); try { String mseq = req.getParameter("mseq"); MessageSequence ms = new MessageSequence(mseq); iAsyncMgntInt.setMseq(ms); int result = iAsyncMgntInt.select_sysOperators_response(holder, errMsg); res.getWriter().println("<a href=\"./index.html\">返回首页</a></script>"); SSysOperatorsList list = holder.value; int size = list.size(); res.getWriter().println("<pre>"); for (int i = 0; i < size; i++) { SSysOperators opers = (SSysOperators) list.get(i); res.getWriter().println(i + ":" + opers.get_loginName()); } res.getWriter().println("<a href=\"./index.html\">返回首页</a></script>"); } catch (Exception e) { // TODO Auto-generated catch block try { e.printStackTrace(res.getWriter()); } catch (IOException e1) { e1.printStackTrace(); } } }
/** * 发起同步请求,获取后台信息,直接显示在页面上 * * @param req * @param res */ public static void sync(HttpServletRequest req, HttpServletResponse res) { System.setProperty("0", "aaaaaaaa"); // h.put(i+"","aaaaaaaaaaaaaaaaaaaaaaaa"); // i++; // System.out.println("*************************system prop is " + // System.getProperties()); IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); try { res.getWriter().println("<a href=\"./index.html\">返回首页</a></script>"); int result = iAsyncMgntInt.select_sysOperators(holder, errMsg); System.out.println("*****result is " + result); if (result != 0) { res.getWriter().println(errMsg.get_errorMsg() + ":" + errMsg.get_errorCode()); } SSysOperatorsList list = holder.value; int size = list.size(); res.getWriter().println("<pre>"); for (int i = 0; i < size; i++) { SSysOperators opers = (SSysOperators) list.get(i); res.getWriter().println(i + ":" + opers.get_loginName()); } res.getWriter().println("<a href=\"./index.html\">返回首页</a></script>"); } catch (Exception e) { e.printStackTrace(); } }
/** * 超时测试 * * @param req * @param res */ public static void asyncSubscribe(HttpServletRequest req, HttpServletResponse res) { IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); iAsyncMgntInt.setAsyncCall(true); // 标志异步调用 HttpSession session = req.getSession(false); Util.set(session.getId(), session); TopicCmd mc = new TopicCmd(); // 自动处理命令 mc.setSessionKey("SYS_OPER_LIST"); mc.setSessionId(session.getId()); iAsyncMgntInt.setResponseCommand(mc); iAsyncMgntInt.setMessageType("test_subscribe"); SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); try { int result = iAsyncMgntInt.select_sysOperators_subscribe(holder, errMsg); // 获取响应结果 res.getWriter().println("<html>"); res.getWriter().println("<head>"); res.getWriter().println("<title>"); res.getWriter().println("异步架构系统测试"); res.getWriter().println("</title>"); res.getWriter().println("</head>"); res.getWriter().println("<body>"); res.getWriter().println("<a href=\"./index.html\">返回首页</a><br>"); res.getWriter().println("消息订阅已发起<br>"); res.getWriter().println("<form name=\"testform\" action=\"./test\" method=\"get\">"); res.getWriter() .println("<input type=\"hidden\" name=\"method\" value=\"asyncSubscribeResult\">"); res.getWriter() .println("<input type=\"hidden\" name=\"mseq\" value=\"" + mc.getSessionKey() + "\">"); res.getWriter().println("<input type=\"submit\" name=\"test\" value=\"查看订阅情况\">"); res.getWriter().println("</form>"); res.getWriter().println("</body>"); res.getWriter().println("</html>"); } catch (Exception e) { try { res.getWriter().println("<pre>"); res.getWriter().println(e.getMessage()); } catch (IOException e1) { e1.printStackTrace(); } } }
/** * 异步请求手动处理测试 * * @param req * @param res */ public static void asyncManual(HttpServletRequest req, HttpServletResponse res) { System.out.println("*************************system prop is " + System.getProperty("0")); IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); iAsyncMgntInt.setAsyncCall(true); // 标志异步调用 SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); try { // iAsyncMgntInt.setMessageConsumer("test_worker"); int result = iAsyncMgntInt.select_sysOperators(holder, errMsg); // System.out.println("*****result is "+result); // System.out.println(iAsyncMgntInt.getMseq().getMessageKey()+ ":" // + iAsyncMgntInt.getMseq().getMessageSequence()); res.getWriter().println("<html>"); res.getWriter().println("<head>"); res.getWriter().println("<title>"); res.getWriter().println("异步架构系统测试"); res.getWriter().println("</title>"); res.getWriter().println("</head>"); res.getWriter().println("<body>"); res.getWriter().println("<form name=\"testform\" action=\"./test\" method=\"get\">"); res.getWriter().println("<input type=\"hidden\" name=\"method\" value=\"asyncResult\">"); res.getWriter() .println( "<input type=\"hidden\" name=\"mseq\" value=\"" + iAsyncMgntInt.getMseq().getMessageSequence() + "\">"); res.getWriter().println("<input type=\"submit\" name=\"test\" value=\"获取异步响应\">"); res.getWriter().println("</form>"); res.getWriter().println("</body>"); res.getWriter().println("</html>"); } catch (Exception e) { try { res.getWriter().println("<pre>"); e.printStackTrace(res.getWriter()); } catch (IOException e1) { e1.printStackTrace(); } } }
/** * 异步请求自动处理测试 * * @param req * @param res */ public static void asyncAuto(HttpServletRequest req, HttpServletResponse res) { IAsyncMgntInt iAsyncMgntInt = new IAsyncMgntInt(); iAsyncMgntInt.setAsyncCall(true); // 标志异步调用 MessageCommand mc = new SimpleResCmd(); // 自动处理命令 iAsyncMgntInt.setResponseCommand(mc); SSysOperatorsListHolder holder = new SSysOperatorsListHolder(); CBSErrorMsg errMsg = new CBSErrorMsg(); try { int result = iAsyncMgntInt.select_sysOperators(holder, errMsg); // System.out.println("*****result is "+result); // // System.out.println(iAsyncMgntInt.getMseq().getMessageKey()+ ":" // + iAsyncMgntInt.getMseq().getMessageSequence()); res.getWriter().println("<html>"); res.getWriter().println("<head>"); res.getWriter().println("<title>"); res.getWriter().println("异步架构系统测试"); res.getWriter().println("</title>"); res.getWriter().println("</head>"); res.getWriter().println("<body>"); res.getWriter().println("<a href=\"./index.html\">返回首页</a><br>"); res.getWriter().println("异步响应已由SimpleResCmd对象自动处理"); res.getWriter().println("</body>"); res.getWriter().println("</html>"); } catch (Exception e) { try { res.getWriter().println("<pre>"); e.printStackTrace(res.getWriter()); } catch (IOException e1) { e1.printStackTrace(); } } }