|
C:\uddi\inspireit\uddi\examples\DeleteTModelExample.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 delete a tModel. You will have to open an account
13 * at one of the official UDDI registries if you don't have access to a local
14 * UDDI 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 and a tModel via the
18 * SaveTModelExample example. If the size of your account is limited, you will
19 * have to make a clean-up first, for example via the Web interface of the
20 * on-line registry.
21 *
22 * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a>
23 */
24 public class DeleteTModelExample {
25
26 public DeleteTModelExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception {
27 // first call the saveTModel example to be sure that at least one
28 // TModel is stored in the UDDI registry
29 SaveTModelExample saveTModel = new SaveTModelExample(queryURL, publishURL, securityURL, username, password);
30 TModelKey tModelKey = saveTModel.getTModelKey();
31
32 // set up an appropriate HTTPS protocol handler (requires the SUN JAAS library in classpath)
33 System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
34 java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
35
36 // configure a UDDI profile to connect to a UDDI registry
37 UDDIProfile profile = new UDDIProfile();
38 profile.setPublishURL(new URL(publishURL));
39
40 if (securityURL != null) {
41 profile.setSecurityURL(new URL(securityURL));
42 }
43
44 profile.setUsername(username);
45 profile.setPassword(password);
46
47 // uncomment one of the following lines to use UDDI V2 or V3 messaging instead of the default V1
48 // profile.setVersion(UDDIConstants.UDDI_V2);
49 // profile.setVersion(UDDIConstants.UDDI_V3);
50
51 try {
52 // get an appropriate publisher
53 UDDIPublisher publisher = UDDIPublisher.getPublisher(profile);
54
55 DispositionReport dispositionReport = publisher.deleteTModel(tModelKey);
56 Results results = dispositionReport.getResults();
57 Result result[] = results.toArray();
58
59 if (result[0].getErrNo() == Result.E_success) {
60 System.out.println("TModel successfully deleted");
61 } else {
62 System.out.println("Errno : " + result[0].getErrNo() +
63 "\n KeyType : " + result[0].getKeyType() +
64 "\n ErrInfo : " + result[0].getErrInfo());
65 }
66 } catch(UDDIException e) {
67 System.out.println("An error has occured. More information follows.");
68
69 DispositionReport dispositionReport = e.getDispositionReport();
70 Results results = dispositionReport.getResults();
71 Result result[] = results.toArray();
72
73 for(int i=0; i< result.length; i++) {
74 System.out.println("Errno : " + result[i].getErrNo() +
75 "\n KeyType : " + result[i].getKeyType() +
76 "\n ErrInfo : " + result[i].getErrInfo());
77 }
78 }
79 }
80
81 public static void main(String args[]) throws Exception {
82 if ((args.length != 4) && (args.length != 5)) {
83 System.out.println("DeleteTModelExample usage: java DeleteTModelExample <queryURL> <publishURL> [<securityURL>] <username> <password>");
84 System.exit(0);
85 }
86
87 String queryURL = args[0];
88 String publishURL = args[1];
89 String securityURL = null;
90 String username = null;
91 String password = null;
92
93 if (args.length == 4) {
94 username = args[2];
95 password = args[3];
96 } else { // must be 5 ...
97 securityURL = args[2];
98 username = args[3];
99 password = args[4];
100 }
101
102 new DeleteTModelExample(queryURL, publishURL, securityURL, username, password);
103 return;
104 }
105 }