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.v3.client.config;
17  
18  import javax.servlet.ServletConfig;
19  import javax.servlet.ServletException;
20  import javax.servlet.http.HttpServlet;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  /**
26   * This servlet is to initialize the UDDIclient on deployment and
27   * cleanup on shutdown.
28   * 
29   * @author Kurt Stam (kstam@apache.org)
30   */
31  public class UDDIClerkServlet extends HttpServlet {
32  	
33  	private static final long serialVersionUID = -91998529871296125L;
34  	private static final Log logger = LogFactory.getLog(UDDIClerkServlet.class);
35  	private transient UDDIClient manager = null;
36  	
37  	/**
38  	 * Starting the UDDIClient
39  	 */
40  	@Override
41  	public void init(ServletConfig config) throws ServletException {
42  		super.init(config);
43  		try {
44  			manager = WebHelper.getUDDIClient(config.getServletContext());
45  			if (manager.getClientConfig().isRegisterOnStartup()) {
46  				manager.registerWSDLs();
47  				manager.registerAnnotatedServices();
48  			}
49  		} catch (Exception e) {
50  			logger.error("UDDI-client could not be started for manager " + manager.getName() + ". "
51  					+ e.getMessage(), e);
52  		} catch (Throwable t) {
53  			logger.error("UDDI-client could not be started."
54  					+ t.getMessage(), t);
55  		}
56  	}
57  	
58  	@Override
59  	public void destroy() {
60  		try {
61  			manager.stop();
62  		} catch (Exception e) {
63  			logger.error("UDDI-Clerk Manager could not be stopped for manager " + manager.getName() + ". "
64  					+ e.getMessage(), e);
65  		} catch (Throwable t) {
66  			logger.error("UDDI-client could not be stopped."
67  					+ t.getMessage(), t);
68  		}
69  		super.destroy();
70  	}
71  
72  }