001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.transport;
021:
022: import org.apache.axis2.context.ConfigurationContext;
023: import org.apache.axis2.context.ConfigurationContextFactory;
024: import org.apache.axis2.engine.ListenerManager;
025: import org.apache.axis2.engine.AxisServer;
026: import org.apache.axis2.transport.http.SimpleHTTPServer;
027: import org.apache.axis2.util.CommandLineOption;
028: import org.apache.axis2.util.CommandLineOptionParser;
029: import org.apache.axis2.util.OptionsValidator;
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032:
033: import java.io.File;
034: import java.util.List;
035: import java.util.Map;
036:
037: public class SimpleAxis2Server extends AxisServer {
038:
039: private static final Log log = LogFactory
040: .getLog(SimpleHTTPServer.class);
041:
042: int port = -1;
043:
044: public static int DEFAULT_PORT = 8080;
045:
046: public SimpleAxis2Server(String repoLocation, String confLocation)
047: throws Exception {
048: super (false);
049: configContext = ConfigurationContextFactory
050: .createConfigurationContextFromFileSystem(repoLocation,
051: confLocation);
052: }
053:
054: /**
055: * @param args
056: * @throws Exception
057: */
058: public static void main(String[] args) throws Exception {
059: String repoLocation = null;
060: String confLocation = null;
061:
062: CommandLineOptionParser optionsParser = new CommandLineOptionParser(
063: args);
064: List invalidOptionsList = optionsParser
065: .getInvalidOptions(new OptionsValidator() {
066: public boolean isInvalid(CommandLineOption option) {
067: String optionType = option.getOptionType();
068: return !("repo".equalsIgnoreCase(optionType) || "conf"
069: .equalsIgnoreCase(optionType));
070: }
071: });
072:
073: if ((invalidOptionsList.size() > 0) || (args.length > 4)) {
074: printUsage();
075: return;
076: }
077:
078: Map optionsMap = optionsParser.getAllOptions();
079:
080: CommandLineOption repoOption = (CommandLineOption) optionsMap
081: .get("repo");
082: CommandLineOption confOption = (CommandLineOption) optionsMap
083: .get("conf");
084:
085: log.info("[SimpleAxisServer] Starting");
086: if (repoOption != null) {
087: repoLocation = repoOption.getOptionValue();
088: log.info("[SimpleAxisServer] Using the Axis2 Repository"
089: + new File(repoLocation).getAbsolutePath());
090: System.out
091: .println("[SimpleAxisServer] Using the Axis2 Repository"
092: + new File(repoLocation).getAbsolutePath());
093: }
094: if (confOption != null) {
095: confLocation = confOption.getOptionValue();
096: System.out
097: .println("[SimpleAxisServer] Using the Axis2 Configuration File"
098: + new File(confLocation).getAbsolutePath());
099: }
100:
101: try {
102: SimpleAxis2Server server = new SimpleAxis2Server(
103: repoLocation, confLocation);
104: server.start();
105: log.info("[SimpleAxisServer] Started");
106: System.out.println("[SimpleAxisServer] Started");
107: } catch (Throwable t) {
108: log
109: .fatal(
110: "[SimpleAxisServer] Shutting down. Error starting SimpleAxisServer",
111: t);
112: System.err
113: .println("[SimpleAxisServer] Shutting down. Error starting SimpleAxisServer");
114: }
115: }
116:
117: public static void printUsage() {
118: System.out
119: .println("Usage: SimpleAxisServer -repo <repository> -conf <axis2 configuration file>");
120: System.out.println();
121: System.exit(1);
122: }
123: }
|