This project has retired. For details please refer to its
Attic page.
TckCommon xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.v3.tck;
17
18 import java.rmi.RemoteException;
19 import java.util.List;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.uddi.api_v3.BindingTemplate;
23 import org.uddi.api_v3.BindingTemplates;
24 import org.uddi.api_v3.BusinessEntity;
25 import org.uddi.api_v3.BusinessInfos;
26 import org.uddi.api_v3.BusinessList;
27 import org.uddi.api_v3.BusinessService;
28 import org.uddi.api_v3.CategoryBag;
29 import org.uddi.api_v3.Contacts;
30 import org.uddi.api_v3.DeleteBusiness;
31 import org.uddi.api_v3.Description;
32 import org.uddi.api_v3.FindBusiness;
33 import org.uddi.api_v3.FindQualifiers;
34 import org.uddi.api_v3.FindService;
35 import org.uddi.api_v3.FindTModel;
36 import org.uddi.api_v3.GetOperationalInfo;
37 import org.uddi.api_v3.GetServiceDetail;
38 import org.uddi.api_v3.KeyedReference;
39 import org.uddi.api_v3.Name;
40 import org.uddi.api_v3.OperationalInfos;
41 import org.uddi.api_v3.ServiceDetail;
42 import org.uddi.api_v3.ServiceInfos;
43 import org.uddi.api_v3.ServiceList;
44 import org.uddi.api_v3.TModelList;
45 import org.uddi.sub_v3.DeleteSubscription;
46 import org.uddi.sub_v3.Subscription;
47 import org.uddi.v3_service.UDDIInquiryPortType;
48 import org.uddi.v3_service.UDDIPublicationPortType;
49 import org.uddi.v3_service.UDDISubscriptionPortType;
50
51
52
53
54
55
56 public class TckCommon {
57
58 private static Log logger = LogFactory.getLog(TckCommon.class);
59
60
61
62
63
64
65
66
67 public static String CatBagToString(CategoryBag categoryBag) {
68 StringBuilder sb = new StringBuilder();
69 if (categoryBag == null) {
70 return "no data";
71 }
72 for (int i = 0; i < categoryBag.getKeyedReference().size(); i++) {
73 sb.append(KeyedReferenceToString(categoryBag.getKeyedReference().get(i)));
74 }
75 for (int i = 0; i < categoryBag.getKeyedReferenceGroup().size(); i++) {
76 sb.append("Key Ref Grp: TModelKey=");
77 for (int k = 0; k < categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().size(); k++) {
78 sb.append(KeyedReferenceToString(categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().get(k)));
79 }
80 }
81 return sb.toString();
82 }
83
84 public static String KeyedReferenceToString(KeyedReference item) {
85 StringBuilder sb = new StringBuilder();
86 sb.append("Key Ref: Name=").
87 append(item.getKeyName()).
88 append(" Value=").
89 append(item.getKeyValue()).
90 append(" tModel=").
91 append(item.getTModelKey()).
92 append(System.getProperty("line.separator"));
93 return sb.toString();
94 }
95
96 public static void PrintContacts(Contacts contacts) {
97 if (contacts == null) {
98 return;
99 }
100 for (int i = 0; i < contacts.getContact().size(); i++) {
101 System.out.println("Contact " + i + " type:" + contacts.getContact().get(i).getUseType());
102 for (int k = 0; k < contacts.getContact().get(i).getPersonName().size(); k++) {
103 System.out.println("Name: " + contacts.getContact().get(i).getPersonName().get(k).getValue());
104 }
105 for (int k = 0; k < contacts.getContact().get(i).getEmail().size(); k++) {
106 System.out.println("Email: " + contacts.getContact().get(i).getEmail().get(k).getValue());
107 }
108 for (int k = 0; k < contacts.getContact().get(i).getAddress().size(); k++) {
109 System.out.println("Address sort code " + contacts.getContact().get(i).getAddress().get(k).getSortCode());
110 System.out.println("Address use type " + contacts.getContact().get(i).getAddress().get(k).getUseType());
111 System.out.println("Address tmodel key " + contacts.getContact().get(i).getAddress().get(k).getTModelKey());
112 for (int x = 0; x < contacts.getContact().get(i).getAddress().get(k).getAddressLine().size(); x++) {
113 System.out.println("Address line value " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getValue());
114 System.out.println("Address line key name " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyName());
115 System.out.println("Address line key value " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyValue());
116 }
117 }
118 for (int k = 0; k < contacts.getContact().get(i).getDescription().size(); k++) {
119 System.out.println("Desc: " + contacts.getContact().get(i).getDescription().get(k).getValue());
120 }
121 for (int k = 0; k < contacts.getContact().get(i).getPhone().size(); k++) {
122 System.out.println("Phone: " + contacts.getContact().get(i).getPhone().get(k).getValue());
123 }
124 }
125
126 }
127
128
129
130
131
132
133
134 public static void PrintBindingTemplates(BindingTemplates bindingTemplates) {
135 if (bindingTemplates == null) {
136 return;
137 }
138 for (int i = 0; i < bindingTemplates.getBindingTemplate().size(); i++) {
139 System.out.println("Binding Key: " + bindingTemplates.getBindingTemplate().get(i).getBindingKey());
140
141 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint() != null) {
142 System.out.println("Access Point: " + bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getValue() + " type " + bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType());
143 }
144
145 if (bindingTemplates.getBindingTemplate().get(i).getHostingRedirector() != null) {
146 System.out.println("Hosting Redirection: " + bindingTemplates.getBindingTemplate().get(i).getHostingRedirector().getBindingKey());
147 }
148 }
149 }
150
151 public static void PrintBusinessInfo(BusinessInfos businessInfos) {
152 if (businessInfos == null) {
153 System.out.println("No data returned");
154 } else {
155 for (int i = 0; i < businessInfos.getBusinessInfo().size(); i++) {
156 System.out.println("===============================================");
157 System.out.println("Business Key: " + businessInfos.getBusinessInfo().get(i).getBusinessKey());
158 System.out.println("Name: " + ListToString(businessInfos.getBusinessInfo().get(i).getName()));
159
160 System.out.println("Name: " + ListToDescString(businessInfos.getBusinessInfo().get(i).getDescription()));
161 System.out.println("Services:");
162 PrintServiceInfo(businessInfos.getBusinessInfo().get(i).getServiceInfos());
163 }
164 }
165 }
166
167 public static String ListToString(List<Name> name) {
168 StringBuilder sb = new StringBuilder();
169 for (int i = 0; i < name.size(); i++) {
170 sb.append(name.get(i).getValue()).append(" ");
171 }
172 return sb.toString();
173 }
174
175 public static String ListToDescString(List<Description> name) {
176 StringBuilder sb = new StringBuilder();
177 for (int i = 0; i < name.size(); i++) {
178 sb.append(name.get(i).getValue()).append(" ");
179 }
180 return sb.toString();
181 }
182
183 public static void PrintServiceInfo(ServiceInfos serviceInfos) {
184 for (int i = 0; i < serviceInfos.getServiceInfo().size(); i++) {
185 System.out.println("-------------------------------------------");
186 System.out.println("Service Key: " + serviceInfos.getServiceInfo().get(i).getServiceKey());
187 System.out.println("Owning Business Key: " + serviceInfos.getServiceInfo().get(i).getBusinessKey());
188 System.out.println("Name: " + ListToString(serviceInfos.getServiceInfo().get(i).getName()));
189 }
190 }
191
192 public static void PrintBusinessDetails(List<BusinessEntity> businessDetail) {
193
194
195 for (int i = 0; i < businessDetail.size(); i++) {
196 System.out.println("Business Detail - key: " + businessDetail.get(i).getBusinessKey());
197 System.out.println("Name: " + ListToString(businessDetail.get(i).getName()));
198 System.out.println("CategoryBag: " + CatBagToString(businessDetail.get(i).getCategoryBag()));
199 PrintContacts(businessDetail.get(i).getContacts());
200 }
201 }
202
203
204
205
206
207
208
209
210
211 public static void DeleteBusiness(String key, String authInfo, UDDIPublicationPortType publish) {
212 if (key == null) {
213 return;
214 }
215 try {
216 DeleteBusiness db = new DeleteBusiness();
217 db.setAuthInfo(authInfo);
218 db.getBusinessKey().add(key);
219 publish.deleteBusiness(db);
220 } catch (Exception ex) {
221 logger.warn("failed to delete business " + key + " " + ex.getMessage());
222 logger.debug("failed to delete business " + key + " " + ex.getMessage(), ex);
223 }
224 }
225
226 public static void removeAllExistingSubscriptions(String authinfo, UDDISubscriptionPortType sub) {
227 List<Subscription> subscriptions;
228 try {
229 subscriptions = sub.getSubscriptions(authinfo);
230
231 DeleteSubscription ds = new DeleteSubscription();
232 ds.setAuthInfo(authinfo);
233 for (int i = 0; i < subscriptions.size(); i++) {
234 ds.getSubscriptionKey().add(subscriptions.get(i).getSubscriptionKey());
235 }
236 if (!subscriptions.isEmpty()) {
237 logger.info("Purging " + subscriptions.size() + " old subscriptions");
238 sub.deleteSubscription(ds);
239 }
240 } catch (Exception ex) {
241 logger.warn("error clearing subscriptions", ex);
242 }
243 }
244
245
246
247
248
249 public static boolean isDebug() {
250 boolean serialize = false;
251 try {
252 if (System.getProperty("debug") != null
253 && System.getProperty("debug").equalsIgnoreCase("true")) {
254 serialize = true;
255 }
256 } catch (Exception ex) {
257 }
258 return serialize;
259 }
260
261
262 public static String DumpAllServices(String authinfo, UDDIInquiryPortType inquiry) {
263 StringBuilder sb = new StringBuilder();
264 FindService fs = new FindService();
265 fs.setAuthInfo(authinfo);
266 fs.setFindQualifiers(new FindQualifiers());
267 fs.getFindQualifiers().getFindQualifier().add("approximateMatch");
268 fs.getName().add(new Name("%", null));
269 try {
270 ServiceList findService = inquiry.findService(fs);
271 if (findService.getServiceInfos() == null) {
272 return ("NO SERVICES RETURNED!");
273 } else {
274 for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
275 sb.append(findService.getServiceInfos().getServiceInfo().get(i).getName().get(0).getValue()).
276 append(" lang=").append(findService.getServiceInfos().getServiceInfo().get(i).getName().get(0).getLang()).
277 append(" ").append(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey()).
278 append(" ").append(findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey()).
279 append(System.getProperty("line.separator"));
280 GetServiceDetail req=new GetServiceDetail();
281 req.setAuthInfo(authinfo);
282 req.getServiceKey().add(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey());
283 ServiceDetail d=inquiry.getServiceDetail(req);
284 for(BusinessService bs : d.getBusinessService()){
285 for(BindingTemplate bt:bs.getBindingTemplates().getBindingTemplate()){
286 sb.append(bt.getBindingKey());
287 sb.append(" ");
288 sb.append(bt.getAccessPoint().getValue());
289 sb. append(System.getProperty("line.separator"));
290 }
291 }
292 }
293 }
294 } catch (Exception ex) {
295 sb.append(ex.getMessage());
296 }
297 return sb.toString();
298 }
299
300
301 public static String DumpAllTModels(String authinfo, UDDIInquiryPortType inquriy) {
302 StringBuilder sb = new StringBuilder();
303 FindTModel fs = new FindTModel();
304 fs.setAuthInfo(authinfo);
305 fs.setFindQualifiers(new FindQualifiers());
306 fs.getFindQualifiers().getFindQualifier().add("approximateMatch");
307 fs.setName(new Name("%", null));
308 try {
309 TModelList findService = inquriy.findTModel(fs);
310 if (findService.getTModelInfos()== null) {
311 return ("NO TMODELS RETURNED!");
312 } else {
313 for (int i = 0; i < findService.getTModelInfos().getTModelInfo().size(); i++) {
314 sb.append(findService.getTModelInfos().getTModelInfo().get(i).getName().getValue()).
315 append(" lang=").append(findService.getTModelInfos().getTModelInfo().get(i).getName().getLang()).
316 append(" ").append(findService.getTModelInfos().getTModelInfo().get(i).getTModelKey())
317 .append(System.getProperty("line.separator"));
318 }
319 }
320 } catch (Exception ex) {
321 return ex.getMessage();
322 }
323 return sb.toString();
324 }
325 public static String DumpAllBusinesses(String authinfo, UDDIInquiryPortType inquriy) {
326 StringBuilder sb = new StringBuilder();
327 FindBusiness fs = new FindBusiness();
328 fs.setAuthInfo(authinfo);
329 fs.setFindQualifiers(new FindQualifiers());
330 fs.getFindQualifiers().getFindQualifier().add("approximateMatch");
331 fs.getName().add(new Name("%", null));
332 try {
333 BusinessList findService = inquriy.findBusiness(fs);
334 if (findService.getBusinessInfos() == null) {
335 return ("NO BUSINESSES RETURNED!");
336 } else {
337 for (int i = 0; i < findService.getBusinessInfos().getBusinessInfo().size(); i++) {
338 sb.append(findService.getBusinessInfos().getBusinessInfo().get(i).getName().get(0).getValue()).
339 append(" lang=").append(findService.getBusinessInfos().getBusinessInfo().get(i).getName().get(0).getLang()).
340 append(" ").append(findService.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())
341 .append(System.getProperty("line.separator"));
342 }
343 }
344 } catch (Exception ex) {
345 return ex.getMessage();
346 }
347 return sb.toString();
348 }
349
350 public static void PrintMarker() {
351 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>> MARKER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
352 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>> MARKER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
353 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>> MARKER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
354 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>> MARKER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
355 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>> MARKER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
356 System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>> MARKER <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
357 }
358
359 public static void DumpAllTModelsOpInfo(String authInfoJoe, UDDIInquiryPortType uddiInquiryImpl) throws Exception {
360 FindTModel ftm = new FindTModel();
361 ftm.setAuthInfo(authInfoJoe);
362
363 ftm.setName(new Name("%", null));
364 ftm.setFindQualifiers(new FindQualifiers());
365 ftm.getFindQualifiers().getFindQualifier().add("approximateMatch");
366 TModelList findTModel = uddiInquiryImpl.findTModel(ftm);
367
368 GetOperationalInfo req = new GetOperationalInfo();
369 req.setAuthInfo(authInfoJoe);
370
371 for (int i = 0; i < findTModel.getTModelInfos().getTModelInfo().size(); i++) {
372 req.getEntityKey().add(
373 findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey());
374 }
375 OperationalInfos operationalInfo = uddiInquiryImpl.getOperationalInfo(req);
376
377 for (int i = 0; i < operationalInfo.getOperationalInfo().size(); i++) {
378 System.out.println(operationalInfo.getOperationalInfo().get(i).getEntityKey() + " on node "
379 + operationalInfo.getOperationalInfo().get(i).getNodeID() + " is owned by " + operationalInfo.getOperationalInfo().get(i).getAuthorizedName());
380 }
381 }
382
383 }