KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > webservices > POJOWebServiceServlet


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
20 import javax.servlet.Servlet JavaDoc;
21 import javax.servlet.ServletConfig JavaDoc;
22 import javax.servlet.ServletContext JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.ServletRequest JavaDoc;
25 import javax.servlet.ServletResponse JavaDoc;
26 import javax.xml.rpc.server.ServiceLifecycle JavaDoc;
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: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
47  */

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