@Before public void setUp() throws Exception { MockHttpSession session = new MockHttpSession(servletContext) { @Override public String getId() { return "TEST$SESSION"; } }; MockHttpServletRequest request = new MockHttpServletRequest(servletContext); request.setSession(session); MockHttpServletResponse response = new MockHttpServletResponse(); Configuration cfg = new ConfigurationImpl(); cfg.setGraniteConfig("/WEB-INF/granite/granite-config-spring.xml"); cfg.setFlexServicesConfig("/WEB-INF/flex/services-config-spring.xml"); servletContext.setAttribute(ServletGraniteConfig.GRANITE_CONFIG_CONFIGURATION_KEY, cfg); GraniteConfig graniteConfig = ServletGraniteConfig.loadConfig(servletContext); ServicesConfig servicesConfig = ServletServicesConfig.loadConfig(servletContext); HttpGraniteContext.createThreadIntance( graniteConfig, servicesConfig, servletContext, request, response); springServiceFactory = new SpringServiceFactory(); springServiceFactory.configure(new XMap("properties")); springServiceFactory.setApplicationContext(applicationContext); }
@Before public void setUp() throws Exception { ServletContext servletContext = initServletContext(); ServletLifecycle.beginApplication(servletContext); new Initialization(servletContext).create().init(); servletContext.setAttribute(Gravity.class.getName(), mockGravity); MockHttpSession session = new MockHttpSession(servletContext) { @Override public String getId() { return "TEST$SESSION"; } }; MockHttpServletRequest request = new MockHttpServletRequest(session); MockHttpServletResponse response = new MockHttpServletResponse(); Configuration cfg = new ConfigurationImpl(); cfg.setGraniteConfig("/WEB-INF/granite/granite-config-seam.xml"); servletContext.setAttribute(ServletGraniteConfig.GRANITE_CONFIG_CONFIGURATION_KEY, cfg); GraniteConfig graniteConfig = ServletGraniteConfig.loadConfig(servletContext); ServicesConfig servicesConfig = ServletServicesConfig.loadConfig(servletContext); HttpGraniteContext.createThreadIntance( graniteConfig, servicesConfig, servletContext, request, response); interceptor.before(requestMessage); SeamServiceFactory seamFactory = new SeamServiceFactory(); seamFactory.configure(new XMap("properties")); @SuppressWarnings("unchecked") Destination destination = new Destination("seam", Collections.EMPTY_LIST, XMap.EMPTY_XMAP, null, null, null); invoker = new SeamServiceInvoker(destination, seamFactory); }
/* * (non-Javadoc) * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) */ @Override public void init(ServletConfig config) { try { super.init(config); Configuration configuration = Activator.getConfigurationService(); getServletContext() .setAttribute(ServletGraniteConfig.GRANITE_CONFIG_CONFIGURATION_KEY, configuration); graniteConfig = ServletGraniteConfig.loadConfig(getServletContext()); servicesConfig = ServletServicesConfig.loadConfig(getServletContext()); // register EventHandler ServicesConfig handle Add or Remove dataservice Dictionary<String, Object> properties = new Hashtable<String, Object>(); String[] topics = new String[] { OSGIConstants.TOPIC_GDS_ADD_SERVICE, OSGIConstants.TOPIC_GDS_REMOVE_SERVICE }; properties.put(EventConstants.EVENT_TOPIC, topics); context.registerService( EventHandler.class.getName(), new ServiceEventHandler(servicesConfig), properties); } catch (ServletException e) { log.error(e, "Could initialize OSGi service adaptor"); } }