1 package org.codehaus.ivory.plexus;
2
3 import javax.servlet.ServletContext;
4 import org.apache.avalon.framework.service.ServiceException;
5 import org.apache.avalon.framework.service.ServiceManager;
6 import org.apache.axis.AxisFault;
7 import org.apache.axis.AxisProperties;
8 import org.apache.axis.server.AxisServer;
9 import org.apache.axis.transport.http.AxisServlet;
10 import org.codehaus.ivory.AxisService;
11 import org.codehaus.ivory.DefaultAxisService;
12
13 /***
14 * An implementation of the Axis AxisServlet which retrieves the AxisEngine
15 * from the ServiceManager.
16 *
17 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
18 * @since Mar 8, 2003
19 */
20 public class PlexusAxisServlet
21 extends AxisServlet
22 {
23 ServiceManager manager;
24
25 AxisService axisService;
26
27 public PlexusAxisServlet()
28 {
29 }
30
31 /***
32 * Provide the AxisEngine to the base servlet class.
33 *
34 * @return AxisServer
35 * @see org.apache.axis.transport.http.AxisServletBase#getEngine()
36 */
37 public AxisServer getEngine() throws AxisFault
38 {
39 manager = getServiceManager();
40
41 try
42 {
43 axisService = ( AxisService ) manager.lookup( AxisService.ROLE );
44 }
45 catch (ServiceException e)
46 {
47 throw new AxisFault( "Could not find the AxisService.", e );
48 }
49
50 return axisService.getAxisServer();
51 }
52
53 /***
54 * Retrieve the ServiceBroker from the ServletContext. This presupposes
55 * that the installation is using Plexus.
56 *
57 * @return ServiceBroker
58 */
59 public ServiceManager getServiceManager()
60 {
61 return DefaultAxisService.getServiceManager();
62 }
63
64 public void destroy()
65 {
66 super.destroy();
67
68 if ( axisService != null )
69 manager.release( axisService );
70 }
71
72 /***
73 * respond to the ?list command.
74 * if enableList is set, we list the engine config. If it isnt, then an
75 * error is written out
76 * @param response
77 * @param writer
78 * @throws AxisFault
79 */
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 protected String getOption(ServletContext context,
134 String param,
135 String dephault)
136 {
137 String value = AxisProperties.getProperty(param);
138
139 if (value == null) value = getInitParameter(param);
140
141 if (value == null) value = context.getInitParameter(param);
142 try
143 {
144 AxisServer engine = getEngine();
145 if (value == null && engine != null) value = (String) engine
146 .getOption(param);
147 }
148 catch (AxisFault axisFault)
149 {
150 }
151
152 return (value != null) ? value : dephault;
153 }
154 }