|
C:\uddi\inspireit\uddi\examples\FindBindingExample.java
|
1 package inspireit.uddi.examples;
2
3 import java.net.*;
4
5 import inspireit.uddi.*;
6 import inspireit.uddi.base.*;
7 import inspireit.uddi.collections.*;
8 import inspireit.uddi.request.*;
9 import inspireit.uddi.response.*;
10
11 /**
12 * This example shows how to find a binding. You will have to open an account at
13 * one of the official UDDI registries if you don't have access to a local UDDI
14 * registry. For example, you can use the beta registry of IBM located at
15 * http://uddi.ibm.com/beta/registry.html.<p>
16 *
17 * The example first saves a business entity, a service, a tModel and a
18 * bindingTemplate via the SaveBindingExample example. If the size of your
19 * account is limited, you will have to make a clean-up first, for example via
20 * the Web interface of the on-line registry.
21 *
22 * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a>
23 */
24 public class FindBindingExample {
25
26 public FindBindingExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception {
27 // first ensure that we have a saved BindingTemplate
28 SaveBindingExample saveBinding = new SaveBindingExample(queryURL, publishURL, securityURL, username, password);
29 ServiceKey serviceKey = saveBinding.getServiceKey();
30 BindingKey bindingKey = saveBinding.getBindingKey();
31 TModelKey tModelKey = saveBinding.getTModelKey();
32
33 // define the appropriate UDDI profile
34 UDDIProfile profile = new UDDIProfile();
35 profile.setQueryURL(new URL(queryURL));
36
37 // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1
38 // profile.setVersion(UDDIConstants.UDDI_V2);
39 // profile.setVersion(UDDIConstants.UDDI_V3);
40 UDDIQuerier querier = UDDIQuerier.getQuerier(profile);
41
42 try {
43 TModelBag tModelBag = new TModelBag(tModelKey);
44 BindingDetail bindingDetail = querier.findBinding(serviceKey, tModelBag);
45 BindingTemplates bindingTemplates = bindingDetail.getBindingTemplates();
46 BindingTemplate bindingTemplate[] = bindingTemplates.toArray();
47
48 for(int i=0; i< bindingTemplate.length; i++) {
49 BindingTemplate bt = bindingTemplate[i];
50 System.out.println("BindingTemplate access point #" + i + ": " + bt.getAccessPoint());
51 }
52 } catch(UDDIException e) {
53 e.printStackTrace();
54 }
55 }
56
57 public static void main(String args[]) throws Exception {
58 if ((args.length != 4) && (args.length != 5)) {
59 System.out.println("FindBindingExample usage: java FindBindingExample <queryURL> <publishURL> [<securityURL>] <username> <password>");
60 System.exit(0);
61 }
62
63 String queryURL = args[0];
64 String publishURL = args[1];
65 String securityURL = null;
66 String username = null;
67 String password = null;
68
69 if (args.length == 4) {
70 username = args[2];
71 password = args[3];
72 } else { // must be 5 ...
73 securityURL = args[2];
74 username = args[3];
75 password = args[4];
76 }
77
78 new FindBindingExample(queryURL, publishURL, securityURL, username, password);
79 return;
80 }
81 }