1 package com.icesoft.faces.webapp.http.servlet; 2 3 import com.icesoft.faces.webapp.http.common.Configuration; 4 import com.icesoft.faces.webapp.http.common.Server; 5 import com.icesoft.faces.webapp.http.core.ViewQueue; 6 7 import java.util.Collection ; 8 9 import javax.servlet.http.HttpServletRequest ; 10 import javax.servlet.http.HttpServletResponse ; 11 import javax.servlet.ServletContext ; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 public class EnvironmentAdaptingServlet implements PseudoServlet { 17 private static final Log LOG = 18 LogFactory.getLog(EnvironmentAdaptingServlet.class); 19 20 private PseudoServlet servlet; 21 22 public EnvironmentAdaptingServlet( 23 final Server server, final Configuration configuration, 24 final String icefacesID, final Collection synchronouslyUpdatedViews, 25 final ViewQueue allUpdatedViews, final ServletContext servletContext) { 26 27 boolean useAsyncHttpServerByDefault; 28 try { 29 getClass().getClassLoader(). 30 loadClass( 31 "com.icesoft.faces.async.server." + 32 "AsyncHttpServerAdaptingServlet"); 33 useAsyncHttpServerByDefault = true; 34 } catch (ClassNotFoundException exception) { 35 useAsyncHttpServerByDefault = false; 36 } 37 boolean useJettyContinuationsByDefault; 38 try { 39 getClass().getClassLoader(). 40 loadClass("org.mortbay.util.ajax.Continuation"); 41 useJettyContinuationsByDefault = true; 42 } catch (ClassNotFoundException e) { 43 useJettyContinuationsByDefault = false; 44 } 45 if (configuration.getAttributeAsBoolean( 46 "useAsyncHttpServer", useAsyncHttpServerByDefault)) { 47 48 if (LOG.isDebugEnabled()) { 49 LOG.debug("Adapting to Asynchronous HTTP Server environment."); 50 } 51 try { 52 servlet = 53 (PseudoServlet) 54 this.getClass().getClassLoader().loadClass( 55 "com.icesoft.faces.async.server." + 56 "AsyncHttpServerAdaptingServlet"). 57 getDeclaredConstructor( 58 new Class [] { 59 Server.class, 60 String .class, 61 Collection .class, 62 ViewQueue.class, 63 ServletContext .class 64 }). 65 newInstance( 66 new Object [] { 67 server, 68 icefacesID, 69 synchronouslyUpdatedViews, 70 allUpdatedViews, 71 servletContext 72 }); 73 } catch (Exception exception) { 74 if (LOG.isFatalEnabled()) { 80 LOG.fatal( 81 "Failed to instantiate AsyncHttpServerAdaptingServlet!", 82 exception); 83 } 84 } 85 } else if (configuration.getAttributeAsBoolean( 86 "useJettyContinuations", useJettyContinuationsByDefault)) { 87 88 if (LOG.isDebugEnabled()) { 89 LOG.debug("Adapting to Jetty's Continuation environment."); 90 } 91 servlet = new ContinuationAdaptingServlet(server); 92 } else { 93 if (LOG.isDebugEnabled()) { 94 LOG.debug("Adapting to thread blocking environment."); 95 } 96 servlet = new ThreadBlockingAdaptingServlet(server); 97 } 98 } 99 100 public void service( 101 final HttpServletRequest request, final HttpServletResponse response) 102 throws Exception { 103 servlet.service(request, response); 104 } 105 106 public void shutdown() { 107 servlet.shutdown(); 108 } 109 } 110 | Popular Tags |