View Javadoc

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  package org.apache.juddi.registry;
17  
18  import java.io.IOException;
19  import java.io.InputStream;
20  import java.util.Properties;
21  
22  import javax.servlet.ServletConfig;
23  import javax.servlet.ServletException;
24  import javax.servlet.http.HttpServlet;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /***
30   * This servlet is ONLY used to initialize the jUDDI webapp on
31   * startup and cleanup the jUDDI webapp on shutdown.
32   * 
33   * @author Steve Viens (sviens@apache.org)
34   */
35  public class RegistryServlet extends HttpServlet
36  {
37    // config file property name (used to look up the juddi property file name).
38    private static final String CONFIG_FILE_PROPERTY_NAME = "juddi.propertiesFile";
39    
40    // default config file name. 
41    private static final String DEFAULT_PROPERTY_FILE = "/WEB-INF/juddi.properties";
42     
43    // private reference to the webapp's logger.
44    private static Log log = LogFactory.getLog(RegistryServlet.class);
45  
46    // registry singleton instance
47    private static RegistryEngine registry = null;
48  
49    /***
50     * Create the shared instance of jUDDI's Registry class
51     * and call it's "init()" method to initialize all core 
52     * components.
53     */
54    public void init(ServletConfig config) 
55      throws ServletException
56    {
57      super.init(config);    
58  
59      Properties props = new Properties();
60  
61      try
62      {      
63        log.info("Loading jUDDI configuration.");
64          
65        // determine the name of the juddi property file to use from web.xml
66        String propFile = config.getInitParameter(CONFIG_FILE_PROPERTY_NAME);
67        if ((propFile == null) || (propFile.trim().length() == 0))
68          propFile = DEFAULT_PROPERTY_FILE;
69        
70        InputStream is = 
71          getServletContext().getResourceAsStream(propFile);
72          
73        if (is != null)
74        {
75          log.info("Resources loaded from: "+propFile);
76  
77          // Load jUDDI configuration from the 
78          // juddi.properties file found in the 
79          // WEB-INF directory.
80  
81          props.load(is);
82        }
83        else
84        {
85          log.warn("Could not locate jUDDI properties '" + propFile + 
86                  "'. Using defaults.");
87  
88          // A juddi.properties file doesn't exist
89          // yet so create create a new Properties 
90          // instance using default property values.
91          
92          props.put(RegistryEngine.PROPNAME_OPERATOR_NAME,
93                    RegistryEngine.DEFAULT_OPERATOR_NAME);
94          
95          props.put(RegistryEngine.PROPNAME_I18N_LANGUAGE_CODE,
96              			RegistryEngine.DEFAULT_I18N_LANGUAGE_CODE);
97    
98          props.put(RegistryEngine.PROPNAME_I18N_COUNTRY_CODE,
99              			RegistryEngine.DEFAULT_I18N_COUNTRY_CODE);
100   
101         props.put(RegistryEngine.PROPNAME_DISCOVERY_URL,
102                   RegistryEngine.DEFAULT_DISCOVERY_URL);
103         
104         props.put(RegistryEngine.PROPNAME_ADMIN_EMAIL_ADDRESS,
105                   RegistryEngine.DEFAULT_ADMIN_EMAIL_ADDRESS);
106         
107         props.put(RegistryEngine.PROPNAME_DATASOURCE_NAME,
108                   RegistryEngine.DEFAULT_DATASOURCE_NAME);
109         
110         props.put(RegistryEngine.PROPNAME_IS_USE_DATASOURCE,
111                   RegistryEngine.DEFAULT_IS_USE_DATASOURCE);
112         
113         props.put(RegistryEngine.PROPNAME_JDBC_DRIVER,
114                 RegistryEngine.DEFAULT_JDBC_DRIVER);
115       
116         props.put(RegistryEngine.PROPNAME_JDBC_URL,
117                 RegistryEngine.DEFAULT_JDBC_URL);
118       
119         props.put(RegistryEngine.PROPNAME_JDBC_USERNAME,
120                 RegistryEngine.DEFAULT_JDBC_USERNAME);
121       
122         props.put(RegistryEngine.PROPNAME_JDBC_PASSWORD,
123                 RegistryEngine.DEFAULT_JDBC_PASSWORD);
124               
125         props.put(RegistryEngine.PROPNAME_AUTH_CLASS_NAME,
126                   RegistryEngine.DEFAULT_AUTH_CLASS_NAME);
127         
128         props.put(RegistryEngine.PROPNAME_CRYPTOR_CLASS_NAME,
129                   RegistryEngine.DEFAULT_CRYPTOR_CLASS_NAME);
130         
131         props.put(RegistryEngine.PROPNAME_DATASTORE_CLASS_NAME,
132                   RegistryEngine.DEFAULT_DATASTORE_CLASS_NAME);
133         
134         props.put(RegistryEngine.PROPNAME_UUIDGEN_CLASS_NAME,
135                   RegistryEngine.DEFAULT_UUIDGEN_CLASS_NAME);
136         
137         props.put(RegistryEngine.PROPNAME_VALIDATOR_CLASS_NAME,
138                   RegistryEngine.DEFAULT_VALIDATOR_CLASS_NAME);  
139 
140         props.put(RegistryEngine.PROPNAME_MAX_NAME_ELEMENTS,
141                   Integer.toString(RegistryEngine.DEFAULT_MAX_NAME_ELEMENTS));
142         
143         props.put(RegistryEngine.PROPNAME_MAX_NAME_LENGTH,
144                   Integer.toString(RegistryEngine.DEFAULT_MAX_NAME_LENGTH));
145 
146         props.put(RegistryEngine.PROPNAME_MAX_MESSAGE_SIZE,
147                   Integer.toString(RegistryEngine.DEFAULT_MAX_MESSAGE_SIZE));        
148 
149         props.put(RegistryEngine.PROPNAME_MAX_BUSINESSES_PER_PUBLISHER,
150                   Integer.toString(RegistryEngine.DEFAULT_MAX_BUSINESSES_PER_PUBLISHER));
151         
152         props.put(RegistryEngine.PROPNAME_MAX_SERVICES_PER_BUSINESS,
153                   Integer.toString(RegistryEngine.DEFAULT_MAX_SERVICES_PER_BUSINESS));
154         
155         props.put(RegistryEngine.PROPNAME_MAX_BINDINGS_PER_SERVICE,
156                   Integer.toString(RegistryEngine.DEFAULT_MAX_BINDINGS_PER_SERVICE));
157         
158         props.put(RegistryEngine.PROPNAME_MAX_TMODELS_PER_PUBLISHER,
159                   Integer.toString(RegistryEngine.DEFAULT_MAX_TMODELS_PER_PUBLISHER));
160         
161         props.put(RegistryEngine.PROPNAME_MAX_ROWS_LIMIT,           
162                   Integer.toString(RegistryEngine.DEFAULT_MAX_ROWS_LIMIT));
163         
164         props.put(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL,           
165                 RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_INITIAL);
166       
167         props.put(RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL,           
168                 RegistryEngine.DEFAULT_JAVA_NAMING_PROVIDER_URL);
169       
170         props.put(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS,           
171                 RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_URL_PKGS);
172         
173       }
174     }
175     catch(IOException ioex) {
176       log.error(ioex.getMessage(),ioex);
177     }
178 
179     log.info("Initializing jUDDI components.");
180     
181     registry = new RegistryEngine(props);
182     registry.init();
183   }
184   
185   /***
186    * Grab the shared instance of jUDDI's Registry class and
187    * call it's "dispose()" method to notify all sub-components
188    * to stop any background threads and release any external
189    * resources they may have aquired.
190    */
191   public void destroy()
192   {
193     super.destroy();
194     
195     log.info("jUDDI Stopping: Cleaning up existing resources.");
196 
197     RegistryEngine registry = RegistryServlet.getRegistry();
198     if (registry != null)
199       registry.dispose();
200   }
201 
202   /***
203    *
204    */
205   public static RegistryEngine getRegistry()
206   {
207     return registry;
208   }
209 }