1 17 package org.apache.geronimo.webservices; 18 19 import java.io.IOException ; 20 import javax.servlet.Servlet ; 21 import javax.servlet.ServletConfig ; 22 import javax.servlet.ServletContext ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.ServletRequest ; 25 import javax.servlet.ServletResponse ; 26 import javax.xml.rpc.server.ServiceLifecycle ; 27 28 48 public class POJOWebServiceServlet implements Servlet { 49 public static final String POJO_CLASS = POJOWebServiceServlet.class.getName()+"@pojoClassName"; 50 private Servlet stack; 51 52 public void init(ServletConfig config) throws ServletException { 53 ServletContext context = config.getServletContext(); 54 55 String pojoClassID = config.getInitParameter(POJO_CLASS); 56 Class pojoClass = (Class ) context.getAttribute(pojoClassID); 57 58 Object pojo; 59 try { 60 pojo = pojoClass.newInstance(); 61 } catch (Exception e) { 62 throw new ServletException ("Unable to instantiate POJO WebService class: " + pojoClass.getName(), e); 63 } 64 65 stack = new WebServiceContainerInvoker(pojo); 66 if (pojo instanceof ServiceLifecycle ) { 67 stack = new ServiceLifecycleManager(stack,(ServiceLifecycle )pojo); 68 } 69 70 71 stack.init(config); 72 } 73 74 public ServletConfig getServletConfig() { 75 return stack.getServletConfig(); 76 } 77 78 public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException , IOException { 79 stack.service(servletRequest, servletResponse); 80 } 81 82 public String getServletInfo() { 83 return stack.getServletInfo(); 84 } 85 86 public void destroy() { 87 stack.destroy(); 88 } 89 } 90 | Popular Tags |