1 22 package org.jboss.ejb3.test.dd.web.servlets; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.net.URL ; 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingException ; 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletException ; 32 import javax.servlet.http.HttpServlet ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.sql.DataSource ; 36 37 import org.jboss.ejb3.test.dd.web.interfaces.ReferenceTest; 38 import org.jboss.ejb3.test.dd.web.interfaces.StatelessSession; 39 import org.jboss.ejb3.test.dd.web.interfaces.StatelessSessionLocal; 40 import org.jboss.ejb3.test.dd.web.util.Util; 41 import org.jboss.security.SecurityAssociation; 42 import org.jboss.security.SimplePrincipal; 43 44 50 public class EJBOnStartupServlet extends HttpServlet 51 { 52 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 53 54 public void init(ServletConfig config) throws ServletException 55 { 56 String param = config.getInitParameter("failOnError"); 57 boolean failOnError = true; 58 if( param != null && Boolean.valueOf(param).booleanValue() == false ) 59 failOnError = false; 60 try 61 { 62 URL propsURL = Util.configureLog4j(); 64 log.debug("log4j.properties = "+propsURL); 65 } 66 catch(Exception e) 67 { 68 log.debug("failed", e); 69 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 70 try 71 { 72 log.debug(Util.displayClassLoaders(loader)); 73 } 74 catch(NamingException ne) 75 { 76 log.debug("failed", ne); 77 } 78 if( failOnError == true ) 79 throw new ServletException ("Failed to init EJBOnStartupServlet", e); 80 } 81 } 82 83 public void destroy() 84 { 85 86 } 87 88 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 89 throws ServletException , IOException 90 { 91 try 92 { 93 SecurityAssociation.setPrincipal(new SimplePrincipal("jduke")); 94 SecurityAssociation.setCredential("theduke".toCharArray()); 95 96 InitialContext ctx = new InitialContext (); 97 StatelessSession bean = (StatelessSession)ctx.lookup("java:comp/env/ejb/OptimizedEJB"); 98 bean.noop(new ReferenceTest(), true); 99 } 100 catch(Exception e) 101 { 102 throw new ServletException ("Failed to call OptimizedEJB", e); 103 } 104 response.setContentType("text/html"); 105 PrintWriter out = response.getWriter(); 106 out.println("<html>"); 107 out.println("<head><title>EJBOnStartupServlet</title></head>"); 108 out.println("<body>Was initialized<br>"); 109 out.println("Tests passed<br>Time:"+Util.getTime()+"</body>"); 110 out.println("</html>"); 111 out.close(); 112 } 113 114 protected void doGet(HttpServletRequest request, HttpServletResponse response) 115 throws ServletException , IOException 116 { 117 processRequest(request, response); 118 } 119 120 protected void doPost(HttpServletRequest request, HttpServletResponse response) 121 throws ServletException , IOException 122 { 123 processRequest(request, response); 124 } 125 } 126 | Popular Tags |