/
configuration.java
72 lines (64 loc) · 2.16 KB
/
configuration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public class configuration {
public static void main(String[] args) throws Exception {
// All configuration in file pointed to by
// --Ice.Config=file.config
// No username, password entered
omero.client client1 = new omero.client(args);
try {
client1.createSession();
} catch (Ice.ConnectionRefusedException cre) {
// Bad address or port?
} finally {
client1.closeSession();
}
// Most basic configuration.
// Uses default port 4064
// createSession needs username and password
omero.client client2 = new omero.client("localhost");
try {
client2.createSession("root", "ome");
} catch (Ice.ConnectionRefusedException cre) {
// Bad address or port?
} finally {
client2.closeSession();
}
// Configuration with port information
omero.client client3 = new omero.client("localhost", 24064);
try {
client3.createSession("root", "ome");
} catch (Ice.ConnectionRefusedException cre) {
// Bad address or port?
} finally {
client3.closeSession();
}
// Advanced configuration can also be done
// via an InitializationData instance.
Ice.InitializationData data = new Ice.InitializationData();
data.properties = Ice.Util.createProperties();
data.properties.setProperty("omero.host", "localhost");
omero.client client4 = new omero.client(data);
try {
client4.createSession("root", "ome");
} catch (Ice.ConnectionRefusedException cre) {
// Bad address or port?
} finally {
client4.closeSession();
}
// Or alternatively via a java.util.Map instance
java.util.Map<String, String> map = new java.util.HashMap<String, String>();
map.put("omero.host", "localhost");
map.put("omero.user", "root");
map.put("omero.pass", "ome");
omero.client client5 = new omero.client(map);
// Again, no username or password needed
// since present in the map. But they *can*
// be overridden.
try {
client5.createSession();
} catch (Ice.ConnectionRefusedException cre) {
// Bad address or port?
} finally {
client5.closeSession();
}
}
}