@Test public void testDoPost() throws Exception { logger.info("doPost"); Server server = Help.getServer(RulesServlet.class); server.start(); try { String url = String.format("http: JSONObject jr = new JSONObject(); jr.put("name", "test doPost rule"); jr.put("text", Help.ExampleRules()[0]); Help.Res r = Help.sendPost(url, jr.toString(2)); assertEquals(200, r.getCode()); jr.remove("name"); r = Help.sendPost(url, jr.toString(2)); assertEquals(400, r.getCode()); jr.put("name", "test doPost rule"); jr.put("text", "<<this is invalid EPL>>"); r = Help.sendPost(url, jr.toString(2)); assertEquals(400, r.getCode()); } finally { server.stop(); } }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { Utils.putCorrelatorAndTrans(request); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); try { String body = Utils.getBodyAsString(request); TimeRulesStore.getInstance().saveTimeRules(body); Result r = RulesManager.make(epService, body); response.setStatus(r.getStatusCode()); response.getOutputStream().print(Encode.forHtmlContent(r.getMessage())); } catch (Exception je) { logger.error(String.format("error: %s" ,je)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
RulesServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { Utils.putCorrelatorAndTrans(request); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); try { String body = Utils.getBodyAsString(request); TimeRulesStore.getInstance().saveTimeRules(body); Result r = RulesManager.make(epService, body); response.setStatus(r.getStatusCode()); response.getOutputStream().print(Encode.forHtmlContent(r.getMessage())); } catch (Exception je) { logger.error(String.format("error: %s" ,je)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } }
RulesServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { Utils.putCorrelatorAndTrans(request); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); try { String body = Utils.getBodyAsString(request); TimeRulesStore.getInstance().saveTimeRules(body); Result r = RulesManager.make(epService, body); response.setStatus(r.getStatusCode()); response.getOutputStream().print(Encode.forHtmlContent(r.getMessage())); } catch (Exception je) { logger.error(String.format("error: %s" ,je)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }  }
RulesServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { Utils.putCorrelatorAndTrans(request); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); try { String body = Utils.getBodyAsString(request); TimeRulesStore.getInstance().saveTimeRules(body); Result r = RulesManager.make(epService, body); response.setStatus(r.getStatusCode()); response.getOutputStream().print(Encode.forHtmlContent(r.getMessage())); } catch (Exception je) { logger.error(String.format("error: %s" ,je)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }  @Override void init(); @Override void destroy(); @Override String getServletInfo(); }
RulesServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { Utils.putCorrelatorAndTrans(request); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); try { String body = Utils.getBodyAsString(request); TimeRulesStore.getInstance().saveTimeRules(body); Result r = RulesManager.make(epService, body); response.setStatus(r.getStatusCode()); response.getOutputStream().print(Encode.forHtmlContent(r.getMessage())); } catch (Exception je) { logger.error(String.format("error: %s" ,je)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }  @Override void init(); @Override void destroy(); @Override String getServletInfo();  }