/** * Creates implementation of {@link ApplicationServer} according to system property. * If system property is not set, creates default implementation. * * @return server or default */ public static ApplicationServer createApplicationServer() { String applicationServerClassName = System.getProperty(APPLICATION_SERVER_PROPERTY); if (applicationServerClassName != null) { return createApplicationServer(applicationServerClassName); } return new StagingServer(); }
/** * This template method called from the {@link #setupFacesListener()} if Sun JSF reference implementation presents. * The default implementation sets the "com.sun.faces.validateXml" "com.sun.faces.verifyObjects" init parameters to the "true" */ protected void setupSunFaces() { facesServer.addInitParameter("com.sun.faces.validateXml", "true"); facesServer.addInitParameter("com.sun.faces.verifyObjects", "true"); }
void requestAttributeRemoved(ServletRequest request, String name, Object removed) { final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent( context, request, name, removed); fireEvent(REQUEST_ATTRIBUTE_LISTENER_CLASS, new EventInvoker<ServletRequestAttributeListener>() { public void invoke(ServletRequestAttributeListener listener) { listener.attributeRemoved(event); } }); }
@Override public synchronized HttpSession getSession(boolean create) { if (!initialised) { throw new TestException("Staging server have not been initialised"); } HttpSession httpSession = this.getCurrentSession(); if (null == httpSession && create) { ServerHttpSession sessionImpl = new ServerHttpSession(); // Create proxy objects. ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (null == loader) { loader = this.getClass().getClassLoader(); } httpSession = (HttpSession) Proxy.newProxyInstance(loader, new Class[] { HttpSession.class }, getInvocationHandler(sessionImpl)); setCurrentSession(httpSession); // inform session listeners. final HttpSessionEvent event = new HttpSessionEvent(httpSession); fireEvent(SESSION_LISTENER_CLASS, new EventInvoker<HttpSessionListener>() { public void invoke(HttpSessionListener listener) { listener.sessionCreated(event); } }); sessionInstances.add(sessionImpl); } return httpSession; }
/** * This template method called from {@link #setUp()} to create {@link FacesServlet} instance. * The default implementation also tests presense of the "org.ajax4jsf.Filter" class. * If this class is avalable, these instance appended to the Faces Servlet call chain. * Default mapping to the FacesServlet instance is "*.jsf" */ protected void setupFacesServlet() { ServletHolder facesServletContainer = new ServletHolder("*.jsf", new FacesServlet()); facesServletContainer.setName("Faces Servlet"); facesServer.addServlet(facesServletContainer); try { // Check for an ajax4jsf filter. Class<? extends Filter> ajaxFilterClass = contextClassLoader .loadClass("org.ajax4jsf.Filter").asSubclass(Filter.class); Filter ajaxFilter = ajaxFilterClass.newInstance(); FilterHolder filterHolder = new FilterHolder("*.jsf", ajaxFilter); filterHolder.setName("ajax4jsf"); facesServer.addResource("/WEB-INF/web.xml", "org/jboss/test/faces/ajax-web.xml"); facesServer.addFilter(filterHolder); } catch (ClassNotFoundException e) { // No Richfaces filter, uses servlet directly. facesServer.addResource("/WEB-INF/web.xml", "org/jboss/test/faces/web.xml"); } catch (Exception e) { throw new TestException(e); } }
log.info("Init staging server"); readDefaultMimeTypes(); getInvocationHandler(context)); if(fireEvent(CONTEXT_LISTENER_CLASS, new EventInvoker<ServletContextListener>() { public void invoke(ServletContextListener listener) {
/** * <p class="changed_added_2_0"></p> * @param url * @throws MalformedURLException * @throws FacesException */ protected void setupFacesRequest(String url) throws MalformedURLException, FacesException { connection = facesServer.getConnection(new URL( url)); setupConnection(); connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer .getContext(), connection.getRequest(), connection .getResponse(), lifecycle); }
fireEvent(SESSION_LISTENER_CLASS, new EventInvoker<HttpSessionListener>() { public void invoke(HttpSessionListener listener) { sessionIterator.remove(); setCurrentSession(null); fireEvent(CONTEXT_LISTENER_CLASS, new EventInvoker<ServletContextListener>() { public void invoke(ServletContextListener listener) {
facesServer = new StagingServer(); setupFacesServlet(); setupFacesListener(); setupJsfInitParameters(); setupWebContent(); facesServer.init(); ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder .getFactory(FactoryFinder.APPLICATION_FACTORY);
@Override public void addServlet(ServletHolder servletHolder) { Map<String, String> initParameters = servletHolder.getInitParameters(); String mapping = servletHolder.getMapping(); String name = servletHolder.getName(); Servlet servlet = servletHolder.getServlet(); ServletContainer servletContainer = new ServletContainer(mapping, servlet); servletContainer.setName(name); if (initParameters != null) { for (Entry<String, String> initEntry : initParameters.entrySet()) { servletContainer.addInitParameter(initEntry.getKey(), initEntry.getValue()); } } addServlet(servletContainer); }
/** * Virtual server instance cleanup. * @throws java.lang.Exception */ @Override @After public void tearDown() throws Exception { if (null != facesContext) { facesContext.release(); facesContext = null; } if (null != connection) { if (!connection.isFinished()) { connection.finish(); } connection = null; } facesServer.destroy(); Thread.currentThread().setContextClassLoader(contextClassLoader); facesServer = null; application = null; lifecycle = null; }
/** * This template method called from the {@link #setUp()} to populate virtual server content. * The default implementation tries to load web content from directory pointed by the System property * "webroot" or same property from the "/webapp.properties" file. */ protected void setupWebContent() { String webappDirectory = System.getProperty("webroot"); File webFile = null; if (null == webappDirectory) { URL resource = this.getClass().getResource("/webapp.properties"); if (null != resource && "file".equals(resource.getProtocol())) { Properties webProperties = new Properties(); try { InputStream inputStream = resource.openStream(); webProperties.load(inputStream); inputStream.close(); webFile = new File(resource.getPath()); webFile = new File(webFile.getParentFile(), webProperties.getProperty("webroot")).getAbsoluteFile(); facesServer.addResourcesFromDirectory("/", webFile); } catch (IOException e) { throw new TestException(e); } } } else { webFile = new File(webappDirectory); facesServer.addResourcesFromDirectory("/", webFile); } }
throw new TestException("Error instantiate JSF RI listener", e); facesServer.addWebListener(listener);
@Override public synchronized HttpSession getSession(boolean create) { if (!initialised) { throw new TestException("Staging server have not been initialised"); } HttpSession httpSession = this.getCurrentSession(); if (null == httpSession && create) { ServerHttpSession sessionImpl = new ServerHttpSession(); // Create proxy objects. ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (null == loader) { loader = this.getClass().getClassLoader(); } httpSession = (HttpSession) Proxy.newProxyInstance(loader, new Class[] { HttpSession.class }, getInvocationHandler(sessionImpl)); setCurrentSession(httpSession); // inform session listeners. final HttpSessionEvent event = new HttpSessionEvent(httpSession); fireEvent(SESSION_LISTENER_CLASS, new EventInvoker<HttpSessionListener>() { public void invoke(HttpSessionListener listener) { listener.sessionCreated(event); } }); sessionInstances.add(sessionImpl); } return httpSession; }
/** * This template method called from {@link #setUp()} to create {@link FacesServlet} instance. * The default implementation also tests presense of the "org.ajax4jsf.Filter" class. * If this class is avalable, these instance appended to the Faces Servlet call chain. * Default mapping to the FacesServlet instance is "*.jsf" */ protected void setupFacesServlet() { ServletHolder facesServletContainer = new ServletHolder("*.jsf", new FacesServlet()); facesServletContainer.setName("Faces Servlet"); facesServer.addServlet(facesServletContainer); try { // Check for an ajax4jsf filter. Class<? extends Filter> ajaxFilterClass = contextClassLoader .loadClass("org.ajax4jsf.Filter").asSubclass(Filter.class); Filter ajaxFilter = ajaxFilterClass.newInstance(); FilterHolder filterHolder = new FilterHolder("*.jsf", ajaxFilter); filterHolder.setName("ajax4jsf"); facesServer.addResource("/WEB-INF/web.xml", "org/jboss/test/faces/ajax-web.xml"); facesServer.addFilter(filterHolder); } catch (ClassNotFoundException e) { // No Richfaces filter, uses servlet directly. facesServer.addResource("/WEB-INF/web.xml", "org/jboss/test/faces/web.xml"); } catch (Exception e) { throw new TestException(e); } }
log.info("Init staging server"); readDefaultMimeTypes(); getInvocationHandler(context)); if(fireEvent(CONTEXT_LISTENER_CLASS, new EventInvoker<ServletContextListener>() { public void invoke(ServletContextListener listener) {
/** * <p class="changed_added_2_0"></p> * @param url * @throws MalformedURLException * @throws FacesException */ protected void setupFacesRequest(String url) throws MalformedURLException, FacesException { connection = facesServer.getConnection(new URL( url)); setupConnection(); connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer .getContext(), connection.getRequest(), connection .getResponse(), lifecycle); }
fireEvent(SESSION_LISTENER_CLASS, new EventInvoker<HttpSessionListener>() { public void invoke(HttpSessionListener listener) { sessionIterator.remove(); setCurrentSession(null); fireEvent(CONTEXT_LISTENER_CLASS, new EventInvoker<ServletContextListener>() { public void invoke(ServletContextListener listener) {
facesServer = new StagingServer(); setupFacesServlet(); setupFacesListener(); setupJsfInitParameters(); setupWebContent(); facesServer.init(); ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder .getFactory(FactoryFinder.APPLICATION_FACTORY);
@Override public void addServlet(ServletHolder servletHolder) { Map<String, String> initParameters = servletHolder.getInitParameters(); String mapping = servletHolder.getMapping(); String name = servletHolder.getName(); Servlet servlet = servletHolder.getServlet(); ServletContainer servletContainer = new ServletContainer(mapping, servlet); servletContainer.setName(name); if (initParameters != null) { for (Entry<String, String> initEntry : initParameters.entrySet()) { servletContainer.addInitParameter(initEntry.getKey(), initEntry.getValue()); } } addServlet(servletContainer); }