1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.httpmonitor;
|
---|
16 |
|
---|
17 | import java.util.Arrays;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.autoquest.httpmonitor.proxy.HttpMonitoringProxy;
|
---|
20 | import de.ugoe.cs.util.console.Console;
|
---|
21 | import de.ugoe.cs.util.console.TextConsole;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * <p>
|
---|
25 | * implements the main method to start the {@link HttpMonitor} or the {@link HttpMonitoringProxy}.
|
---|
26 | * Which one is to be started is determined by the first command line argument. If this is set to
|
---|
27 | * "proxy" then the proxy is started. If this is set to "monitor" or left out then the monitor is
|
---|
28 | * started.
|
---|
29 | * </p>
|
---|
30 | *
|
---|
31 | * @author Patrick Harms
|
---|
32 | * @version 1.0
|
---|
33 | */
|
---|
34 | public class Runner {
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * <p>
|
---|
38 | * Main method of the application.
|
---|
39 | * </p>
|
---|
40 | *
|
---|
41 | * @param args command line arguments
|
---|
42 | */
|
---|
43 | public static void main(String[] args) {
|
---|
44 | new TextConsole();
|
---|
45 |
|
---|
46 | String type;
|
---|
47 | if (args.length > 0) {
|
---|
48 | type = args[0];
|
---|
49 | }
|
---|
50 | else {
|
---|
51 | type = "monitor";
|
---|
52 | }
|
---|
53 |
|
---|
54 | HttpMonitorComponent component;
|
---|
55 | String[] remainingArgs = Arrays.copyOfRange(args, 1, args.length);
|
---|
56 |
|
---|
57 | if ("monitor".equalsIgnoreCase(type)) {
|
---|
58 | component = new HttpMonitor(remainingArgs);
|
---|
59 | }
|
---|
60 | else if ("proxy".equalsIgnoreCase(type)) {
|
---|
61 | component = new HttpMonitoringProxy(remainingArgs);
|
---|
62 | }
|
---|
63 | else {
|
---|
64 | throw new IllegalArgumentException("unknown type of server requested: " + type);
|
---|
65 | }
|
---|
66 |
|
---|
67 | try {
|
---|
68 | component.init();
|
---|
69 | }
|
---|
70 | catch (HttpMonitorException e) {
|
---|
71 | Console.printerrln("could not initialize HTTP " + type + " server: " + e.getMessage());
|
---|
72 | Console.logException(e);
|
---|
73 | }
|
---|
74 |
|
---|
75 | try {
|
---|
76 | component.start();
|
---|
77 | }
|
---|
78 | catch (HttpMonitorException e) {
|
---|
79 | Console.printerrln("could not start HTTP " + type + " server: " + e.getMessage());
|
---|
80 | Console.logException(e);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|