KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > server > JNDIAxisServerFactory


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.server;
18
19 import org.apache.axis.AxisEngine;
20 import org.apache.axis.AxisFault;
21 import org.apache.axis.utils.Messages;
22
23 import javax.naming.InitialContext JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25 import javax.servlet.ServletContext JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  * Helper class for obtaining AxisServers, which hides the complexity
30  * of JNDI accesses, etc.
31  *
32  * !!! QUESTION : Does this class need to play any ClassLoader tricks?
33  *
34  * @author Glen Daniels (gdaniels@apache.org)
35  */

36
37 public class JNDIAxisServerFactory extends DefaultAxisServerFactory {
38
39     /**
40      * Obtain an AxisServer reference, using JNDI if possible, otherwise
41      * creating one using the standard Axis configuration pattern. If we
42      * end up creating one and do have JNDI access, bind it to the passed
43      * name so we find it next time.
44      *
45      * NOTE : REQUIRES SERVLET 2.3 FOR THE GetServletContextName() CALL!
46      *
47      * @param environment The following is used, in addition to
48      * the keys used by the parent class:
49      * AxisEngine.ENV_SERVLET_CONTEXT
50      * [required, else default/parent behavior]
51      * - Instance of ServletContext
52      */

53     public AxisServer getServer(Map JavaDoc environment)
54         throws AxisFault
55     {
56         log.debug("Enter: JNDIAxisServerFactory::getServer");
57
58         InitialContext JavaDoc context = null;
59
60         // First check to see if JNDI works
61
// !!! Might we need to set up context parameters here?
62
try {
63             context = new InitialContext JavaDoc();
64         } catch (NamingException JavaDoc e) {
65             log.warn(Messages.getMessage("jndiNotFound00"), e);
66         }
67         
68         ServletContext JavaDoc servletContext = null;
69         try {
70             servletContext =
71                 (ServletContext JavaDoc)environment.get(AxisEngine.ENV_SERVLET_CONTEXT);
72         } catch (ClassCastException JavaDoc e) {
73             log.warn(Messages.getMessage("servletContextWrongClass00"), e);
74             // Fall through
75
}
76
77         AxisServer server = null;
78         if (context != null && servletContext != null) {
79             // Figure out the name by looking in the servlet context (for now)
80

81             /**
82              * !!! WARNING - THIS CLASS NEEDS TO FIGURE OUT THE CORRECT
83              * NAMING SCHEME FOR GETTING/PUTTING SERVERS FROM/TO JNDI!
84              *
85              */

86                 
87             // For servlet 2.3....?
88
// String name = servletContext.getServletContextName();
89

90             // THIS IS NOT ACCEPTABLE JNDI NAMING...
91
String JavaDoc name = servletContext.getRealPath("/WEB-INF/Server");
92
93 // The following was submitted as a patch, but I don't believe this
94
// is going to produce a valid JNDI name of ANY sort... yuck.
95
// This would produce a URL, not a path name.
96
//
97
// Since it appears, from comments above, that this entire scheme is
98
// broken, then for now I'll simply check for a null-name to prevent
99
// possible NPE on WebLogic.
100
//
101
// What ARE we doing here?!?!
102
//
103
// if (name == null) {
104
// try {
105
// name = servletContext.getResource("/WEB-INF/Server").toString();
106
// } catch (Exception e) {
107
// // ignore
108
// }
109
// }
110

111             // We've got JNDI, so try to find an AxisServer at the
112
// specified name.
113
if (name != null) {
114                 try {
115                     server = (AxisServer)context.lookup(name);
116                 } catch (NamingException JavaDoc e) {
117                     // Didn't find it.
118
server = super.getServer(environment);
119                     try {
120                         context.bind(name, server);
121                     } catch (NamingException JavaDoc e1) {
122                         // !!! Couldn't do it, what should we do here?
123
}
124                 }
125             }
126         }
127         
128         if (server == null) {
129             server = super.getServer(environment);
130         }
131
132         log.debug("Exit: JNDIAxisServerFactory::getServer");
133
134         return server;
135     }
136 }
137
Popular Tags