1
2
3
4
5
6
7 package org.apache.jetspeed.webservices.util;
8
9 import java.io.Serializable;
10
11 import org.uddi4j.UDDIException;
12 import org.uddi4j.transport.TransportException;
13 import org.uddi4j.client.UDDIProxy;
14 import org.uddi4j.response.*;
15
16
17 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
18 import org.apache.jetspeed.services.logging.JetspeedLogger;
19
20 /***
21 * UDDIAccessBean provides a command bean interface
22 * to UDDI registry services.
23 * Please note that currently only inquiry tasks are supported. I
24 * hope to add other task types soon.
25 * @author Scott A. Roehrig@IBM Corporation
26 * @version 1.0
27 */
28 public class UDDIAccessBean extends Object implements Serializable
29 {
30 /***
31 * Static initialization of the logger for this class
32 */
33 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(UDDIAccessBean.class.getName());
34
35
36 private transient UDDIProxy proxy;
37 private String queryURL;
38
39 /*** setter method for queryURL */
40 public void setQueryURL(String queryURL) {
41 this.queryURL = queryURL;
42 }
43
44 /*** getter method for queryURL */
45 public String getQueryURL() {
46 return queryURL;
47 }
48
49 /*** creates new UDDIAccessBean */
50 public UDDIAccessBean() {
51 proxy = new UDDIProxy();
52 queryURL = "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi";
53 }
54
55 /*** creates new UDDIAccessBean with provided queryURL */
56 public UDDIAccessBean(String queryURL) {
57 proxy = new UDDIProxy();
58 this.queryURL = queryURL;
59 }
60
61 /*** performs business lookup against registry */
62 public java.util.List queryBusiness(String name) {
63
64 java.util.List businessList = new java.util.Vector();
65
66 try {
67 proxy.setInquiryURL(queryURL);
68 BusinessList results = proxy.find_business(name, null, 0);
69 businessList = results.getBusinessInfos().getBusinessInfoVector();
70 if (logger.isDebugEnabled()) {
71 java.util.ListIterator iterator = businessList.listIterator();
72 while (iterator.hasNext() == true) {
73 org.uddi4j.response.BusinessInfo business = (org.uddi4j.response.BusinessInfo)iterator.next();
74 logger.debug(business.getDefaultDescriptionString());
75 }
76 }
77 }
78 catch (java.net.MalformedURLException exception) {
79 exception.printStackTrace();
80 if (logger.isDebugEnabled()) {
81 logger.error(exception.getMessage(), exception);
82 }
83 }
84 catch (UDDIException exception) {
85 exception.printStackTrace();
86 if (logger.isDebugEnabled()) {
87 logger.error(exception.getMessage(), exception);
88 }
89 }
90 catch (TransportException exception) {
91 exception.printStackTrace();
92 if (logger.isDebugEnabled()) {
93 logger.error(exception.getMessage(), exception);
94 }
95 }
96
97 return businessList;
98 }
99
100 /*** returns businessKey object associated with provided business */
101 public String getBusinessKey(String businessName) {
102 String businessKey = null;
103
104 java.util.List businessList = new java.util.Vector();
105
106 try {
107 proxy.setInquiryURL(queryURL);
108 BusinessList results = proxy.find_business(businessName, null, 0);
109 businessList = results.getBusinessInfos().getBusinessInfoVector();
110
111 java.util.ListIterator iterator = businessList.listIterator();
112 while (iterator.hasNext() == true) {
113 BusinessInfo business = (BusinessInfo)iterator.next();
114 if (business.getNameString().equals(businessName)) {
115 businessKey = business.getBusinessKey();
116 if (logger.isDebugEnabled()) {
117 logger.debug(business.getNameString()+" has associated key "+businessKey);
118 }
119 }
120 }
121 }
122 catch (java.net.MalformedURLException exception) {
123 exception.printStackTrace();
124 if (logger.isDebugEnabled()) {
125 logger.error(exception.getMessage(), exception);
126 }
127 }
128 catch (UDDIException exception) {
129 exception.printStackTrace();
130 if (logger.isDebugEnabled()) {
131 logger.error(exception.getMessage(), exception);
132 }
133 }
134 catch (TransportException exception) {
135 exception.printStackTrace();
136 if (logger.isDebugEnabled()) {
137 logger.error(exception.getMessage(), exception);
138 }
139 }
140
141 return businessKey;
142 }
143
144 /*** performs service lookup against registry */
145 public java.util.List queryService(String businessKey, String description) {
146
147 java.util.List serviceList = new java.util.Vector();
148
149 try {
150 proxy.setInquiryURL(queryURL);
151 ServiceList results = proxy.find_service(businessKey, description, null, 0);
152 serviceList = results.getServiceInfos().getServiceInfoVector();
153 if (logger.isDebugEnabled()) {
154 java.util.ListIterator iterator = serviceList.listIterator();
155 while (iterator.hasNext() == true) {
156 org.uddi4j.response.ServiceInfo service = (org.uddi4j.response.ServiceInfo)iterator.next();
157 logger.debug(service.getNameString());
158 }
159 }
160 }
161 catch (java.net.MalformedURLException exception) {
162 exception.printStackTrace();
163 if (logger.isDebugEnabled()) {
164 logger.error(exception.getMessage(), exception);
165 }
166 }
167 catch (UDDIException exception) {
168 exception.printStackTrace();
169 if (logger.isDebugEnabled()) {
170 logger.error(exception.getMessage(), exception);
171 }
172 }
173 catch (TransportException exception) {
174 exception.printStackTrace();
175 if (logger.isDebugEnabled()) {
176 logger.error(exception.getMessage(), exception);
177 }
178 }
179
180 return serviceList;
181 }
182
183 /*** returns serviceKey associated with provided service */
184 public String getServiceKey(String businessKey, String serviceName) {
185 String serviceKey = null;
186
187 java.util.List serviceList = new java.util.Vector();
188
189 try {
190 proxy.setInquiryURL(queryURL);
191 ServiceList results = proxy.find_service(businessKey, serviceName, null, 0);
192 serviceList = results.getServiceInfos().getServiceInfoVector();
193
194 java.util.ListIterator iterator = serviceList.listIterator();
195 while (iterator.hasNext() == true) {
196 ServiceInfo service = (ServiceInfo)iterator.next();
197 if (service.getNameString().equals(serviceName)) {
198 serviceKey = service.getServiceKey();
199 if (logger.isDebugEnabled()) {
200 logger.debug(service.getNameString()+" has associated key "+serviceKey);
201 }
202 }
203 }
204 }
205 catch (java.net.MalformedURLException exception) {
206 exception.printStackTrace();
207 if (logger.isDebugEnabled()) {
208 logger.error(exception.getMessage(), exception);
209 }
210 }
211 catch (UDDIException exception) {
212 exception.printStackTrace();
213 if (logger.isDebugEnabled()) {
214 logger.error(exception.getMessage(), exception);
215 }
216 }
217 catch (TransportException exception) {
218 exception.printStackTrace();
219 if (logger.isDebugEnabled()) {
220 logger.error(exception.getMessage(), exception);
221 }
222 }
223
224 return serviceKey;
225 }
226
227 /*** called before object is garbage collected */
228 public void finalize() {
229 proxy = null;
230 queryURL = null;
231 }
232
233 }