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.plugin.http.commands;
|
---|
16 |
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.List;
|
---|
19 |
|
---|
20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
22 | import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser;
|
---|
23 | import de.ugoe.cs.util.console.Command;
|
---|
24 | import de.ugoe.cs.util.console.Console;
|
---|
25 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * <p>
|
---|
29 | * Command to parse a file with a session monitored by AutoQUESTs HTTP monitor.
|
---|
30 | * </p>
|
---|
31 | *
|
---|
32 | * @author Patrick Harms
|
---|
33 | * @version 1.0
|
---|
34 | */
|
---|
35 | public class CMDparseHTTP implements Command {
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * (non-Javadoc)
|
---|
39 | *
|
---|
40 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
41 | */
|
---|
42 | @Override
|
---|
43 | public void run(List<Object> parameters) {
|
---|
44 | String filename = null;
|
---|
45 | String sequencesName = "sequences";
|
---|
46 |
|
---|
47 | try {
|
---|
48 | filename = (String) parameters.get(0);
|
---|
49 | if (parameters.size() >= 2) {
|
---|
50 | sequencesName = (String) parameters.get(1);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | catch (Exception e) {
|
---|
54 | throw new IllegalArgumentException("missing parameter for file name");
|
---|
55 | }
|
---|
56 |
|
---|
57 | HTTPLogParser parser = new HTTPLogParser();
|
---|
58 |
|
---|
59 | try {
|
---|
60 | parser.parseFile(filename);
|
---|
61 | }
|
---|
62 | catch (Exception e) {
|
---|
63 | Console.printerrln("Could not parse " + filename + ": " + e.getMessage());
|
---|
64 | return;
|
---|
65 | }
|
---|
66 |
|
---|
67 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
68 |
|
---|
69 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
70 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * (non-Javadoc)
|
---|
76 | *
|
---|
77 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
78 | */
|
---|
79 | @Override
|
---|
80 | public String help() {
|
---|
81 | return "parseHTTP <filename> [<sequencesName>]";
|
---|
82 | }
|
---|
83 |
|
---|
84 | }
|
---|