Search for and release WSDL In the UDDI registration center

Source: Internet
Author: User
Tags ibm developerworks
Compile at the beginning for publishing the application Program Of Code Before that, you must understand the two basic requirements of such applications. First, the publishing application must read and understand the content of the WSDL document. Second, they must send requests to the UDDI registration center and then process any response. Fortunately, there are two ready-made Java class libraries that provide this feature: Web Services Description Language for Java (wsdl4j) and UDDI Java API (uddi4j ).

Wsdl4j provides a standard Java interface that can be used to parse existing WSDL documents or create new WSDL documents through programming. Wsdl4j is an open-source project (see references) located on the IBM developerworks website to "java standard request 110 (Java specification request 110 (JSR 110 )) java APIs for WSDL provides a reference implementation (for more information, see references ). This JSR is developed through Java Community process.

The programming example in this article uses wsdl4j v0.8. Most wsdl4j classes represent elements that can appear in the WSDL document. For example, it is represented by the definition class. Element, which is represented by the service class Element. It also makes the WSDL document easy to read and parse, and uses the content of the wsdl4j object as the compile class written in the XML document.

Uddi4j provides a Java client interface that can be used to publish and search service descriptions in the UDDI registration center. This is also an open source project hosted on the IBM developerworks website (please refer to references again for a link ).

For publishing an application, I will use uddi4j v1.03. This version provides a complete implementation of the UDDI V1 application programming interface. The uddi4j class contains a complete representation of the UDDI data entity. For example, the tModel class represents the UDDI tModel and the businessService class represents the businessService. Uddi4j also contains a UDDI registry proxy class. This class is used to send publish and find requests to the UDDI registration center.

Release the WSDL service interface as a UDDI tModel

I will start by developing some code that will be used to publish the description of the WSDL service interface as the UDDI tModel. In the first part of this series, I reviewed the steps required to correctly define a WSDL service interface. As a requirement for developing and publishing applications, I will perform these steps. Here is a brief summary of these steps:

Set the tModel name through targetnamespace In the WSDL document.

If the description element contains a document element, use it to create a tModel description.

Place the network accessible location of the WSDL service interface document in overviewdoc.

Add at least one keyedreference, which indicates that the tModel contains a reference to the WSDL service description.

The code associated with each step is described in detail below. You can also view and download the complete publishserviceinterface application (see references for links ).

Step 1: Create a tModel and set the name through targetnamespace

Before proceeding to this step, you must read and parse the WSDL document. Use the wsdlreader class in wsdl4j to complete this operation. After reading the WSDL document, create a new tModel object and set its name through targetnamespace In the WSDL document.

Listing 1: first read and parse the WSDL document

// Read WSDL service interface document
Definition def = wsdlreader. readwsdl (null, wsdlurl );

...

// Create tModel from WSDL Service Interface
TModel = new tModel ();

// [Step 1: tModel} set the businessService name from targetnamespace
TModel. setname (def. gettargetnamespace ());

Step 2: Set the tModel description through the WSDL document Element

It is optional to set the tModel description. If the document element is specified within the definition element, it can be used to set the tModel description.

Listing 2: Setting the tModel description

// Get documentation Element
Element element = def. getdocumentationelement ();

// [Step 2: tModel] Set Default tModel description
String DESC = domutils. getchildcharacterdata (element );
TModel. setdefadedescriptionstring (DESC );

Step 3: Create overviewdoc for tModel

Overviewdoc will include the network accessible location of the WSDL service interface document. In this Code segment, set overviewurl to the position of the WSDL document.

Listing 3: Setting overviewurl

// Create overview Doc
Overviewdoc = new overviewdoc ();

// Create overview URL
Overviewurl = new overviewurl (wsdlurl );

// Set overviewurl
Overviewdoc. setoverviewurl (overviewurl );

// [Step 3: tModel] set the overviewdoc
TModel. setoverviewdoc (overviewdoc );

Step 4: classify tModel as the WSDL service description

Because tModel can reference the service description that can be specified in any markup language, it is important to point out that the tModel represents a WSDL service description. Adding an additional item to the categorybag of tModel completes this operation. In this sample code, there are two keyedreference. One indicates the type of service description, and the other indicates the commercial purpose of the service that implements this service interface.

Listing 4: edit the tModel categorybag

// Create a categorybag and get the categorybag
Categorybag = new categorybag ();

// Create a keyedreference for wsdlspec
Keyedreference Kr = new keyedreference ("UDDI-org: types", "wsdlspec ");
KR. settmodelkey ("UUID: C1ACF26D-9672-4404-9D70-39B756E62AB4 ");
Krlist. Add (KR );

// Create a keyedreference for the category of service
Vector krlist = new vector ();
KR = new keyedreference ("stock market trading services", "84121801 ");
KR. settmodelkey ("UUID: DB77450D-9FA8-45D4-A7BC-04411D14E384 ");
Krlist. Add (KR );

// Set keyed reference Vector
Categorybag. setkeyedreferencevector (krlist );

// [Step 4: tModel] set the category bag
TModel. setcategorybag (categorybag );

Release the WSDL service as a UDDI businessService

The second application published the WSDL service implementation description in UDDI as businessService. To complete this operation, you must create both businessService and bindingTemplate. The following steps are based on the process defined in the first part of this series. These steps show how to create both businessService and bindingTemplate and use them as the basis for building your published application. The code associated with each step is extracted from the complete publishserviceimplementation application.

First, I will review the steps for creating a businessService. Here is the summary of these steps:

Set the businessService name by the service element name.

If a name is specified, use the content of the document element to create the description of businessService.

Step 1: Create a businessService and set the name through the service name

Start by reading and parsing the content of the WSDL document. You can use the wsdlreader class in wsdl4j to complete this operation. After reading the WSDL document, you create a new businessService object and set its name through the service name in the WSDL document.

Listing 5: Create and name a new businessService object

// Read WSDL service implementation document Definition
Wsdldefinition = wsdlreader. readwsdl (null, wsdlurl );

// Get the first service element only
Service wsdlservice =
(Service []) wsdldefinition. getservices (). Values (). toarray (new service [0]) [0];

...

// Create businessService from WSDL Service Interface
BusinessService = new businessService ();

...

// [Step 1: businessService] set the businessService name from service name
BusinessService. setname (wsdlservice. getqname (). getlocalpart ());

Step 2: Set the businessService description through the WSDL document Element

The WSDL document element in the service element is used to set the default description of businessService:

Listing 6: Setting the default businessService description

// Get documentation Element
Element = wsdlservice. getdocumentationelement ();

// [Step 2: businessService] Set Default businessService description
BusinessService. setdefadedescriptionstring (domutils. getchildcharacterdata (element ));

Now you have created a businessService. You can create a bindingTemplate. Here is the summary of the four steps for creating bindingtemplatehere:

If the port element contains the document element, use its content to create the description of the bindingTemplate.

Use the location in the port element to set the accesspoint.

Add a tmodelinstanceinfo to bindingTemplate. This element contains tmodelkey.

Create an overviewdoc element that contains the reference to the WSDL service implementation document.

Step 1: Create a bindingTemplate and set the description through the WSDL document Element

Create a new bindingTemplate object and set its default description through the WSDL document element in the port element.

Listing 7: Creating and setting bindingTemplate objects

// Create a bindingTemplate
BindingTemplate = new bindingTemplate ();

// Get the first port Element
Port wsdlport = (Port []) wsdlservice. getports (). Values (). toarray (New Port [0]) [0];

// Get documentation Element
Element = wsdlport. getdocumentationelement ();

// [Step 1: bindingTemplate] Set Default bindingTemplate description
BindingTemplate. setdefadedescriptionstring (domutils. getchildcharacterdata (element ));

Step 2: Set the access point in bindingTemplate

Set the access point through the scalability element in the port element. For this sample code, I assume that soap binding is used and HTTP protocol is used for access points.

Listing 8: Set the bindingTemplate Access Point

// Get first extensibility elementextensibility
Element ext = (extensibilityelement) wsdlport. getextensibilityelements (). Get (0 );

// Create access point (assume that it is always soap binding and HTTP Protocol)
Accesspoint = new accesspoint (soapaddress) ext). getlocationuri (), "HTTP ");

// [Step 2: bindingTemplate] set the Access Point
BindingTemplate. setaccesspoint (accesspoint );

Step 3: Create tmodelinstanceinfo that references the Service Interface

BindingTemplate must contain a reference to the tModel associated with the service interface definition. Create a tmodelinstanceinfo containing the tmodelkey of the tModel to complete this operation.

Listing 9

// [Step 3: bindingTemplate] Create tmodelinstanceinfo using the tmodelkey
Tmodelinstanceinfo = new tmodelinstanceinfo (tmodelkey );

Step 4: Create overviewdoc in instancedetails

In addition to the location where overviewdoc will contain the WSDL service implementation document, this step is similar to the one used in the Service Interface document.

Listing 10

// Create overview urloverviewurl
Overviewurl = new overviewurl (wsdlurl );

// Set overviewurl
Overviewdoc. setoverviewurl (overviewurl );

// [Step 4: bindingTemplate] set the overview doc
instancedetails. setoverviewdoc (overviewdoc);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.