|
C:\uddi\inspireit\uddi\examples\FindServiceExample.java
|
1 package inspireit.uddi.examples;
2
3 import java.net.*;
4
5 import inspireit.uddi.base.*;
6 import inspireit.uddi.collections.*;
7 import inspireit.uddi.request.*;
8 import inspireit.uddi.response.*;
9 import inspireit.uddi.response.base.*;
10
11 /**
12 * This example shows how to find services.
13 *
14 * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a>
15 */
16 public class FindServiceExample {
17
18 public FindServiceExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception {
19 // first ensure that we have a saved BusinessEntity
20 SaveServiceExample saveService = new SaveServiceExample(queryURL, publishURL, securityURL, username, password);
21 BusinessKey businessKey = saveService.getBusinessKey();
22
23 // first define the appropriate UDDI profile
24 UDDIProfile profile = new UDDIProfile();
25 profile.setQueryURL(new URL(queryURL));
26
27 // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1
28 // profile.setVersion(UDDIConstants.UDDI_V2);
29 // profile.setVersion(UDDIConstants.UDDI_V3);
30
31 UDDIQuerier querier = UDDIQuerier.getQuerier(profile);
32
33 try {
34 ServiceList serviceList = querier.findService(businessKey, new Name("INSPIRE IT"));
35
36 if (serviceList == null) {
37 System.out.println("Not found.");
38 } else {
39 ServiceInfos serviceInfos = serviceList.getServiceInfos();
40 ServiceInfo serviceInfo[] = serviceInfos.toArray();
41
42 for(int i=0; i< serviceInfo.length; i++) {
43 ServiceInfo si = serviceInfo[i];
44 Names names = si.getNames();
45 Name name[] = names.toArray();
46 System.out.println("ServiceInfo #" + i + ": " + name[0]);
47 }
48 }
49 } catch(UDDIException e) {
50 e.printStackTrace();
51 }
52 }
53
54 public static void main(String args[]) throws Exception {
55 if ((args.length != 4) && (args.length != 5)) {
56 System.out.println("FindServiceExample usage: java FindServiceExample <queryURL> <publishURL> [<securityURL>] <username> <password>");
57 System.exit(0);
58 }
59
60 String queryURL = args[0];
61 String publishURL = args[1];
62 String securityURL = null;
63 String username = null;
64 String password = null;
65
66 if (args.length == 4) {
67 username = args[2];
68 password = args[3];
69 } else { // must be 5 ...
70 securityURL = args[2];
71 username = args[3];
72 password = args[4];
73 }
74
75 new FindServiceExample(queryURL, publishURL, securityURL, username, password);
76 return;
77 }
78 }