1 9 10 import java.util.Properties ; 11 import java.util.Vector ; 12 13 import org.uddi4j.UDDIException; 14 import org.uddi4j.client.UDDIProxy; 15 import org.uddi4j.datatype.Name; 16 import org.uddi4j.datatype.business.BusinessEntity; 17 import org.uddi4j.datatype.service.BusinessService; 18 import org.uddi4j.response.AuthToken; 19 import org.uddi4j.response.BusinessDetail; 20 import org.uddi4j.response.DispositionReport; 21 import org.uddi4j.response.Result; 22 import org.uddi4j.response.ServiceDetail; 23 import org.uddi4j.response.ServiceInfo; 24 import org.uddi4j.response.ServiceList; 25 import org.uddi4j.util.FindQualifier; 26 import org.uddi4j.util.FindQualifiers; 27 28 45 public class BusinessServiceExample 46 { 47 48 Properties config = null; 49 50 public static void main (String args[]) 51 { 52 BusinessServiceExample app = new BusinessServiceExample(); 53 System.out.println("\n*********** Running BusinessServiceExample ***********"); 54 app.run(); 55 System.exit(0); 56 } 57 58 public void run() 59 { 60 config = Configurator.load(); 62 63 UDDIProxy proxy = new UDDIProxy(); 65 66 try 67 { 68 proxy.setInquiryURL(config.getProperty("inquiryURL")); 70 proxy.setPublishURL(config.getProperty("publishURL")); 71 72 System.out.println("\nGet authtoken"); 74 75 AuthToken token = proxy.get_authToken(config.getProperty("userid"), 77 config.getProperty("password")); 78 79 System.out.println("Returned authToken:" + token.getAuthInfoString()); 80 81 System.out.println("\nSave '" + config.getProperty("serviceName") + "'"); 82 83 85 Vector entities = new Vector (); 86 87 BusinessEntity be = new BusinessEntity("", config.getProperty("businessName")); 91 entities.addElement(be); 92 93 BusinessDetail bd = proxy.save_business(token.getAuthInfoString(),entities); 95 96 Vector businessEntities = bd.getBusinessEntityVector(); 99 BusinessEntity returnedBusinessEntity = (BusinessEntity)(businessEntities.elementAt(0)); 100 String businessKey = returnedBusinessEntity.getBusinessKey(); 101 102 BusinessService businessService = new BusinessService(""); 106 businessService.setDefaultNameString(config.getProperty("serviceName"),null); 107 businessService.setBusinessKey(businessKey); 108 Vector services = new Vector (); 109 services.addElement(businessService); 110 111 ServiceDetail serviceDetail = proxy.save_service(token.getAuthInfoString(),services); 113 114 Vector businessServices = serviceDetail.getBusinessServiceVector(); 117 BusinessService businessServiceReturned = (BusinessService)(businessServices.elementAt(0)); 118 String serviceKey = businessServiceReturned.getServiceKey(); 119 System.out.println("The saved Service : "+ businessServiceReturned.getDefaultNameString()); 120 System.out.println("The ServiceKey : "+ serviceKey); 121 122 System.out.println("\nFinding Service saved in first step"); 123 124 Vector names = new Vector (); 126 names.add(new Name(config.getProperty("serviceName"))); 127 128 FindQualifiers findQualifiers = new FindQualifiers(); 130 Vector qualifier = new Vector (); 131 qualifier.add(new FindQualifier("exactNameMatch")); 132 findQualifiers.setFindQualifierVector(qualifier); 133 134 ServiceList serviceList = proxy.find_service(businessKey, names, null,null,findQualifiers,5); 137 138 Vector serviceInfoVector = serviceList.getServiceInfos().getServiceInfoVector(); 140 for( int i = 0; i < serviceInfoVector.size(); i++ ) 141 { 142 ServiceInfo serviceInfo = (ServiceInfo)serviceInfoVector.elementAt(i); 143 System.out.println("Name of Service : " + serviceInfo.getDefaultNameString()); 145 System.out.println("Service key : " + serviceInfo.getServiceKey()); 146 } 147 148 System.out.println("\nDeleting the saved service"); 149 System.out.println("Name of Service : " + 153 businessServiceReturned.getDefaultNameString()); 154 System.out.println("Service key : " + 155 businessServiceReturned.getServiceKey()); 156 157 DispositionReport dr = proxy.delete_service ( 159 token.getAuthInfoString(), 160 businessServiceReturned.getServiceKey()); 161 162 if( dr.success() ) 163 { 164 System.out.println("Service successfully deleted"); 165 } 166 else 167 { 168 System.out.println(" Error during deletion of Service\n"+ 169 "\n operator:" + dr.getOperator() + 170 "\n generic:" + dr.getGeneric() ); 171 172 Vector results = dr.getResultVector(); 173 for( int i=0; i<results.size(); i++ ) 174 { 175 Result r = (Result)results.elementAt(i); 176 System.out.println("\n errno:" + r.getErrno() ); 177 if( r.getErrInfo()!=null ) 178 { 179 System.out.println("\n errCode:" + r.getErrInfo().getErrCode() + 180 "\n errInfoText:" + r.getErrInfo().getText()); 181 } 182 } 183 } 184 185 186 System.out.println("\nCleaning the Data Structures added/saved from registry"); 189 { 190 DispositionReport dr1 = proxy.delete_business(token.getAuthInfoString(), 192 businessKey); 193 194 if( dr1.success() ) 195 { 196 System.out.println("Registry successfully cleaned"); 197 } 198 else 199 { 200 System.out.println(" Error during deletion of Business\n"+ 201 "\n operator:" + dr1.getOperator() + 202 "\n generic:" + dr1.getGeneric() ); 203 204 Vector results = dr1.getResultVector(); 205 for( int i=0; i<results.size(); i++ ) 206 { 207 Result r = (Result)results.elementAt(i); 208 System.out.println("\n errno:" + r.getErrno() ); 209 if( r.getErrInfo()!=null ) 210 { 211 System.out.println("\n errCode:" + r.getErrInfo().getErrCode() + 212 "\n errInfoText:" + r.getErrInfo().getText()); 213 } 214 } 215 } 216 } 217 } 218 catch( UDDIException e ) 220 { 221 DispositionReport dr = e.getDispositionReport(); 222 if( dr!=null ) 223 { 224 System.out.println("UDDIException faultCode:" + e.getFaultCode() + 225 "\n operator:" + dr.getOperator() + 226 "\n generic:" + dr.getGeneric() ); 227 228 Vector results = dr.getResultVector(); 229 for( int i=0; i<results.size(); i++ ) 230 { 231 Result r = (Result)results.elementAt(i); 232 System.out.println("\n errno:" + r.getErrno() ); 233 if( r.getErrInfo()!=null ) 234 { 235 System.out.println("\n errCode:" + r.getErrInfo().getErrCode() + 236 "\n errInfoText:" + r.getErrInfo().getText()); 237 } 238 } 239 } 240 e.printStackTrace(); 241 } 242 catch( Exception e ) 244 { 245 e.printStackTrace(); 246 } 247 } 248 } 249 | Popular Tags |