01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.webservices;
17:
18: import java.io.IOException;
19: import javax.servlet.Servlet;
20: import javax.servlet.ServletConfig;
21: import javax.servlet.ServletContext;
22: import javax.servlet.ServletException;
23: import javax.servlet.ServletRequest;
24: import javax.servlet.ServletResponse;
25: import javax.xml.rpc.server.ServiceLifecycle;
26:
27: /**
28: * Delegates requests to a WebServiceContainer which is presumably for a POJO WebService
29: * Nothing stopping us from using this for EJBs or other types of webservices other than
30: * it is more than we need. EJB webservices use the JettyEJBWebServiceContext.
31: * <p/>
32: * From a 10,000 foot view the Jetty architecture has:
33: * Container -> Context -> Holder -> Servlet
34: * <p/>
35: * A Container has multiple Contexts, typically webapps
36: * A Context provides the JNDI, TX, and Security for the webapp and has many Holders
37: * A Holder simply wraps each Servlet
38: * <p/>
39: * The POJO Web Service architecture on Jetty looks like this:
40: * Container -> WebApp Context -> JettyPOJOWebServiceHolder -> POJOWebServiceServlet
41: * <p/>
42: * The EJB Web Service architecure, on the other hand, creates one Context for each EJB:
43: * Container -> JettyEJBWebServiceContext
44: *
45: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
46: */
47: public class POJOWebServiceServlet implements Servlet {
48: public static final String POJO_CLASS = POJOWebServiceServlet.class
49: .getName()
50: + "@pojoClassName";
51: private Servlet stack;
52:
53: public void init(ServletConfig config) throws ServletException {
54: ServletContext context = config.getServletContext();
55:
56: String pojoClassID = config.getInitParameter(POJO_CLASS);
57: Class pojoClass = (Class) context.getAttribute(pojoClassID);
58:
59: Object pojo;
60: try {
61: pojo = pojoClass.newInstance();
62: } catch (Exception e) {
63: throw new ServletException(
64: "Unable to instantiate POJO WebService class: "
65: + pojoClass.getName(), e);
66: }
67:
68: stack = new WebServiceContainerInvoker(pojo);
69: if (pojo instanceof ServiceLifecycle) {
70: stack = new ServiceLifecycleManager(stack,
71: (ServiceLifecycle) pojo);
72: }
73:
74: stack.init(config);
75: }
76:
77: public ServletConfig getServletConfig() {
78: return stack.getServletConfig();
79: }
80:
81: public void service(ServletRequest servletRequest,
82: ServletResponse servletResponse) throws ServletException,
83: IOException {
84: stack.service(servletRequest, servletResponse);
85: }
86:
87: public String getServletInfo() {
88: return stack.getServletInfo();
89: }
90:
91: public void destroy() {
92: stack.destroy();
93: }
94: }
|