The ability to publish services in a UDDI registry requires the application used to publish the service interface definitions to understand WSDL. WSDL4J is one mechanism that allows an application to read and interpret WSDL documents and optionally create new ones programmatically.
Let us start by looking at the steps necessary to publish a WSDL service interface in UDDI. As we have previously learned, WSDL service interfaces are represented as UDDI tModels. The first step is to actually read the WSDL document. For illustrative purposes, we will demonstrate the steps using WSDL4J APIs.
// Read the WSDL service interface document Definition definition = WSDLReader.readWSDL(null, wsdlURL); // Create a new tModel to be used to map the WSDL service interface Tmodel tModel = new tModel();
Next, we will specify a target namespace for the tModel as well as set the tModel description, which is optional. We will obtain the description from WSDL.
tModel.setName(definition.getTargetNamespace()); Element element = definition.getDocumentationElement(); String description = DOMUtils.getChildCharacterData(element); tModel.setDefaultDescriptionString(description);
Now, we will create the overviewDoc. As you may remember, it contains an overviewURL that points to the location of the WSDL document:
OverviewDoc overviewDoc = new OverviewDoc(); OverviewURL overviewURL = new OverviewURL(wsdlURL); tModel.setOverviewDoc(overviewDoc);
Remember that a tModel can point to multiple things, so in this case, we need to make sure it references a WSDL service description. We will create a categoryBag and place two keyedReferences in it. The first will contain the service description, and the second will specify the service's business description.
CategoryBag categoryBag = new CategoryBag(); Vector keyedReferenceList = new Vector(); KeyedReference keyedReference = new KeyedReference("uddi-org:types", "wsdlSpec"); KeyedReference.setTModelKey("UUID:B1FAC26D-4569-4421-9E20-36A752A62ED4"); KeyedReferenceList.add(keyedReference); KeyedReference = new KeyedReference("Flute Bank News Service", "54328910"); KeyedReference.setTModelKey("UUID:DB44690D-9AF8-4D24-A9AD-04621E34E274"); KeyedReferenceList.add(keyedReference); CategoryBag.setKeyedReferenceVector(keyedReferenceList); TModel.setCategoryBag(categoryBag);
Now that we have the WSDL and its respective tModel, it becomes necessary to publish them as bindingTemplates in the UDDI registry. We also need to create the businessService, based on the WSDL service implementation. The actual publication process will use the UDDI4J APIs, which are discussed later. In the meantime, we have only two more steps to take. The first is to create a businessService. Let us look at a code snippet that demonstrates this:
WsdlDefinition wsdlDefinition = new WsdlDefinition(); wsdlDefinition = WSDLReader.readWSDL(null, wsdlURL); Service wsdlService = ((Service[]) wsdlDefinition.getServices().values().toArray(new Service[0]))[0]; BusinessService businessService = new BusinessService(); businessService.setName(wsdlService.getQName().getLocalPar()); element = wsdlService.getDocumentationElement(); businessService.setDefaultDescriptionString(DOMUtils.getChildCharacterData(element));
After the WSDL document is parsed in the above example, a new businessService is created. The name of the service and its documentation is derived from its WSDL. Let us also create the corresponding bindingTemplate, using the following code:
BindingTemplate bindingTemplate = new BindingTemplate(); Port wsdlPort = ((Port[]) wsdlService.getPorts().values().toArray(new Port[0]))[0]; Element = wsdlPort.getDocumentationElement(); BindingTemplate.setDefaultDescriptionString(DOMUtils.getChildCharacterData(element));
We are using the documentation element from WSDL to create the description for the bindingTemplate. This is contained within the WSDL port element. The access point is specified in WSDL as the extensibility element, which changes depending on transport. Let us create additional code that uses the SOAP bindings:
Element extensibilityElement = (ExtensibilityElement) wsdlPort.getExtensibilityElements().get(0); AccessPoint accessPoint = new AccessPoint((SOAPAddress)extensibilityElement).getLocationURI(), "http"); bindingTemplate.setAccessPoint(accessPoint);
The bindingTemplate contains a reference to the tModel associated with the WSDL service interface document and contained in the tModelInstanceInfo. Remember that the tModelInstanceInfo contains the tModelKey for the specified tModel. In addition, the bindingTemplate will contain an overviewDoc that points to the WSDL service implementation document. This is demonstrated below:
TModelInstanceInfo = new TmodelInstanceInfo(tModelKey); OverviewURL overviewURL = new OverviewURL(wsdlURL); overviewDoc.setOverviewURL(overviewURL); instanceDetails.setOverviewDoc(overviewDoc);
This was the last step in parsing WSDL to create the appropriate UDDI entities. To publish this information in UDDI, you would need to use UDDI4J (discussed later in this chapter) or JAXR (discussed in its own chapter).