1 /** 2 * 3 * Copyright 2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 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 /** 29 * Delegates requests to a WebServiceContainer which is presumably for a POJO WebService 30 * Nothing stopping us from using this for EJBs or other types of webservices other than 31 * it is more than we need. EJB webservices use the JettyEJBWebServiceContext. 32 * <p/> 33 * From a 10,000 foot view the Jetty architecture has: 34 * Container -> Context -> Holder -> Servlet 35 * <p/> 36 * A Container has multiple Contexts, typically webapps 37 * A Context provides the JNDI, TX, and Security for the webapp and has many Holders 38 * A Holder simply wraps each Servlet 39 * <p/> 40 * The POJO Web Service architecture on Jetty looks like this: 41 * Container -> WebApp Context -> JettyPOJOWebServiceHolder -> POJOWebServiceServlet 42 * <p/> 43 * The EJB Web Service architecure, on the other hand, creates one Context for each EJB: 44 * Container -> JettyEJBWebServiceContext 45 * 46 * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $ 47 */ 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 }