Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Using collections in WebSphere Service Registry and Repository to resolve versioned imports, Part 1: Creating and managing versioned documents

A guide to creating versioned documents and collections with WebSphere Service Registry and Repository

Bernard Z. Kufluk (bernard@uk.ibm.com), Software Engineer, IBM
Bernard Kufluk is an IBM software developer working on WebSphere Service Registry and Repository. He has been engaged in the API development team since November 2005. Over the past seven years, he has worked on various IBM products including WebSphere Voice Application Access, WebSphere Voice Response, and Intelligent Notification Services. You can reach him at bernard@uk.ibm.com.
Ian Heritage (heritage@uk.ibm.com), Software Engineer, IBM
Ian Heritage is an IBM Software Developer working on WebSphere Service Registry and Repository. He is leading the Level 3 Service Team and has been engaged in testing the product since November 2005. Prior to this, Ian worked on WebSphere Voice Response and Unified Messaging for WebSphere Voice Response.

Summary:  This article is the first in a series describing how to use collections within WebSphere Service Registry and Repository. Part 1 of this series provides step-by-step instructions to help you create and manage versioned documents within WebSphere Service Registry and Repository. A worked example and sample code you can try out on your own system help you learn how to correctly and predictably link documents. Future articles in this series will explore more advanced scenarios that cover detailed explanations of the scoping rules and how to use collections from the Web services API.

View more content in this series

Date:  31 Jan 2007
Level:  Intermediate

Activity:  2197 views
Comments:  

Introduction

IBM® WebSphere® Service Registry and Repository V6 (hereafter referred to as Service Registry and Repository) is an industrial-strength tool that helps you achieve more business value from your service-oriented architecture (SOA) by enabling better management and governance of your services. You can use Service Registry and Repository to store information about services in your systems, or in other organizations' systems, that you already use, plan to use, or want to be aware of. For example, an application can check with Service Registry and Repository just before it invokes a service to locate the most appropriate service that satisfies its functional and performance needs. This capability helps make your SOA deployment more dynamic and more adaptable to changing business conditions.

Service Registry and Repository provides management for Service Metadata including WSDL and XML Schema documents. Service Registry and Repository maintains relationships between the documents in its database. These relationships can be manipulated at creation time to allow the user fine-grained control over specific versions of their services.

Before you begin this article, install WebSphere Service Registry and Repository to make full use of this article and the examples. A simple Java™ program using the EJB API shows how to tackle this subject programmatically. You should also download the code from the Downloads section of this article.

Use the instructions from Tim Baldwin's article on sample applications for WebSphere Service Registry and Repository, Introducing WebSphere Service Registry and Repository APIs to install the samples (see Resources). Use the sample name of "EJB-VersioningWithCollections". The code is available in the class "com.ibm.wsrr.samples.ejb.VersioningWithCollections".

Creating a document

Let's begin by creating an entry in the Repository, so that we have a document to work with. We can start with an XML Schema Document, in our case, myXmlSchemaDocument.xsd. When creating the document, you can add a version.

Tip: Notice that once a document has been created, the version cannot be changed.

The version field is a free format string in WebSphere Service Registry and Repository that lets you use any type of versioning system. By default, it is an empty string. For this example, set the version to 2.0.

  1. Direct your browser to the machine running the Service Registry and Repository. The URL is usually of the form: http://hostname:9080/ServiceRegistry.
  2. Select Service Documents => XSD Documents => Load Document (see Figure 1).

    Figure 1. Screenshot showing loading screen for myXmlSchemaDocument.xsd
    myXmlSchemaDocument.xsd

  3. Now that you've created the document, view it by selecting Service Documents=> XSD Documents.
  4. Select myXmlSchemaDocument.xsd. The details view shows the version of the document is set to 2.0. See Figure 2.

    Figure 2. Screenshot showing summary screen for myXmlSchemaDocument.xsd
    myXmlSchemaDocument.xsd summary

  5. Select the content tab to view the document source. Additionally, you can download the original document by selecting the download document button (see Figure 3).

    Figure 3. Content screen for myXmlSchemaDocument.xsd
    xml content

Linking versions

The Web Service, myWebService, can perform operations, but needs a datatype definition from myXmlSchemaDocument.xsd to do so. myWebService is defined by myWebService.wsdl.

In this example, we want to link to a particular version of myXmlSchemaDocument, version 2.0, that we created earlier. If we were to supply the Registry simply with myWebService.wsdl, the system would have no way of telling which version we wanted to link to.

Important technical note: The repository by default will only link to documents that do not have a version. In the example above, a new version-less myXmlSchemaDocument.xsd would be created in the repository from the URI in myWebService.wsdl.

So how do we logically associate documents together in the registry such that we can tell which versions belong together?

The answer lies within a new object called a GenericObject. We need to create a GenericObject to represent our collection of services and schemas that we want associated in the registry.

The structure that we are going to build looks like the collection hierarchy (see Figure 4):


Figure 4. Collection hierarchy
Collection hierarchy

In order to use collections, you need to use the WebSphere Service Registry and Repository API, rather than the Web User Interface (UI). This article uses the EJB API, but alternatively, you can also use the Web Services API or the command line interface.

Creating a generic object

Use the following steps to create a generic object to represent the collection of services and schemas that we want associated in the registry.

  1. Create a generic object named, GenericObject, with the code in Listing 1.

    Listing 1. Create a GenericObject
            GenericObject myGenericObject = 
                (GenericObject)DataFactory.INSTANCE.create(TypeConstants.SR_URI, 
                        TypeConstants.TYPE_GENERICOBJECT);
            // Generic objects must have a name set.
            myGenericObject.setName("myCollection"); 
          

  2. Create the new myWsdlService.wsdl (see Listing 2).

    Listing 2. Create the wsdl document
            // Example code to create myWebService.wsdl which imports myXmlSchemaDocument.xsd 
            FileInputStream is = new FileInputStream("resources/myWebService.wsdl");
            WSDLDocument myWebServicesDoc = (WSDLDocument)SRXMLHelper.INSTANCE.load(is, 
                    TypeConstants.TYPE_WSDLDOCUMENT);
            myWebServicesDoc.setName("myWebService.wsdl");
            myWebServicesDoc.setLocation("myWebService.wsdl");
    

  3. Create the code to retrieve the myXmlSchema.xsd version 2.0 that we created earlier.

    Listing 3. Retrieve the xml schema document
            // Example code to retrieve myXmlSchema.xsd with a version string of "2.0"
            // Assuming we don't already know the bsrURI of the required XSD document we 
            // need to run a property query.
            PropertyQuery propertyQuery = 
                (PropertyQuery)DataFactory.INSTANCE.create(TypeConstants.SR_URI, 
                        TypeConstants.TYPE_PROPERTYQUERY);
            String xpath = "/WSRR/XSDDocument[@name='myXmlSchemaDocument.xsd" " +
                    "and @version='2.0' " +
                    "and @namespace='http://com.ibm.wsrr.samples/xsd']";
            propertyQuery.setQueryExpression(xpath);
            // We only need the "bsrURI" of the XSDDocument
            BSRSDOHelper.INSTANCE.addProperty(propertyQuery, "prop1", "bsrURI");        
            System.out.println("  running query " + xpath);
            List results = serviceRegistry.executeQuery(propertyQuery);
            propertyQuery = null;
            //The result size should be 1.
            System.out.println(" result size = " + results.size());        
            PropertyQueryResult result = (PropertyQueryResult)results.get(0);
            String myXmlSchemaDocumentBsrUri = 
                BSRSDOHelper.INSTANCE.getPropertyQueryResultValue(result, "bsrURI");
            System.out.println(" result: " + myXmlSchemaDocumentBsrUri);        
    
            // Example code to retrieve myXmlSchema.xsd with a version string of "2.0" 
            // given its bsrURI
            System.out.println("  retrieving myXmlSchemaDocument.xsd from the repository");
            XSDDocument myXmlSchemaDoc = 
                (XSDDocument)serviceRegistry.retrieve(myXmlSchemaDocumentBsrUri);
    

  4. Link the documents together under the GenericObject myCollection using two user defined relationships (see Listing 4 below).

    Listing 4. Link the objects
            BSRSDOHelper.INSTANCE.addRelationship(myGenericObject,"myRelationship1",
                    myWebServicesDoc);
            BSRSDOHelper.INSTANCE.addRelationship(myGenericObject,"myRelationship2",
                    myXmlSchemaDoc);
    

  5. Now that the collection is complete, send it to the registry to be stored (see Listing 5).

    Listing 5. Persist the collection
            serviceRegistry.create(myGenericObject);                
    

Good job! You've saved the document and associated it with the correct version!

Notice that when creating collections, if the registry fails to find the document that it is trying to resolve from an import link, it will look first in the Repository itself, and follow the document URI secondly.

Making sure everything works

Let's check that everything went as planned.

  1. Find the WSDL document. Select Service Documents => WSDL Documents (see Figure 5).

    Figure 5. myWebService.wsdl
    myWebService.wsdl

  2. Select myWebService.wsdl => imported schemas (see Figure 6).

    Figure 6. Screenshot showing the imported schemas
    imported schemas

  3. Select myXmlSchemaDocument.xsd and check that the version is 2.0 as expected.
  4. Objects of type GenericObject are known as Concepts in the Service Registry and Repository Web UI. To view the GenericObject that we created earlier, select Unified Service Metadata => Concepts (see Figure 7).

    Figure 7. The GenericObject
    myXmlSchemaDocument.xsd

Important technical note: The GenericObject is no longer required now that the association has been created between the documents. Deleting the GenericObject will not affect the imported XSD Documents relationship.

Congratulations! You successfully created a schema document with a version and then associated it with a new Web service in the WebSphere Service Registry and Repository.

Conclusion

You have been introduced to the concept of using a collection to manage documents. In this article you were taken through step-by-step instructions for creating and managing versioned documents within WebSphere Service Registry and Repository. You created a versioned schema document within the Repository and then deliberately associated a new Web service with this specific versioned schema document. Future articles in this series will go into more advanced scenarios covering detailed explanations of the scoping rules and how to use collections from the Web Services API.



Downloads

DescriptionNameSizeDownload method
Sample WebSphere client application0701_kufluk-VersioningWithCollections.ear2.3MBHTTP
Sample application source code and projects0701_kufluk-VersioningWithCollectionsPIF.zip2.4MBHTTP

Information about download methods


Resources

About the authors

Bernard Kufluk is an IBM software developer working on WebSphere Service Registry and Repository. He has been engaged in the API development team since November 2005. Over the past seven years, he has worked on various IBM products including WebSphere Voice Application Access, WebSphere Voice Response, and Intelligent Notification Services. You can reach him at bernard@uk.ibm.com.

Ian Heritage is an IBM Software Developer working on WebSphere Service Registry and Repository. He is leading the Level 3 Service Team and has been engaged in testing the product since November 2005. Prior to this, Ian worked on WebSphere Voice Response and Unified Messaging for WebSphere Voice Response.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=191837
ArticleTitle=Using collections in WebSphere Service Registry and Repository to resolve versioned imports, Part 1: Creating and managing versioned documents
publish-date=01312007
author1-email=bernard@uk.ibm.com
author1-email-cc=Author1 cc address
author2-email=heritage@uk.ibm.com
author2-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers