1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.service;
15
16 import uk.nhs.interoperability.capabilities.DirectoryOfServices;
17 import uk.nhs.interoperability.infrastructure.ITKAddress;
18 import uk.nhs.interoperability.infrastructure.ITKServiceImpl;
19 import uk.nhs.interoperability.transport.ITKTransportRoute;
20 import uk.nhs.interoperability.transport.ITKTransportRouteImpl;
21 import uk.nhs.interoperability.util.ITKDirectoryProperties;
22 import uk.nhs.interoperability.util.ITKServiceProperties;
23 import uk.nhs.interoperability.util.Logger;
24
25
26
27
28
29
30
31
32 public class ITKSimpleDOS implements DirectoryOfServices {
33
34
35 private static final String IS_SUPPORTED = "supported";
36
37
38 private static final String SUPPORTS_ASYNC = "supportsAsync";
39
40
41 private static final String SUPPORTS_SYNC = "supportsSync";
42
43
44 private static final String IS_BASE64 = "isBase64";
45
46
47 private static final String MIME_TYPE = "mimeType";
48
49
50 private static final String CHANNELID = "channelid";
51
52
53 private static final String TIME_TO_LIVE = "TimeToLive";
54
55
56 private static final String WRAPPER_TYPE = "WrapperType";
57
58
59 private static final String DESTINATION_TYPE = "DestinationType";
60
61
62 private static final String EXCEPTION_TO = "ExceptionTo";
63
64
65 private static final String DEFAULT = "DEFAULT";
66
67
68 private static final String REPLY_TO = "ReplyTo";
69
70
71 private static final String ROUTE_TYPE = "RouteType";
72
73
74 private static final String PHYSICAL_DESTINATION = "PhysicalDestination";
75
76
77
78
79 @Override
80 public ITKTransportRoute resolveDestination(String serviceId, ITKAddress address) {
81
82 ITKTransportRoute route = null;
83
84 String svc = serviceId;
85 String add = address.getURI();
86 String channelKey = svc + "." + add + "." + CHANNELID;
87 Logger.trace("Channel Key:"+channelKey);
88
89 String channelId = ITKDirectoryProperties.getProperty(channelKey);
90
91 if (null!=channelId){
92 Logger.trace("Channel Id:"+channelId);
93 String physicalDestination = getDirectoryProperty(channelId,PHYSICAL_DESTINATION);
94 String routeType = getDirectoryProperty(channelId,ROUTE_TYPE);
95 String replyTo = getDirectoryProperty(channelId,REPLY_TO);
96 String exceptionTo = getDirectoryProperty(channelId,EXCEPTION_TO);
97 String destinationType = getDirectoryProperty(channelId,DESTINATION_TYPE);
98 String wrapperType = getDirectoryProperty(channelId,WRAPPER_TYPE);
99 String timeToLive = getDirectoryProperty(channelId,TIME_TO_LIVE);
100
101
102 int ttl = 30*60;
103 if (null!=timeToLive){
104 ttl = Integer.parseInt(timeToLive);
105 }
106 route = new ITKTransportRouteImpl(routeType,physicalDestination,
107 replyTo,exceptionTo,destinationType,wrapperType,ttl);
108 }
109
110 return route;
111 }
112
113
114
115
116
117
118
119
120 private String getDirectoryProperty(String channelId, String propertyName){
121 String propertyValue = ITKDirectoryProperties.getProperty(channelId+"."+propertyName);
122 if (propertyValue==null){
123 propertyValue = ITKDirectoryProperties.getProperty(DEFAULT+"."+propertyName);
124 }
125 if (propertyValue==null){
126 propertyValue = "";
127 }
128 return propertyValue;
129 }
130
131
132
133
134 public ITKService getService(String serviceId) {
135
136 ITKServiceImpl service = new ITKServiceImpl(serviceId);
137
138 boolean isSupported = getServiceBooleanProperty(serviceId, IS_SUPPORTED);
139 if (!isSupported) {
140 return null;
141 }
142 service.setBase64(getServiceBooleanProperty(serviceId, IS_BASE64));
143 service.setSupportsSync(getServiceBooleanProperty(serviceId, SUPPORTS_SYNC));
144 service.setSupportsAsync(getServiceBooleanProperty(serviceId, SUPPORTS_ASYNC));
145 service.setMimeType(getServiceProperty(serviceId, MIME_TYPE));
146
147 return service;
148 }
149
150
151
152
153
154
155
156
157 private String getServiceProperty(String serviceId, String propertyName){
158
159 String propertyValue = ITKServiceProperties.getProperty(serviceId+"."+propertyName);
160 if (propertyValue==null){
161 propertyValue = ITKServiceProperties.getProperty(DEFAULT+"."+propertyName);
162 }
163 if (propertyValue==null){
164 propertyValue = "";
165 }
166 return propertyValue;
167 }
168
169
170
171
172
173
174
175
176 private boolean getServiceBooleanProperty(String serviceId, String propertyName){
177
178 boolean propertyValue = false;
179 if (!propertyName.equals("")){
180
181 String serviceProperty = ITKServiceProperties.getProperty(serviceId+"."+propertyName);
182
183 if (null!=serviceProperty){
184 if (serviceProperty.equals("Y")){
185 propertyValue = true;
186 }
187 } else {
188 serviceProperty = ITKServiceProperties.getProperty("DEFAULT."+propertyName);
189
190 }
191 }
192 return propertyValue;
193 }
194 }