1 | /** |
---|
2 | * This software is copyright (c) 2011-2013 by |
---|
3 | * - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
4 | * This is free software. You can redistribute it |
---|
5 | * and/or modify it under the terms described in |
---|
6 | * the GNU General Public License v3 of which you |
---|
7 | * should have received a copy. Otherwise you can download |
---|
8 | * it from |
---|
9 | * |
---|
10 | * http://www.gnu.org/licenses/gpl-3.0.txt |
---|
11 | * |
---|
12 | * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
13 | * |
---|
14 | * @license http://www.gnu.org/licenses/gpl-3.0.txt |
---|
15 | * GNU General Public License v3 |
---|
16 | */ |
---|
17 | package eu.clarin.sru.client; |
---|
18 | |
---|
19 | import org.slf4j.Logger; |
---|
20 | import org.slf4j.LoggerFactory; |
---|
21 | |
---|
22 | import eu.clarin.sru.client.fcs.ClarinFCSRecordParser; |
---|
23 | |
---|
24 | |
---|
25 | public class TestClient { |
---|
26 | private static final Logger logger = |
---|
27 | LoggerFactory.getLogger(TestClient.class); |
---|
28 | |
---|
29 | |
---|
30 | public static void main(String[] args) { |
---|
31 | if (args.length > 0) { |
---|
32 | logger.info("initializing client ..."); |
---|
33 | SRUClient client = new SRUClient(); |
---|
34 | |
---|
35 | try { |
---|
36 | client.registerRecordParser(new ClarinFCSRecordParser()); |
---|
37 | } catch (SRUClientException e) { |
---|
38 | logger.error("error adding record parser", e); |
---|
39 | System.exit(1); |
---|
40 | } |
---|
41 | |
---|
42 | // explain |
---|
43 | try { |
---|
44 | logger.info("performing 'explain' request ..."); |
---|
45 | SRUExplainRequest request = TestUtils.makeExplainRequest(args[0]); |
---|
46 | SRUExplainResponse response = client.explain(request); |
---|
47 | TestUtils.printExplainResponse(response); |
---|
48 | } catch (SRUClientException e) { |
---|
49 | logger.error("a fatal error occured while performing 'explain' request", e); |
---|
50 | } |
---|
51 | |
---|
52 | // scan |
---|
53 | try { |
---|
54 | logger.info("performing 'scan' request ..."); |
---|
55 | SRUScanRequest request = TestUtils.makeScanRequest(args[0]); |
---|
56 | SRUScanResponse response = client.scan(request); |
---|
57 | TestUtils.printScanResponse(response); |
---|
58 | } catch (SRUClientException e) { |
---|
59 | logger.error("a fatal error occured while performing 'scan' request", e); |
---|
60 | } |
---|
61 | |
---|
62 | // searchRetrieve |
---|
63 | try { |
---|
64 | logger.info("performing 'searchRetrieve' request ..."); |
---|
65 | SRUSearchRetrieveRequest request = TestUtils.makeSearchRequest(args[0], null); |
---|
66 | SRUSearchRetrieveResponse response = client.searchRetrieve(request); |
---|
67 | TestUtils.printSearchResponse(response); |
---|
68 | } catch (SRUClientException e) { |
---|
69 | logger.error("a fatal error occured while performing 'searchRetrieve' request", e); |
---|
70 | } |
---|
71 | |
---|
72 | logger.info("done"); |
---|
73 | } else { |
---|
74 | System.err.println("missing args"); |
---|
75 | System.exit(64); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | static { |
---|
81 | org.apache.log4j.BasicConfigurator |
---|
82 | .configure(new org.apache.log4j.ConsoleAppender( |
---|
83 | new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"), |
---|
84 | org.apache.log4j.ConsoleAppender.SYSTEM_ERR)); |
---|
85 | org.apache.log4j.Logger logger = org.apache.log4j.Logger |
---|
86 | .getRootLogger(); |
---|
87 | logger.setLevel(org.apache.log4j.Level.INFO); |
---|
88 | logger.getLoggerRepository().getLogger("eu.clarin") |
---|
89 | .setLevel(org.apache.log4j.Level.DEBUG); |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|