Main Page

Previous Section Next Section

Publishing WSDL Service Interfaces in UDDI

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.

Element element = definition.getDocumentationElement();
String description = DOMUtils.getChildCharacterData(element);

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);

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 = new KeyedReference("Flute Bank News Service", "54328910");


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
BusinessService businessService = new BusinessService();

element = wsdlService.getDocumentationElement();

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();

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)
AccessPoint accessPoint = new
AccessPoint((SOAPAddress)extensibilityElement).getLocationURI(), "http");

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);

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).

Previous Section Next Section

JavaScript Editor Java Tutorials Free JavaScript Editor