1 | package gov.va.med.edp;
|
---|
2 |
|
---|
3 | import gov.va.med.edp.vistalink.VistaLinkTemplate;
|
---|
4 | import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfig;
|
---|
5 | import gov.va.med.edp.vistalink.locator.VistaLinkConnectorConfigConnectionFactoryLocator;
|
---|
6 | import joptsimple.OptionException;
|
---|
7 | import joptsimple.OptionParser;
|
---|
8 | import joptsimple.OptionSet;
|
---|
9 | import joptsimple.OptionSpec;
|
---|
10 |
|
---|
11 | import java.io.Console;
|
---|
12 | import java.io.IOException;
|
---|
13 | import java.util.ArrayList;
|
---|
14 | import java.util.HashSet;
|
---|
15 | import java.util.List;
|
---|
16 |
|
---|
17 | import static java.util.Arrays.asList;
|
---|
18 |
|
---|
19 | public class VistaLinkTester {
|
---|
20 | public static void main(String[] args) throws IOException {
|
---|
21 | OptionParser parser = new OptionParser();
|
---|
22 | OptionSpec<String> hostOption = parser.acceptsAll(asList("S", "server", "host")).withRequiredArg().ofType(String.class);
|
---|
23 | OptionSpec<Integer> portOption = parser.acceptsAll(asList("P", "port")).withRequiredArg().ofType(Integer.class);
|
---|
24 | OptionSpec<String> divisionOption = parser.acceptsAll(asList("D", "division", "station-num")).withRequiredArg().ofType(String.class);
|
---|
25 | OptionSpec<String> rpcContextOption = parser.acceptsAll(asList("C", "context", "rpc-context")).withRequiredArg().ofType(String.class);
|
---|
26 | OptionSpec<String> rpcNameOption = parser.acceptsAll(asList("N", "name", "rpc-name")).withRequiredArg().ofType(String.class);
|
---|
27 |
|
---|
28 | try {
|
---|
29 | OptionSet options = parser.parse(args);
|
---|
30 |
|
---|
31 | Console console = System.console();
|
---|
32 |
|
---|
33 | String host = options.has(hostOption) ? hostOption.value(options) : console.readLine("Host: ");
|
---|
34 | int port = options.has(portOption) ? portOption.value(options) : Integer.parseInt(console.readLine("Port: "));
|
---|
35 | String division = options.has(divisionOption) ? divisionOption.value(options) : console.readLine("Division: ");
|
---|
36 |
|
---|
37 | char[] accessCode = console.readPassword("Access: ");
|
---|
38 | char[] verifyCode = console.readPassword("Verify: ");
|
---|
39 |
|
---|
40 | String rpcContext = options.has(rpcContextOption) ? rpcContextOption.value(options) : console.readLine("RPC Context: ");
|
---|
41 | String rpcName = options.has(rpcNameOption) ? rpcNameOption.value(options) : console.readLine("RPC Name: ");
|
---|
42 | ;
|
---|
43 |
|
---|
44 | if (rpcContext == null) rpcContext = "";
|
---|
45 |
|
---|
46 | VistaLinkTester tester = new VistaLinkTester(host, port, division, accessCode.toString(), verifyCode.toString());
|
---|
47 |
|
---|
48 | System.out.println("Enter RPC Parameters (^ when finished)");
|
---|
49 |
|
---|
50 | List<String> params = new ArrayList<String>();
|
---|
51 | int i = 1;
|
---|
52 | boolean done = false;
|
---|
53 | while (!done) {
|
---|
54 | String param = console.readLine("RPC Param " + i + ": ");
|
---|
55 | if (param.equalsIgnoreCase("^")) {
|
---|
56 | done = true;
|
---|
57 | } else {
|
---|
58 | params.add(param);
|
---|
59 | i++;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | System.out.println("Executing vlink://" + division + "@" + host + ":" + port + "/" + rpcContext + "/" + rpcName);
|
---|
64 |
|
---|
65 | System.out.println(tester.execute(rpcContext, rpcName, params));
|
---|
66 | } catch (OptionException e) {
|
---|
67 | System.out.println(e.getLocalizedMessage());
|
---|
68 | System.out.println("Usage:");
|
---|
69 | parser.printHelpOn(System.out);
|
---|
70 | System.exit(1);
|
---|
71 | } catch (Throwable t) {
|
---|
72 | t.printStackTrace();
|
---|
73 | }
|
---|
74 | // HashSet connectors = new HashSet();
|
---|
75 | // connectors.add(new VistaLinkConnectorConfig("500", "WORLDVISTA DEMO CLINIC", "66.206.177.84", 9310, "EDISUSER1", "VISTAIS#1"));
|
---|
76 | }
|
---|
77 |
|
---|
78 | private String division;
|
---|
79 |
|
---|
80 | private VistaLinkTemplate t;
|
---|
81 |
|
---|
82 | public VistaLinkTester(String host, int port, String division, String accessCode, String verifyCode) {
|
---|
83 | this.division = division;
|
---|
84 |
|
---|
85 | HashSet connectors = new HashSet();
|
---|
86 | connectors.add(new VistaLinkConnectorConfig(division, "VISTALINK TESTER", host, port, accessCode, verifyCode));
|
---|
87 |
|
---|
88 | VistaLinkConnectorConfigConnectionFactoryLocator l = new VistaLinkConnectorConfigConnectionFactoryLocator();
|
---|
89 | l.setConnectors(connectors);
|
---|
90 |
|
---|
91 | t = new VistaLinkTemplate(l);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public String execute(String rpcContext, String rpcName, List params) {
|
---|
95 | if (params.size() > 0)
|
---|
96 | return t.rpcAsApplication(this.division, "VISTALINK TESTER", rpcContext, rpcName, params);
|
---|
97 | else
|
---|
98 | return t.rpcAsApplication(this.division, "VISTALINK TESTER", rpcContext, rpcName);
|
---|
99 | }
|
---|
100 | }
|
---|