@Test public void testInitEPService() { logger.info("initEPService"); ServletContext sc = new ServletContextMock(); EPServiceProvider result = Utils.initEPService(sc); assertEquals(sc.getAttribute("epService"), result); EPServiceProvider result2 = Utils.initEPService(sc); assertEquals(result, result2); }
public static synchronized EPServiceProvider initEPService(ServletContext sc) { Configuration configuration = new Configuration(); configuration.getEngineDefaults().getExpression().setUdfCache(false); EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME); if (epService == null) { epService = EPServiceProviderManager.getDefaultProvider(configuration); Map<String, Object> def = new HashMap<String, Object>(); def.put("id", String.class); def.put("type", String.class); def.put(Constants.SUBSERVICE_FIELD, String.class); def.put(Constants.SERVICE_FIELD, String.class); ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration(); cfg.addEventType(Constants.IOT_EVENT, def); cfg.addImport("com.telefonica.iot.perseo.utils.*"); try { cfg.addPlugInSingleRowFunction("getNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("dateToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "dateToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("timeToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "timeToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); } catch (ConfigurationException e) { logger.error(e.getMessage()); } sc.setAttribute(EPSERV_ATTR_NAME, epService); } return epService; }
Utils { public static synchronized EPServiceProvider initEPService(ServletContext sc) { Configuration configuration = new Configuration(); configuration.getEngineDefaults().getExpression().setUdfCache(false); EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME); if (epService == null) { epService = EPServiceProviderManager.getDefaultProvider(configuration); Map<String, Object> def = new HashMap<String, Object>(); def.put("id", String.class); def.put("type", String.class); def.put(Constants.SUBSERVICE_FIELD, String.class); def.put(Constants.SERVICE_FIELD, String.class); ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration(); cfg.addEventType(Constants.IOT_EVENT, def); cfg.addImport("com.telefonica.iot.perseo.utils.*"); try { cfg.addPlugInSingleRowFunction("getNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("dateToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "dateToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("timeToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "timeToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); } catch (ConfigurationException e) { logger.error(e.getMessage()); } sc.setAttribute(EPSERV_ATTR_NAME, epService); } return epService; } }
Utils { public static synchronized EPServiceProvider initEPService(ServletContext sc) { Configuration configuration = new Configuration(); configuration.getEngineDefaults().getExpression().setUdfCache(false); EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME); if (epService == null) { epService = EPServiceProviderManager.getDefaultProvider(configuration); Map<String, Object> def = new HashMap<String, Object>(); def.put("id", String.class); def.put("type", String.class); def.put(Constants.SUBSERVICE_FIELD, String.class); def.put(Constants.SERVICE_FIELD, String.class); ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration(); cfg.addEventType(Constants.IOT_EVENT, def); cfg.addImport("com.telefonica.iot.perseo.utils.*"); try { cfg.addPlugInSingleRowFunction("getNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("dateToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "dateToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("timeToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "timeToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); } catch (ConfigurationException e) { logger.error(e.getMessage()); } sc.setAttribute(EPSERV_ATTR_NAME, epService); } return epService; }  }
Utils { public static synchronized EPServiceProvider initEPService(ServletContext sc) { Configuration configuration = new Configuration(); configuration.getEngineDefaults().getExpression().setUdfCache(false); EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME); if (epService == null) { epService = EPServiceProviderManager.getDefaultProvider(configuration); Map<String, Object> def = new HashMap<String, Object>(); def.put("id", String.class); def.put("type", String.class); def.put(Constants.SUBSERVICE_FIELD, String.class); def.put(Constants.SERVICE_FIELD, String.class); ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration(); cfg.addEventType(Constants.IOT_EVENT, def); cfg.addImport("com.telefonica.iot.perseo.utils.*"); try { cfg.addPlugInSingleRowFunction("getNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("dateToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "dateToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("timeToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "timeToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); } catch (ConfigurationException e) { logger.error(e.getMessage()); } sc.setAttribute(EPSERV_ATTR_NAME, epService); } return epService; }  static synchronized EPServiceProvider initEPService(ServletContext sc); static synchronized void destroyEPService(ServletContext sc); static Map<String, Object> JSONObject2Map(JSONObject jo); static JSONObject Event2JSONObject(EventBean event); static JSONObject Statement2JSONObject(EPStatement st); static boolean DoHTTPPost(String urlStr, String content); static void putCorrelatorAndTrans(HttpServletRequest req); static String getBodyAsString(HttpServletRequest request); static void setTimerRuleHeaders(JSONObject rule); static Boolean isValidURL(String url); }
Utils { public static synchronized EPServiceProvider initEPService(ServletContext sc) { Configuration configuration = new Configuration(); configuration.getEngineDefaults().getExpression().setUdfCache(false); EPServiceProvider epService = (EPServiceProvider) sc.getAttribute(EPSERV_ATTR_NAME); if (epService == null) { epService = EPServiceProviderManager.getDefaultProvider(configuration); Map<String, Object> def = new HashMap<String, Object>(); def.put("id", String.class); def.put("type", String.class); def.put(Constants.SUBSERVICE_FIELD, String.class); def.put(Constants.SERVICE_FIELD, String.class); ConfigurationOperations cfg = epService.getEPAdministrator().getConfiguration(); cfg.addEventType(Constants.IOT_EVENT, def); cfg.addImport("com.telefonica.iot.perseo.utils.*"); try { cfg.addPlugInSingleRowFunction("getNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getMilisToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getMilisToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("dateToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "dateToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("timeToUTC", "com.telefonica.iot.perseo.utils.DateTimeUtils", "timeToUTC", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunset", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunset", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); cfg.addPlugInSingleRowFunction("getSecondsToNextSunrise", "com.telefonica.iot.perseo.utils.DateTimeUtils", "getSecondsToNextSunrise", ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED); } catch (ConfigurationException e) { logger.error(e.getMessage()); } sc.setAttribute(EPSERV_ATTR_NAME, epService); } return epService; }  static synchronized EPServiceProvider initEPService(ServletContext sc); static synchronized void destroyEPService(ServletContext sc); static Map<String, Object> JSONObject2Map(JSONObject jo); static JSONObject Event2JSONObject(EventBean event); static JSONObject Statement2JSONObject(EPStatement st); static boolean DoHTTPPost(String urlStr, String content); static void putCorrelatorAndTrans(HttpServletRequest req); static String getBodyAsString(HttpServletRequest request); static void setTimerRuleHeaders(JSONObject rule); static Boolean isValidURL(String url);  }