1 16 package org.apache.juddi.proxy; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.net.MalformedURLException ; 21 import java.net.URL ; 22 import java.util.Properties ; 23 24 import org.apache.juddi.AbstractRegistry; 25 import org.apache.juddi.IRegistry; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.request.Admin; 28 import org.apache.juddi.datatype.request.AuthInfo; 29 import org.apache.juddi.datatype.request.Inquiry; 30 import org.apache.juddi.datatype.request.Publish; 31 import org.apache.juddi.datatype.request.SecurityPolicy; 32 import org.apache.juddi.datatype.response.AuthToken; 33 import org.apache.juddi.error.RegistryException; 34 import org.apache.juddi.handler.HandlerMaker; 35 import org.apache.juddi.handler.IHandler; 36 import org.apache.juddi.util.Loader; 37 import org.apache.juddi.util.xml.XMLUtils; 38 39 import org.w3c.dom.Document ; 40 import org.w3c.dom.Element ; 41 42 48 public class RegistryProxy extends AbstractRegistry 49 { 50 private static HandlerMaker maker = HandlerMaker.getInstance(); 52 53 private static final String PROPFILE_NAME = "juddi.properties"; 55 56 public static final String INQUIRY_ENDPOINT_PROPERTY_NAME = "juddi.proxy.inquiryURL"; 58 public static final String PUBLISH_ENDPOINT_PROPERTY_NAME = "juddi.proxy.publishURL"; 59 public static final String ADMIN_ENDPOINT_PROPERTY_NAME = "juddi.proxy.adminURL"; 60 public static final String TRANSPORT_CLASS_PROPERTY_NAME = "juddi.proxy.transportClass"; 61 public static final String SECURITY_PROVIDER_PROPERTY_NAME = "juddi.proxy.securityProvider"; 62 public static final String PROTOCOL_HANDLER_PROPERTY_NAME = "juddi.proxy.protocolHandler"; 63 public static final String UDDI_VERSION_PROPERTY_NAME = "juddi.proxy.uddiVersion"; 64 public static final String UDDI_NAMESPACE_PROPERTY_NAME = "juddi.proxy.uddiNamespace"; 65 66 public static final String DEFAULT_INQUIRY_ENDPOINT = "http://localhost/juddi/inquiry"; 68 public static final String DEFAULT_PUBLISH_ENDPOINT = "http://localhost/juddi/publish"; 69 public static final String DEFAULT_ADMIN_ENDPOINT = "http://localhost/juddi/admin"; 70 public static final String DEFAULT_TRANSPORT_CLASS = "org.apache.juddi.proxy.AxisTransport"; 71 public static final String DEFAULT_SECURITY_PROVIDER = "com.sun.net.ssl.internal.ssl.Provider"; 72 public static final String DEFAULT_PROTOCOL_HANDLER = "com.sun.net.ssl.internal.www.protocol"; 73 public static final String DEFAULT_UDDI_VERSION = "2.0"; 74 public static final String DEFAULT_UDDI_NAMESPACE = "urn:uddi-org:api_v2"; 75 76 private URL inquiryURL; 78 private URL publishURL; 79 private URL adminURL; 80 private Transport transport; 81 private String securityProvider; 82 private String protocolHandler; 83 private String uddiVersion; 84 private String uddiNamespace; 85 86 93 public RegistryProxy() 94 { 95 super(); 96 97 Properties props = new Properties (); 101 102 try { 103 InputStream stream = Loader.getResourceAsStream(PROPFILE_NAME); 104 if (stream != null) 105 props.load(stream); 106 } 107 catch (IOException ioex) { 108 ioex.printStackTrace(); 109 } 110 111 this.init(props); 112 } 113 114 121 public RegistryProxy(Properties props) 122 { 123 super(); 124 125 this.init(props); 126 } 127 128 131 private void init(Properties props) 132 { 133 if (props == null) 136 props = new Properties (); 137 138 try 140 { 141 String iURL = props.getProperty(INQUIRY_ENDPOINT_PROPERTY_NAME); 142 if (iURL != null) 143 this.setInquiryURL(new URL (iURL)); 144 else 145 this.setInquiryURL(new URL (DEFAULT_INQUIRY_ENDPOINT)); 146 147 String pURL = props.getProperty(PUBLISH_ENDPOINT_PROPERTY_NAME); 148 if (pURL != null) 149 this.setPublishURL(new URL (pURL)); 150 else 151 this.setPublishURL(new URL (DEFAULT_PUBLISH_ENDPOINT)); 152 153 String aURL = props.getProperty(ADMIN_ENDPOINT_PROPERTY_NAME); 154 if (aURL != null) 155 this.setAdminURL(new URL (aURL)); 156 else 157 this.setAdminURL(new URL (DEFAULT_ADMIN_ENDPOINT)); 158 } 159 catch(MalformedURLException muex) { 160 muex.printStackTrace(); 161 } 162 163 String secProvider = props.getProperty(SECURITY_PROVIDER_PROPERTY_NAME); 164 if (secProvider != null) 165 this.setSecurityProvider(secProvider); 166 else 167 this.setSecurityProvider(DEFAULT_SECURITY_PROVIDER); 168 169 String protoHandler = props.getProperty(PROTOCOL_HANDLER_PROPERTY_NAME); 170 if (protoHandler != null) 171 this.setProtocolHandler(protoHandler); 172 else 173 this.setProtocolHandler(DEFAULT_PROTOCOL_HANDLER); 174 175 String uddiVer = props.getProperty(UDDI_VERSION_PROPERTY_NAME); 176 if (uddiVer != null) 177 this.setUddiVersion(uddiVer); 178 else 179 this.setUddiVersion(DEFAULT_UDDI_VERSION); 180 181 String uddiNS = props.getProperty(UDDI_NAMESPACE_PROPERTY_NAME); 182 if (uddiNS != null) 183 this.setUddiNamespace(uddiNS); 184 else 185 this.setUddiNamespace(DEFAULT_UDDI_NAMESPACE); 186 187 String transClass = props.getProperty(TRANSPORT_CLASS_PROPERTY_NAME); 188 if (transClass != null) 189 this.setTransport(this.getTransport(transClass)); 190 else 191 this.setTransport(this.getTransport(DEFAULT_TRANSPORT_CLASS)); 192 } 193 194 197 public URL getAdminURL() 198 { 199 return this.adminURL; 200 } 201 202 205 public void setAdminURL(URL url) 206 { 207 this.adminURL = url; 208 } 209 210 213 public URL getInquiryURL() 214 { 215 return this.inquiryURL; 216 } 217 218 221 public void setInquiryURL(URL url) 222 { 223 this.inquiryURL = url; 224 } 225 226 229 public URL getPublishURL() 230 { 231 return this.publishURL; 232 } 233 234 237 public void setPublishURL(URL url) 238 { 239 this.publishURL = url; 240 } 241 242 245 public Transport getTransport() 246 { 247 return transport; 248 } 249 250 253 public void setTransport(Transport transport) 254 { 255 this.transport = transport; 256 } 257 258 261 public String getProtocolHandler() 262 { 263 return this.protocolHandler; 264 } 265 266 269 public void setProtocolHandler(String protoHandler) 270 { 271 this.protocolHandler = protoHandler; 272 } 273 274 277 public String getSecurityProvider() 278 { 279 return this.securityProvider; 280 } 281 282 285 public void setSecurityProvider(String secProvider) 286 { 287 this.securityProvider = secProvider; 288 } 289 290 293 public String getUddiNamespace() 294 { 295 return this.uddiNamespace; 296 } 297 298 301 public void setUddiNamespace(String uddiNS) 302 { 303 this.uddiNamespace = uddiNS; 304 } 305 306 309 public String getUddiVersion() 310 { 311 return this.uddiVersion; 312 } 313 314 317 public void setUddiVersion(String uddiVer) 318 { 319 this.uddiVersion = uddiVer; 320 } 321 322 325 public RegistryObject execute(RegistryObject uddiRequest) 326 throws RegistryException 327 { 328 332 URL endPointURL = null; 333 if (uddiRequest instanceof Inquiry) 334 endPointURL = this.getInquiryURL(); 335 else if (uddiRequest instanceof Publish || uddiRequest instanceof SecurityPolicy) 336 endPointURL = this.getPublishURL(); 337 else if (uddiRequest instanceof Admin) 338 endPointURL = this.getAdminURL(); 339 else 340 throw new RegistryException("Unsupported Request: The " + 341 "request '"+uddiRequest.getClass().getName()+"' is an " + 342 "invalid or unknown request type."); 343 344 348 Document document = XMLUtils.createDocument(); 349 Element temp = document.createElement("temp"); 350 351 357 String requestName = uddiRequest.getClass().getName(); 358 IHandler requestHandler = maker.lookup(requestName); 359 requestHandler.marshal(uddiRequest,temp); 360 Element request = (Element )temp.getFirstChild(); 361 362 request.setAttribute("generic",this.getUddiVersion()); 363 request.setAttribute("xmlns",this.getUddiNamespace()); 364 365 368 Element response = transport.send(request,endPointURL); 369 370 373 String responseName = response.getLocalName(); 374 if (responseName == null) 375 { 376 throw new RegistryException("Unsupported response " + 377 "from registry. A value was not present."); 378 } 379 380 384 IHandler handler = maker.lookup(responseName.toLowerCase()); 385 if (handler == null) 386 { 387 throw new RegistryException("Unsupported response " + 388 "from registry. Response type '" + responseName + 389 "' is unknown."); 390 } 391 392 396 RegistryObject uddiResponse = handler.unmarshal(response); 397 398 402 if (uddiResponse instanceof RegistryException) 403 throw ((RegistryException)uddiResponse); 404 405 407 return uddiResponse; 408 } 409 410 411 417 public String execute(String uddiRequest, String urltype) 418 throws RegistryException 419 { 420 URL endPointURL = null; 421 if(urltype.equalsIgnoreCase("INQUIRY")) 422 endPointURL = this.getInquiryURL(); 423 else endPointURL = this.getPublishURL(); 424 425 428 return transport.send(uddiRequest,endPointURL); 429 } 430 431 432 439 public Transport getTransport(String className) 440 { 441 Transport transport = null; 442 Class transportClass = null; 443 444 if (className == null) 447 className = DEFAULT_TRANSPORT_CLASS; 448 449 try { 450 transportClass = Loader.getClassForName(className); 452 } 453 catch(ClassNotFoundException cnfex) { 454 cnfex.printStackTrace(); 455 } 456 457 try { 458 transport = (Transport)transportClass.newInstance(); 460 } 461 catch(java.lang.Exception ex) { 462 ex.printStackTrace(); 463 } 464 465 return transport; 466 } 467 468 469 470 471 472 473 474 public static void main(String [] args) 475 throws RegistryException 476 { 477 480 485 495 Properties props = new Properties (); 497 props.setProperty(INQUIRY_ENDPOINT_PROPERTY_NAME,"http://test.uddi.microsoft.com/inquire"); 498 props.setProperty(PUBLISH_ENDPOINT_PROPERTY_NAME,"https://test.uddi.microsoft.com/publish"); 499 props.setProperty(TRANSPORT_CLASS_PROPERTY_NAME,"org.apache.juddi.proxy.AxisTransport"); 500 props.setProperty(SECURITY_PROVIDER_PROPERTY_NAME,"com.sun.net.ssl.internal.ssl.Provider"); 501 props.setProperty(PROTOCOL_HANDLER_PROPERTY_NAME,"com.sun.net.ssl.internal.www.protocol"); 502 IRegistry registry = new RegistryProxy(props); 503 504 AuthToken authToken = registry.getAuthToken("sviens","password"); 505 AuthInfo authInfo = authToken.getAuthInfo(); 506 507 System.out.println(authInfo.getValue()); 508 } 509 } | Popular Tags |