001: /*
002: * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.wso2.esb;
018:
019: import org.apache.axiom.om.OMElement;
020: import org.apache.axiom.om.xpath.AXIOMXPath;
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.Constants;
023: import org.apache.axis2.context.ConfigurationContext;
024: import org.apache.axis2.description.Parameter;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.derby.drda.NetworkServerControl;
028: import org.apache.synapse.ServerManager;
029: import org.apache.synapse.SynapseConstants;
030: import org.apache.synapse.config.SynapseConfiguration;
031: import org.apache.synapse.core.SynapseEnvironment;
032: import org.apache.synapse.registry.Registry;
033: import org.jaxen.JaxenException;
034: import org.jaxen.SimpleNamespaceContext;
035: import org.jaxen.XPath;
036: import org.wso2.adminui.UIProcessingException;
037: import org.wso2.adminui.UIProcessor;
038: import org.wso2.esb.jmx.ESBJMXAuthenticator;
039: import org.wso2.esb.jmx.mbean.*;
040: import org.wso2.esb.registry.ESBRegistry;
041: import org.wso2.esb.statistics.StatisticsReporterThread;
042: import org.wso2.esb.transport.WebServer;
043: import org.wso2.esb.transport.tomcat.TomcatServer;
044: import org.wso2.esb.util.HibernateConfigCache;
045: import org.wso2.esb.util.XmlConfigurationFactory;
046: import org.wso2.utils.NetworkUtils;
047: import org.wso2.utils.ServerException;
048:
049: import javax.management.MBeanServer;
050: import javax.management.ObjectName;
051: import javax.management.remote.JMXConnectorServer;
052: import javax.management.remote.JMXConnectorServerFactory;
053: import javax.management.remote.JMXServiceURL;
054: import javax.xml.namespace.QName;
055: import java.io.File;
056: import java.io.IOException;
057: import java.io.InputStream;
058: import java.lang.management.ManagementFactory;
059: import java.net.UnknownHostException;
060: import java.rmi.NoSuchObjectException;
061: import java.rmi.registry.LocateRegistry;
062: import java.rmi.server.UnicastRemoteObject;
063: import java.util.*;
064:
065: /*
066: * The Service bus manager
067: */
068: public class ServiceBusManager {
069:
070: private static Log log = LogFactory.getLog(ServiceBusManager.class);
071:
072: private int httpPort = 8080;
073: private int httpsPort = 9443;
074: private String host = "localhost";
075: private ServiceBusConfiguration esbConfiguration;
076: private ConfigurationContext configurationContext;
077: private NetworkServerControl networkServerControl;
078: /*The thread which reads statistics from memory and write them to the DB */
079: private StatisticsReporterThread statisticsReporterThread;
080: private static ServiceBusManager instance;
081: private WebServer webServer;
082: private Thread shutdownHook;
083: private static final QName USERNAME_QN = new QName(
084: "http://www.wso2.org/projects/esb", "Username");
085: private static final QName PASSWORD_QN = new QName(
086: "http://www.wso2.org/projects/esb", "Password");
087: private String axis2ConfLocation;
088: private String axis2RepoLocation;
089: private String synapseConfLocation;
090: private String esbHomeLocation;
091: private JMXConnectorServer jmxConnectorServer;
092: private java.rmi.registry.Registry rmiRegistry;
093:
094: public static ServiceBusManager getInstance() {
095: if (instance == null) {
096: instance = new ServiceBusManager();
097: }
098: return instance;
099: }
100:
101: private ServiceBusManager() {
102: this (ServiceBusConfiguration.getInstance());
103: if (XmlConfigurationFactory
104: .getXmlConfiguration(ServiceBusConstants.ESB_WEB_XML_KEY) == null) {
105: try {
106: String server_web_xml = System
107: .getProperty(ServiceBusConstants.ESB_SERVER_WEB_XML);
108: if (server_web_xml == null || "".equals(server_web_xml)) {
109: server_web_xml = "conf" + File.separator
110: + ServiceBusConstants.ESB_SERVER_WEB_XML;
111: }
112: XmlConfigurationFactory.init(
113: ServiceBusConstants.ESB_WEB_XML_KEY,
114: server_web_xml,
115: ServiceBusConstants.ESB_XML_NAMESPACE);
116: } catch (ServerException e) {
117: log.error("Error loading server-web.xml", e);
118: }
119: }
120: }
121:
122: public void init() {
123: initSystemProperties();
124: createTempAxisWorkDirectory();
125: HibernateConfigCache.clearCache();
126: }
127:
128: public void start() throws ServiceBusException {
129: webServer = new TomcatServer();
130: try {
131: webServer.start();
132: } catch (AxisFault axisFault) {
133: throw new ServiceBusException(axisFault);
134: } catch (Exception e) {
135: throw new ServiceBusException(e);
136: }
137: }
138:
139: public void stop() throws ServiceBusException {
140: if (webServer != null) {
141: try {
142: webServer.stop();
143: } catch (AxisFault axisFault) {
144: log.fatal("ServiceBus#stopListener encounted an error",
145: axisFault);
146: throw new ServiceBusException(
147: "ServiceBus#stopListener encounted an error");
148: } catch (Exception e) {
149: log.fatal("ServiceBus#stopListener encounted an error",
150: e);
151: throw new ServiceBusException(
152: "ServiceBus#stopListener encounted an error");
153: }
154: } else {
155: log.fatal("ServiceBus#stopListener encounted an error");
156: throw new ServiceBusException(
157: "ServiceBus#stopListener encounted an error");
158: }
159: }
160:
161: public void startListeners() throws AxisFault, ServiceBusException {
162: startDataBaseServer();
163: ServerManager.getInstance().setAxis2Repolocation(
164: System.getProperty("axis2.repo"));
165: ServerManager.getInstance().start();
166: configurationContext = ServerManager.getInstance()
167: .getConfigurationContext();
168: startStatisticsReporter();
169: setESBDefaults(configurationContext);
170:
171: // Create the index.html page and save it in the ConfigContext
172: generateWelcomePage();
173: startJMXService();
174: registerMBeans();
175: addShutdownHook();
176: }
177:
178: public void stopListeners() throws ServiceBusException, AxisFault {
179: stopStatisticsReporter();
180: stopDataBaseServer();
181: ServerManager.getInstance().stop();
182: stopJMXService();
183: }
184:
185: private void addShutdownHook() {
186: shutdownHook = new Thread() {
187: public void run() {
188: try {
189: ServiceBus serviceBus = new ServiceBus();
190: serviceBus.shutdown();
191: log.info("[ESB] Shutdown completed");
192: log.info("[ESB] Halting JVM");
193: } catch (Exception e) {
194: log
195: .warn("[ESB] Error occurred while shutting down WSO2 ESB : "
196: + e);
197: }
198: }
199: };
200: Runtime.getRuntime().addShutdownHook(shutdownHook);
201: }
202:
203: public void removeShutdownHook() {
204: Runtime.getRuntime().removeShutdownHook(shutdownHook);
205: }
206:
207: public Thread getShutdownHook() {
208: return shutdownHook;
209: }
210:
211: public ServiceBusManager(ServiceBusConfiguration esbConfiguration) {
212: this .esbConfiguration = esbConfiguration;
213: }
214:
215: public ServiceBusConfiguration getEsbConfiguration() {
216: return esbConfiguration;
217: }
218:
219: public void setEsbConfiguration(
220: ServiceBusConfiguration esbConfiguration) {
221: this .esbConfiguration = esbConfiguration;
222: }
223:
224: /**
225: * This implementation does not validate the user against a database. In future it
226: * is envisioned that the ESB will reuse the common authentication components shared
227: * between WSAS and ESB
228: * <p/>
229: * <Server>
230: * <ESBUsers>
231: * <User>
232: * <Username>Username</Username>
233: * <Password>Password</Password>
234: * <Description>Description</Description>
235: * </User>
236: * </ESBUsers>
237: * </Server>
238: *
239: * @param username
240: * @param password
241: * @return true if the user is authenticated successfully
242: */
243: public boolean authenticate(String username, String password) {
244:
245: OMElement docElement = esbConfiguration.getDocumentElement();
246: if (docElement == null)
247: handleException("esb configuration document element is null");
248:
249: // get all user elements /ESBUsers/User
250: List nodeList = null;
251: try {
252: SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
253: nsCtx.addNamespace("esb",
254: "http://www.wso2.org/projects/esb");
255: XPath xp = new AXIOMXPath("//esb:ESBUsers/esb:User");
256: xp.setNamespaceContext(nsCtx);
257: nodeList = xp.selectNodes(docElement);
258:
259: } catch (JaxenException e) {
260: handleException("//esb:ESBUsers/esb:User xpath error", e);
261: }
262:
263: if (nodeList == null) {
264: return false;
265: }
266: // for each user element get username element
267: // if username == givenUsername then
268: // get password element
269: // if password == givenPassword then
270: // return true
271: // goto next
272: // if no username matches then
273: // return false
274: for (Iterator iter = nodeList.iterator(); iter.hasNext();) {
275: OMElement userElement = (OMElement) iter.next();
276: OMElement usernameElement = userElement
277: .getFirstChildWithName(USERNAME_QN);
278: if (usernameElement == null) {
279: handleException("Required element, 'ESBUsers/User/Username' not found!");
280: }
281: if (username != null
282: && username
283: .equals(usernameElement.getText().trim())) {
284: OMElement passwordElement = userElement
285: .getFirstChildWithName(PASSWORD_QN);
286: if (passwordElement == null) {
287: handleException("Required element, 'ESBUsers/User/Password' not found!");
288: }
289: if (password != null
290: && password.equals(passwordElement.getText()
291: .trim())) {
292: return true;
293: }
294: }
295: }
296:
297: return false;
298: }
299:
300: /**
301: * Starts the Derby database instance in network mode for multi user access
302: * Waits till the server can be pinged, upto a maximum of 10 seconds
303: *
304: * @throws ServiceBusException
305: */
306: public void startDataBaseServer() throws ServiceBusException {
307:
308: String host = null;
309: try {
310: networkServerControl = new NetworkServerControl();
311: networkServerControl.start(null);
312:
313: for (int i = 0; i < 10; i++) {
314: Thread.sleep(1000);
315: try {
316: networkServerControl.ping();
317: Properties properties = networkServerControl
318: .getCurrentProperties();
319: host = properties.getProperty("derby.drda.host");
320: int port = Integer.parseInt(properties
321: .getProperty("derby.drda.portNumber"));
322: log.info("Database server started on " + host
323: + " over port " + port);
324: return;
325:
326: } catch (Exception ignore) {
327: }
328: }
329: handleFatal("Database server failed to start");
330:
331: } catch (UnknownHostException e) {
332: handleException("Unknown host : " + host, e);
333: } catch (Exception e) {
334: handleException("Error starting the database server", e);
335: }
336: }
337:
338: /**
339: * Requests the Derby DB to stop itself
340: *
341: * @throws ServiceBusException
342: */
343: public void stopDataBaseServer() throws ServiceBusException {
344: if (networkServerControl != null) {
345: try {
346: networkServerControl.shutdown();
347: log.info("Database server shutting down");
348: } catch (Exception e) {
349: throw new ServiceBusException(e);
350: }
351: }
352: }
353:
354: /**
355: * Assign deafult values for synapse configuration which are specific to ESB.
356: *
357: * @param configContext ConfigurationContext
358: */
359: private void setESBDefaults(ConfigurationContext configContext) {
360:
361: Parameter configParameter = configurationContext
362: .getAxisConfiguration().getParameter(
363: SynapseConstants.SYNAPSE_CONFIG);
364: Object o = configParameter.getValue();
365:
366: if (o != null && o instanceof SynapseConfiguration) {
367: SynapseConfiguration synConfig = (SynapseConfiguration) o;
368:
369: // set default registry to ESB registry
370: if (synConfig.getRegistry() == null) {
371: Registry registry = new ESBRegistry();
372: registry.addConfigProperty("root", "file:registry");
373: registry.addConfigProperty("cachableDuration", "15000");
374:
375: synConfig.setRegistry(registry);
376: }
377: }
378: }
379:
380: /**
381: * Generate the index.html page and cache it in the ConfigurationContext
382: */
383: private void generateWelcomePage() throws ServiceBusException {
384:
385: Hashtable fileContents = new Hashtable();
386: try {
387: UIProcessor
388: .createPages(
389: System
390: .getProperty(ServiceBusConstants.ESB_HOME)
391: + File.separator
392: + XmlConfigurationFactory
393: .getXmlConfiguration(
394: ServiceBusConstants.ESB_WEB_XML_KEY)
395: .getUniqueValue(
396: "//ns:Mapping[@name=\"admin\"]/ns:ResourceBase")
397: + File.separator,
398: System
399: .getProperty(ServiceBusConstants.ESB_UI_EXTENSIONS_CONFIG_XML),
400: fileContents);
401: } catch (UIProcessingException e) {
402: handleException("Error generating welcome page", e);
403: }
404: configurationContext.setProperty(
405: ServiceBusConstants.GENERATED_PAGES, fileContents);
406: }
407:
408: public void initSystemProperties() {
409: //ESB home
410: if (esbHomeLocation != null) {
411: System.setProperty(ServiceBusConstants.ESB_HOME,
412: esbHomeLocation);
413: } else {
414: String esbHome = System
415: .getProperty(ServiceBusConstants.ESB_HOME); // this has to be provided
416: if (esbHome == null) {
417: System.setProperty(ServiceBusConstants.ESB_HOME, ".");
418: esbHome = System
419: .getProperty(ServiceBusConstants.ESB_HOME);
420: }
421: System.setProperty(SynapseConstants.SYNAPSE_HOME, esbHome);
422: esbHomeLocation = esbHome;
423: }
424:
425: //Axis2 repo
426: if (axis2RepoLocation != null) {
427: System.setProperty(Constants.AXIS2_REPO, axis2RepoLocation);
428: } else {
429: String axis2Repo = System.getProperty(Constants.AXIS2_REPO);
430: if (axis2Repo == null) {
431: System
432: .setProperty(Constants.AXIS2_REPO,
433: esbHomeLocation + File.separator
434: + "repository");
435: }
436: axis2RepoLocation = axis2Repo;
437: }
438:
439: //Axis2 conf - axis2.xml
440: if (axis2ConfLocation != null) {
441: System.setProperty(Constants.AXIS2_CONF, axis2ConfLocation);
442: } else {
443: String axis2Xml = System.getProperty(Constants.AXIS2_CONF);
444: if (axis2Xml == null) {
445: System
446: .setProperty(
447: Constants.AXIS2_CONF,
448: esbHomeLocation
449: + File.separator
450: + ServiceBusConstants.ESB_CONF_DIRECTORY
451: + File.separator
452: + Constants.AXIS2_CONF);
453: }
454: axis2ConfLocation = axis2Xml;
455: }
456:
457: //Synapse conf - synapse.xml
458: if (synapseConfLocation != null) {
459: System.setProperty(SynapseConstants.SYNAPSE_XML,
460: synapseConfLocation);
461: } else {
462: String synapseXml = System
463: .getProperty(SynapseConstants.SYNAPSE_XML);
464: if (synapseXml == null) {
465: System
466: .setProperty(
467: SynapseConstants.SYNAPSE_XML,
468: esbHomeLocation
469: + File.separator
470: + ServiceBusConstants.ESB_CONF_DIRECTORY
471: + File.separator
472: + SynapseConstants.SYNAPSE_XML);
473: }
474: synapseConfLocation = synapseXml;
475: }
476:
477: //ESB conf - server.xml
478: String esbXml = System
479: .getProperty(ServiceBusConstants.ESB_SERVER_XML);
480: if (esbXml == null) {
481: System.setProperty(ServiceBusConstants.ESB_SERVER_XML,
482: esbHomeLocation + File.separator
483: + ServiceBusConstants.ESB_CONF_DIRECTORY
484: + File.separator + "server.xml");
485: }
486:
487: //ESB GUI conf - server-web.xml
488: String serverWeb = System
489: .getProperty(ServiceBusConstants.ESB_SERVER_WEB_XML);
490: if (serverWeb == null) {
491: System.setProperty(ServiceBusConstants.ESB_SERVER_WEB_XML,
492: esbHomeLocation + File.separator
493: + ServiceBusConstants.ESB_CONF_DIRECTORY
494: + ServiceBusConstants.ESB_SERVER_WEB_XML);
495: }
496:
497: //AdminUI conf
498: String ui_extension_xml = System
499: .getProperty(ServiceBusConstants.ESB_UI_EXTENSIONS_CONFIG_XML);
500: if (ui_extension_xml == null) {
501: System
502: .setProperty(
503: ServiceBusConstants.ESB_UI_EXTENSIONS_CONFIG_XML,
504: "conf"
505: + File.separator
506: + ServiceBusConstants.ESB_UI_EXTENSIONS_CONFIG_XML);
507: }
508:
509: //Hibernate Conf
510: String hibernameConf = System
511: .getProperty(ServiceBusConstants.ESB_HIBERNATE_CFG_XML);
512: if (hibernameConf == null) {
513: InputStream inStream = Thread.currentThread()
514: .getContextClassLoader().getResourceAsStream(
515: ServiceBusConstants.ESB_HIBERNATE_CFG_XML);
516: if (inStream == null) {
517: System
518: .setProperty(
519: ServiceBusConstants.ESB_HIBERNATE_CFG_XML,
520: "conf"
521: + File.separator
522: + ServiceBusConstants.ESB_HIBERNATE_CFG_XML);
523: } else {
524: System.setProperty(
525: ServiceBusConstants.ESB_HIBERNATE_CFG_XML,
526: ServiceBusConstants.ESB_HIBERNATE_CFG_XML);
527: }
528: }
529:
530: //Derby Conf
531: String derbyHome = System
532: .getProperty(ServiceBusConstants.ESB_DERBY_SYSTEM_HOME);
533: if (derbyHome == null) {
534: System.setProperty(
535: ServiceBusConstants.ESB_DERBY_SYSTEM_HOME,
536: esbHomeLocation + File.separator
537: + ServiceBusConstants.ESB_CONF_DIRECTORY);
538: }
539: }
540:
541: private static void handleFatal(String msg)
542: throws ServiceBusException {
543: log.fatal(msg);
544: throw new ServiceBusException(msg);
545: }
546:
547: private static void handleException(String msg, Exception e)
548: throws ServiceBusException {
549: log.error(msg, e);
550: throw new ServiceBusException(msg, e);
551: }
552:
553: private static void handleException(String msg) {
554: log.error(msg);
555: throw new ServiceBusException(msg);
556: }
557:
558: public void startStatisticsReporter() throws ServiceBusException {
559:
560: Parameter synapseEnvParameter = configurationContext
561: .getAxisConfiguration().getParameter(
562: SynapseConstants.SYNAPSE_ENV);
563: if (synapseEnvParameter != null) {
564: try {
565: String statisticsPersistenceInterval = esbConfiguration
566: .getFirstProperty("StatisticsPersistenceInterval");
567: SynapseEnvironment synEnv = (SynapseEnvironment) synapseEnvParameter
568: .getValue();
569: statisticsReporterThread = new StatisticsReporterThread(
570: synEnv);
571: statisticsReporterThread.setDelay(Long
572: .parseLong(statisticsPersistenceInterval));
573: statisticsReporterThread.start();
574: } catch (Exception e) {
575: throw new ServiceBusException(e);
576: }
577: }
578: }
579:
580: public void stopStatisticsReporter() throws ServiceBusException {
581: if (statisticsReporterThread != null) {
582: statisticsReporterThread.shutdown();
583: }
584: }
585:
586: private void startJMXService() {
587: String jmxPort = ServiceBusConfiguration.getInstance()
588: .getFirstProperty("Ports.JMX");
589: if (jmxPort != null) {
590: String javaVersion = System.getProperty("java.version");
591: if (javaVersion.indexOf("1.4") != -1) { // In ESB, JMX is not supported on JDK 1.4
592: log
593: .warn("JMX is not supported on JDK 1.4. "
594: + "Please use JDK 1.5 or newer version if you requre JMX functionality.");
595: return;
596: }
597: log.info("Starting JMX Connector");
598: int jmxPortInt = Integer.parseInt(jmxPort);
599: MBeanServer mbs = ManagementFactory
600: .getPlatformMBeanServer();
601: try {
602: rmiRegistry = LocateRegistry.createRegistry(jmxPortInt);
603: // Create an RMI connector and start it
604: String jmxURL = "service:jmx:rmi:///jndi/rmi://"
605: + NetworkUtils.getLocalHostname() + ":"
606: + jmxPortInt + "/esb";
607: JMXServiceURL url = new JMXServiceURL(jmxURL);
608:
609: // Security credentials are included in the env Map
610: HashMap env = new HashMap();
611: env.put(JMXConnectorServer.AUTHENTICATOR,
612: new ESBJMXAuthenticator());
613: jmxConnectorServer = JMXConnectorServerFactory
614: .newJMXConnectorServer(url, env, mbs);
615: jmxConnectorServer.start();
616: log.info("JMX Service URL : " + jmxURL);
617: } catch (Exception e) {
618: String msg = "Could not initialize MBean server";
619: log.error(msg, e);
620: throw new ServiceBusException(msg, e);
621: }
622: }
623: }
624:
625: private void stopJMXService() throws ServiceBusException {
626: if (jmxConnectorServer != null) {
627: try {
628: log.info("Shutting down the JMX Connector ");
629: jmxConnectorServer.stop();
630: } catch (IOException e) {
631: String msg = "Error when Shutting down the JMX Connector ";
632: log.error(msg, e);
633: throw new ServiceBusException(msg, e);
634: }
635: }
636: try {
637: UnicastRemoteObject.unexportObject(rmiRegistry, true);
638: } catch (NoSuchObjectException e) {
639: String msg = "Error when stoping localregistry(RMI)";
640: log.error(msg, e);
641: throw new ServiceBusException(msg, e);
642: }
643: }
644:
645: private void registerMBeans() {
646: MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
647: String jmxAgentName = System.getProperty("jmx.agent.name");
648: if (jmxAgentName == null || "".equals(jmxAgentName)) {
649: jmxAgentName = "org.wso2.esb";
650: }
651:
652: registerMBean(mbs, new ServerView(), jmxAgentName
653: + ":Type=Admin,ConnectorName=ServerAdmin");
654: registerMBean(mbs, new ServerStatusView(), jmxAgentName
655: + ":Type=Admin,ConnectorName=ServerStatus");
656:
657: registerMBean(mbs, new ServerStatisticsView(), jmxAgentName
658: + ":Type=Statistics,ConnectorName=ServerStatistics");
659: registerMBean(mbs, new SequenceStatisticsView(), jmxAgentName
660: + ":Type=Statistics,ConnectorName=SequenceStatistics");
661: registerMBean(
662: mbs,
663: new ProxyServiceStatisticsView(),
664: jmxAgentName
665: + ":Type=Statistics,ConnectorName=ProxyServiceStatistics");
666: registerMBean(mbs, new EndpointStatisticsView(), jmxAgentName
667: + ":Type=Statistics,ConnectorName=EndpointStatistics");
668: registerMBean(
669: mbs,
670: new SynapseServiceStatisticsView(),
671: jmxAgentName
672: + ":Type=Statistics,ConnectorName=SynapseServiceStatistics");
673: }
674:
675: private void registerMBean(MBeanServer mbs, Object mbeanInstance,
676: String objectName) {
677: try {
678: ObjectName name = new ObjectName(objectName);
679: Set set = mbs.queryNames(name, null);
680: if (set != null && set.isEmpty()) {
681: mbs.registerMBean(mbeanInstance, name);
682: } else {
683: mbs.unregisterMBean(name);
684: mbs.registerMBean(mbeanInstance, name);
685: }
686: } catch (Exception e) {
687: log.warn("Error registering a MBean with objectname ' "
688: + objectName + " ' for JMX management", e);
689: }
690: }
691:
692: /**
693: * Creates a temp directory for axis2 working dir
694: */
695: private static void createTempAxisWorkDirectory() {
696: String tempDirName = System.getProperty("java.io.tmpdir");
697: if (tempDirName != null || !"".equals(tempDirName)) {
698: File tempDir = new File(tempDirName, "_axis2");
699: if (tempDir.exists()) {
700: //Deletes already exists directory
701: deleteNonEmptyDirectory(tempDir);
702: }
703: tempDir.mkdirs();
704: }
705: }
706:
707: /**
708: * Deletes a non-empty directory
709: *
710: * @param directory The current directory
711: * @return True if a deletion successes
712: */
713: private static boolean deleteNonEmptyDirectory(File directory) {
714: if (directory.isDirectory()) {
715: //delete all child directories and files
716: String[] children = directory.list();
717: for (int i = 0; i < children.length; i++) {
718: boolean success = deleteNonEmptyDirectory(new File(
719: directory, children[i]));
720: if (!success) {
721: return false;
722: }
723: }
724: }
725: // The directory is now empty so delete it
726: return directory.delete();
727: }
728:
729: public int getHttpPort() {
730: return httpPort;
731: }
732:
733: public void setHttpPort(int httpPort) {
734: this .httpPort = httpPort;
735: }
736:
737: public int getHttpsPort() {
738: return httpsPort;
739: }
740:
741: public void setHttpsPort(int httpsPort) {
742: this .httpsPort = httpsPort;
743: }
744:
745: public String getHost() {
746: return host;
747: }
748:
749: public void setHost(String host) {
750: this .host = host;
751: }
752:
753: public ConfigurationContext getConfigurationContext() {
754: return configurationContext;
755: }
756:
757: public void setConfigurationContext(
758: ConfigurationContext configurationContext) {
759: this.configurationContext = configurationContext;
760: }
761: }
|