This project has retired. For details please refer to its
Attic page.
SimpleBrowseUDDIv2 xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.example.uddiv2.api.bridge.example;
18
19 import java.util.List;
20 import org.apache.juddi.api_v3.AccessPointType;
21 import org.apache.juddi.v3.client.UDDIConstants;
22 import org.apache.juddi.v3.client.config.UDDIClient;
23 import org.apache.juddi.v3.client.transport.Transport;
24 import org.uddi.api_v3.AuthToken;
25 import org.uddi.api_v3.BindingTemplates;
26 import org.uddi.api_v3.BusinessDetail;
27 import org.uddi.api_v3.BusinessInfos;
28 import org.uddi.api_v3.BusinessList;
29 import org.uddi.api_v3.BusinessService;
30 import org.uddi.api_v3.CategoryBag;
31 import org.uddi.api_v3.Contacts;
32 import org.uddi.api_v3.Description;
33 import org.uddi.api_v3.DiscardAuthToken;
34 import org.uddi.api_v3.FindBusiness;
35 import org.uddi.api_v3.GetAuthToken;
36 import org.uddi.api_v3.GetBusinessDetail;
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.ServiceDetail;
41 import org.uddi.api_v3.ServiceInfos;
42 import org.uddi.v3_service.UDDIInquiryPortType;
43 import org.uddi.v3_service.UDDISecurityPortType;
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public class SimpleBrowseUDDIv2 {
61
62 private static UDDISecurityPortType security = null;
63 private static UDDIInquiryPortType inquiry = null;
64
65
66
67
68 public SimpleBrowseUDDIv2() {
69 try {
70
71
72 UDDIClient client = new UDDIClient("META-INF/uddiv2-browse-uddi.xml");
73
74
75
76 Transport transport = client.getTransport("default");
77
78 security = transport.getUDDISecurityService();
79 inquiry = transport.getUDDIInquiryService();
80 } catch (Exception e) {
81 e.printStackTrace();
82 }
83 }
84
85
86
87
88
89
90 public static void main(String args[]) {
91
92 SimpleBrowseUDDIv2 sp = new SimpleBrowseUDDIv2();
93 sp.Browse(args);
94 }
95
96 public void Browse(String[] args) {
97 try {
98
99 String token = GetAuthKey("uddi", "uddi");
100 BusinessList findBusiness = GetBusinessList(token);
101 PrintBusinessInfo(findBusiness.getBusinessInfos());
102 PrintBusinessDetails(findBusiness.getBusinessInfos(), token);
103 PrintServiceDetailsByBusiness(findBusiness.getBusinessInfos(), token);
104
105 security.discardAuthToken(new DiscardAuthToken(token));
106
107 } catch (Exception e) {
108 e.printStackTrace();
109 }
110 }
111
112
113
114
115
116
117
118
119
120 private BusinessList GetBusinessList(String token) throws Exception {
121 FindBusiness fb = new FindBusiness();
122 fb.setAuthInfo(token);
123 org.uddi.api_v3.FindQualifiers fq = new org.uddi.api_v3.FindQualifiers();
124 fq.getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
125
126 fb.setFindQualifiers(fq);
127 Name searchname = new Name();
128 searchname.setValue(UDDIConstants.WILDCARD);
129 fb.getName().add(searchname);
130 BusinessList findBusiness = inquiry.findBusiness(fb);
131 return findBusiness;
132
133 }
134
135
136
137
138
139
140
141 private String CatBagToString(CategoryBag categoryBag) {
142 StringBuilder sb = new StringBuilder();
143 if (categoryBag == null) {
144 return "no data";
145 }
146 for (int i = 0; i < categoryBag.getKeyedReference().size(); i++) {
147 sb.append(KeyedReferenceToString(categoryBag.getKeyedReference().get(i)));
148 }
149 for (int i = 0; i < categoryBag.getKeyedReferenceGroup().size(); i++) {
150 sb.append("Key Ref Grp: TModelKey=");
151 for (int k = 0; k < categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().size(); k++) {
152 sb.append(KeyedReferenceToString(categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().get(k)));
153 }
154 }
155 return sb.toString();
156 }
157
158 private String KeyedReferenceToString(KeyedReference item) {
159 StringBuilder sb = new StringBuilder();
160 sb.append("Key Ref: Name=").
161 append(item.getKeyName()).
162 append(" Value=").
163 append(item.getKeyValue()).
164 append(" tModel=").
165 append(item.getTModelKey()).
166 append(System.getProperty("line.separator"));
167 return sb.toString();
168 }
169
170 private void PrintContacts(Contacts contacts) {
171 if (contacts == null) {
172 return;
173 }
174 for (int i = 0; i < contacts.getContact().size(); i++) {
175 System.out.println("Contact " + i + " type:" + contacts.getContact().get(i).getUseType());
176 for (int k = 0; k < contacts.getContact().get(i).getPersonName().size(); k++) {
177 System.out.println("Name: " + contacts.getContact().get(i).getPersonName().get(k).getValue());
178 }
179 for (int k = 0; k < contacts.getContact().get(i).getEmail().size(); k++) {
180 System.out.println("Email: " + contacts.getContact().get(i).getEmail().get(k).getValue());
181 }
182 for (int k = 0; k < contacts.getContact().get(i).getAddress().size(); k++) {
183 System.out.println("Address sort code " + contacts.getContact().get(i).getAddress().get(k).getSortCode());
184 System.out.println("Address use type " + contacts.getContact().get(i).getAddress().get(k).getUseType());
185 System.out.println("Address tmodel key " + contacts.getContact().get(i).getAddress().get(k).getTModelKey());
186 for (int x = 0; x < contacts.getContact().get(i).getAddress().get(k).getAddressLine().size(); x++) {
187 System.out.println("Address line value " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getValue());
188 System.out.println("Address line key name " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyName());
189 System.out.println("Address line key value " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyValue());
190 }
191 }
192 for (int k = 0; k < contacts.getContact().get(i).getDescription().size(); k++) {
193 System.out.println("Desc: " + contacts.getContact().get(i).getDescription().get(k).getValue());
194 }
195 for (int k = 0; k < contacts.getContact().get(i).getPhone().size(); k++) {
196 System.out.println("Phone: " + contacts.getContact().get(i).getPhone().get(k).getValue());
197 }
198 }
199
200 }
201
202 private void PrintServiceDetail(BusinessService get) {
203 if (get == null) {
204 return;
205 }
206 System.out.println("Name " + ListToString(get.getName()));
207 System.out.println("Desc " + ListToDescString(get.getDescription()));
208 System.out.println("Key " + (get.getServiceKey()));
209 System.out.println("Cat bag " + CatBagToString(get.getCategoryBag()));
210 if (!get.getSignature().isEmpty()) {
211 System.out.println("Item is digitally signed");
212 } else {
213 System.out.println("Item is not digitally signed");
214 }
215 PrintBindingTemplates(get.getBindingTemplates());
216 }
217
218
219
220
221
222
223
224 private void PrintBindingTemplates(BindingTemplates bindingTemplates) {
225 if (bindingTemplates == null) {
226 return;
227 }
228 for (int i = 0; i < bindingTemplates.getBindingTemplate().size(); i++) {
229 System.out.println("Binding Key: " + bindingTemplates.getBindingTemplate().get(i).getBindingKey());
230
231
232
233
234
235
236
237
238
239 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint() != null) {
240 System.out.println("Access Point: " + bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getValue() + " type " + bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType());
241 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType() != null) {
242 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType().equalsIgnoreCase(AccessPointType.END_POINT.toString())) {
243 System.out.println("Use this access point value as an invocation endpoint.");
244 }
245 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType().equalsIgnoreCase(AccessPointType.BINDING_TEMPLATE.toString())) {
246 System.out.println("Use this access point value as a reference to another binding template.");
247 }
248 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType().equalsIgnoreCase(AccessPointType.WSDL_DEPLOYMENT.toString())) {
249 System.out.println("Use this access point value as a URL to a WSDL document, which presumably will have a real access point defined.");
250 }
251 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType().equalsIgnoreCase(AccessPointType.HOSTING_REDIRECTOR.toString())) {
252 System.out.println("Use this access point value as an Inquiry URL of another UDDI registry, look up the same binding template there (usage varies).");
253 }
254 }
255 }
256
257 }
258 }
259
260 private enum AuthStyle {
261
262 HTTP_BASIC,
263 HTTP_DIGEST,
264 HTTP_NTLM,
265 UDDI_AUTH,
266 HTTP_CLIENT_CERT
267 }
268
269
270
271
272
273
274
275
276
277
278 private String GetAuthKey(String username, String password) {
279 try {
280
281 GetAuthToken getAuthTokenRoot = new GetAuthToken();
282 getAuthTokenRoot.setUserID(username);
283 getAuthTokenRoot.setCred(password);
284
285
286 AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
287 System.out.println(username + " AUTHTOKEN = (don't log auth tokens!");
288 return rootAuthToken.getAuthInfo();
289 } catch (Exception ex) {
290 System.out.println("Could not authenticate with the provided credentials " + ex.getMessage());
291 }
292 return null;
293 }
294
295 private void PrintBusinessInfo(BusinessInfos businessInfos) {
296 if (businessInfos == null) {
297 System.out.println("No data returned");
298 } else {
299 for (int i = 0; i < businessInfos.getBusinessInfo().size(); i++) {
300 System.out.println("===============================================");
301 System.out.println("Business Key: " + businessInfos.getBusinessInfo().get(i).getBusinessKey());
302 System.out.println("Name: " + ListToString(businessInfos.getBusinessInfo().get(i).getName()));
303
304 System.out.println("Description: " + ListToDescString(businessInfos.getBusinessInfo().get(i).getDescription()));
305 System.out.println("Services:");
306 PrintServiceInfo(businessInfos.getBusinessInfo().get(i).getServiceInfos());
307 }
308 }
309 }
310
311 private String ListToString(List<Name> name) {
312 StringBuilder sb = new StringBuilder();
313 for (int i = 0; i < name.size(); i++) {
314 sb.append(name.get(i).getValue()).append(" ");
315 }
316 return sb.toString();
317 }
318
319 private String ListToDescString(List<Description> name) {
320 StringBuilder sb = new StringBuilder();
321 for (int i = 0; i < name.size(); i++) {
322 sb.append(name.get(i).getValue()).append(" ");
323 }
324 return sb.toString();
325 }
326
327 private void PrintServiceInfo(ServiceInfos serviceInfos) {
328 for (int i = 0; i < serviceInfos.getServiceInfo().size(); i++) {
329 System.out.println("-------------------------------------------");
330 System.out.println("Service Key: " + serviceInfos.getServiceInfo().get(i).getServiceKey());
331 System.out.println("Owning Business Key: " + serviceInfos.getServiceInfo().get(i).getBusinessKey());
332 System.out.println("Name: " + ListToString(serviceInfos.getServiceInfo().get(i).getName()));
333 }
334 }
335
336 private void PrintBusinessDetails(BusinessInfos businessInfos, String token) throws Exception {
337 GetBusinessDetail gbd = new GetBusinessDetail();
338 gbd.setAuthInfo(token);
339 for (int i = 0; i < businessInfos.getBusinessInfo().size(); i++) {
340 gbd.getBusinessKey().add(businessInfos.getBusinessInfo().get(i).getBusinessKey());
341 }
342 BusinessDetail businessDetail = inquiry.getBusinessDetail(gbd);
343 for (int i = 0; i < businessDetail.getBusinessEntity().size(); i++) {
344 System.out.println("Business Detail - key: " + businessDetail.getBusinessEntity().get(i).getBusinessKey());
345 System.out.println("Name: " + ListToString(businessDetail.getBusinessEntity().get(i).getName()));
346 System.out.println("CategoryBag: " + CatBagToString(businessDetail.getBusinessEntity().get(i).getCategoryBag()));
347 PrintContacts(businessDetail.getBusinessEntity().get(i).getContacts());
348 }
349 }
350
351 private void PrintServiceDetailsByBusiness(BusinessInfos businessInfos, String token) throws Exception {
352 for (int i = 0; i < businessInfos.getBusinessInfo().size(); i++) {
353 GetServiceDetail gsd = new GetServiceDetail();
354 for (int k = 0; k < businessInfos.getBusinessInfo().get(i).getServiceInfos().getServiceInfo().size(); k++) {
355 gsd.getServiceKey().add(businessInfos.getBusinessInfo().get(i).getServiceInfos().getServiceInfo().get(k).getServiceKey());
356 }
357 gsd.setAuthInfo(token);
358 System.out.println("Fetching data for business " + businessInfos.getBusinessInfo().get(i).getBusinessKey());
359 ServiceDetail serviceDetail = inquiry.getServiceDetail(gsd);
360 for (int k = 0; k < serviceDetail.getBusinessService().size(); k++) {
361 PrintServiceDetail(serviceDetail.getBusinessService().get(k));
362 }
363 System.out.println("................");
364
365 }
366 }
367 }