|
C:\uddi\inspireit\uddi\examples\DeleteBusinessExample.java
|
1 package inspireit.uddi.examples;
2
3 import java.net.*;
4
5 import inspireit.uddi.request.*;
6 import inspireit.uddi.response.*;
7 import inspireit.uddi.response.base.*;
8 import inspireit.uddi.base.*;
9 import inspireit.uddi.collections.*;
10
11 /**
12 * This example shows how to delete a business entity. You will have to open an
13 * account at one of the official UDDI registries if you don't have access to a
14 * local UDDI registry. For example, you can use the beta registry of IBM
15 * located at http://uddi.ibm.com/beta/registry.html.<p>
16 *
17 * The example first saves a business entity via the SaveBusinessExample
18 * example. If the size of your account is limited, you will have to make a
19 * clean-up first, for example via the Web interface of the on-line registry.
20 *
21 * @author Bertrand Fontaine, <a href="http://www.inspireit.biz" target="INSPIREIT">INSPIRE IT</a>
22 */
23 public class DeleteBusinessExample {
24
25 public DeleteBusinessExample(String queryURL, String publishURL, String securityURL, String username, String password) throws Exception {
26 // first call the saveBusiness example to be sure that at least one
27 // BusinessEntity is stored in the UDDI registry
28 SaveBusinessExample saveBusiness = new SaveBusinessExample(queryURL, publishURL, securityURL, username, password);
29 BusinessKey businessKey = saveBusiness.getBusinessKey();
30
31 // set up an appropriate HTTPS protocol handler (requires the SUN JAAS
32 // 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 try {
51 // get an appropriate publisher and querier
52 UDDIPublisher publisher = UDDIPublisher.getPublisher(profile);
53
54 DispositionReport dispositionReport = publisher.deleteBusiness(businessKey);
55 Results results = dispositionReport.getResults();
56 Result result[] = results.toArray();
57
58 if (result[0].getErrNo() == Result.E_success) {
59 System.out.println("Business successfully deleted");
60 } else {
61 System.out.println("Errno : " + result[0].getErrNo() +
62 "\n KeyType : " + result[0].getKeyType() +
63 "\n ErrInfo : " + result[0].getErrInfo());
64 }
65 } catch(UDDIException e) {
66 System.out.println("An error has occured. More information follows.");
67 DispositionReport dispositionReport = e.getDispositionReport();
68
69 if (dispositionReport != null) {
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 } else {
79 System.out.println(e.getMessage());
80 }
81 }
82 }
83
84 public static void main(String args[]) throws Exception {
85 if ((args.length != 4) && (args.length != 5)) {
86 System.out.println("DeleteBusinessExample usage: java DeleteBusinessExample <queryURL> <publishURL> [<securityURL>] <username> <password>");
87 System.exit(0);
88 }
89
90 String queryURL = args[0];
91 String publishURL = args[1];
92 String securityURL = null;
93 String username = null;
94 String password = null;
95
96 if (args.length == 4) {
97 username = args[2];
98 password = args[3];
99 } else { // must be 5 ...
100 securityURL = args[2];
101 username = args[3];
102 password = args[4];
103 }
104
105 new DeleteBusinessExample(queryURL, publishURL, securityURL, username, password);
106 return;
107 }
108 }