| 17 February 2009 |
Currently I am busy, besides my daily job, to get SCDJWS certificated. I'm having this one on my todo list for long time, actually it's been so long that I am wondering if it might be a little outdated. But the main reason to do it anyway is that I already have bought a voucher that is only valid for a few more weeks so why not use it. And while I was looking on the net for info about the theory I stumbled upon this article defending why JAX-RPC is still useful to understand.
Anyway, one item I definitely have to learn more about is JAXR and UDDI. I know the concepts but that's it. I am not familiar with all the ins and outs, which they want you to know for the exam. To fill this gap of knowledge I wanted to use this article that describes how to use JAXR to access a UDDI registry. Unfortunately the registries that are used in the examples don't exist anymore or at least I am not able to reach them. So I decided to setup my own registry, that seemed like fun to do and a good exercise anyway. I followed these steps to setup jUDDI: Don't go there.
Just get the 2.0 version of jUDDI here and follow the guidelines in the manual that is packed with this distribution (the Tomcat distribution make things very easy). I tried the steps to install an older version of jUDDI but this resulted in the following stacktrace when I tried to access the registry from my java code:
java.lang.IllegalArgumentException
at
com.sun.xml.registry.uddi.bindings_v2.impl.runtime.UnmarshallerImpl.unmarshal(Unknown
Source)
at com.sun.xml.registry.common.util.MarshallerUtil.jaxbUnmarshalObject(Unknown
Source)
at com.sun.xml.registry.uddi.Processor.processResponseJAXB (Unknown Source)
at com.sun.xml.registry.uddi.Processor.processRequestJAXB(Unknown Source)
at com.sun.xml.registry.uddi.UDDIMapper.findOrganizations(Unknown Source)
at com.sun.xml.registry.uddi.BusinessQueryManagerImpl.findOrganizations(Unknown
Source)
And although the error is found a lot on the internet I haven't been able to found a solution for it, other then just try the newer version of jUDDI.
When you have installed all components (Tomcat, jUDDI and MySQL, for example) you can run the jUDDI validation page to see if everything is configured well and working.

Here are some sample classes I used when playing around with JAXR. I have inserted one record in the UDDI database by hand:

This way I can identify myself with JAXR as an existing publisher so I am allowed to register stuff in the UDDI. To create an organization in the UDDI registry:
-
package net.pascalalma.client;
-
-
/**
-
*
-
* @author pascal
-
*/
-
import java.net.PasswordAuthentication;
-
import java.util.logging.Level;
-
import java.util.logging.Logger;
-
import javax.xml.registry.*;
-
import javax.xml.registry.infomodel.*;
-
-
import java.util.*;
-
import javax.xml.registry.infomodel.ClassificationScheme;
-
-
public class CreateOrganizationTest {
-
-
String regUrli = "http://localhost:8080/juddi/inquiry";
-
String regUrlp = "http://localhost:8080/juddi/publish";
-
-
BusinessQueryManager bqm = null;
-
BusinessLifeCycleManager blm = null;
-
-
-
public CreateOrganizationTest() {
-
setConnectionProperties();
-
}
-
-
-
try {
-
CreateOrganizationTest bqt = new CreateOrganizationTest();
-
-
bqt.executeCreation();
-
-
} catch (JAXRException e) {
-
}
-
-
}
-
-
public void executeCreation()
-
throws JAXRException {
-
-
// First, create a ConnectionFactory, they create the
-
// Connection from it using the specified connection properties.
-
-
ConnectionFactory factory = ConnectionFactory.newInstance();
-
factory.setProperties(connProps);
-
-
// Next, obtain the registry service, and from that, obtain
-
// a business query manager object.
-
-
RegistryService rs = conn.getRegistryService();
-
blm = rs.getBusinessLifeCycleManager();
-
-
-
-
// Set client authorization information for privileged registry operations
-
creds.add(passwdAuth);
-
// Set credentials on the JAXR provider
-
conn.setCredentials(creds);
-
// Set communication preference
-
conn.setSynchronous(true);
-
-
Organization o = createOrganization();
-
-
orgs.add(o);
-
BulkResponse br = blm.saveOrganizations(orgs);
-
-
}
-
-
protected void setConnectionProperties() {
-
-
// Static properties set for the connection to the UDDI server.
-
-
connProps.setProperty("javax.xml.registry.queryManagerURL", regUrli);
-
connProps.setProperty("javax.xml.registry.lifeCycleManagerURL", regUrlp);
-
connProps.setProperty("javax.xml.registry.factoryClass",
-
"com.sun.xml.registry.uddi.ConnectionFactoryImpl");
-
-
}
-
-
try {
-
return blm.createInternationalString(txt);
-
} catch (JAXRException ex) {
-
Logger.getLogger(CreateOrganizationTest.class.getName()).log(Level.SEVERE, null, ex);
-
return null;
-
}
-
}
-
/**
-
* Creates a Jaxr Organization with 1 or more services
-
*/
-
protected Organization createOrganization() throws JAXRException {
-
Organization org = blm.createOrganization("PALMA IT");
-
org.setDescription(getIString("My Company"));
-
Service service = blm.createService("PALMA's JAXR Service");
-
service.setDescription(getIString("Services of XML Registry"));
-
//Create serviceBinding
-
ServiceBinding serviceBinding = blm.createServiceBinding();
-
serviceBinding.setDescription(blm.createInternationalString("Test Service Binding"));
-
-
//Turn validation of URI off
-
serviceBinding.setValidateURI(false);
-
serviceBinding.setAccessURI("http://www.palma-it.com/MyService/");
-
// Add the serviceBinding to the service
-
service.addServiceBinding(serviceBinding);
-
-
User user = blm.createUser();
-
org.setPrimaryContact(user);
-
PersonName personName = blm.createPersonName("Pascal Alma");
-
TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
-
telephoneNumber.setNumber("06 12345678");
-
telephoneNumber.setType(null);
-
PostalAddress address = blm.createPostalAddress("26", "Lisdreef", "Papendrecht", "ZH", "Netherlands", "3355 EC", "");
-
postalAddresses.add(address);
-
EmailAddress emailAddress = blm.createEmailAddress("blog@pascalalma.net");
-
emailAddresses.add(emailAddress);
-
-
numbers.add(telephoneNumber);
-
user.setPersonName(personName);
-
user.setPostalAddresses(postalAddresses);
-
user.setEmailAddresses(emailAddresses);
-
user.setTelephoneNumbers(numbers);
-
-
ClassificationScheme cScheme = blm.createClassificationScheme("top-companies", "");
-
cScheme.setKey(cKey);
-
Classification classification = blm.createClassification(cScheme,
-
"Computer Systems Design and Related Services", "1");
-
org.addClassification(classification);
-
ClassificationScheme cScheme1 = blm.createClassificationScheme("D-U-N-S", "");
-
cScheme1.setKey(cKey1);
-
ExternalIdentifier ei = blm.createExternalIdentifier(cScheme1, "D-U-N-S number", "08-01");
-
org.addExternalIdentifier(ei);
-
org.addService(service);
-
return org;
-
}
-
}
To search for registered organizations:
-
/*
-
* To change this template, choose Tools | Templates
-
* and open the template in the editor.
-
*/
-
package net.pascalalma.client;
-
-
/**
-
*
-
* @author pascal
-
*/
-
import javax.xml.registry.*;
-
import javax.xml.registry.infomodel.*;
-
-
import java.util.*;
-
-
public class BusinessQueryTest {
-
-
// Edit these properties if you are behind a firewall, otherwise
-
// leave them blank.
-
String regUrli = "http://localhost:8080/juddi/inquiry";
-
String regUrlp = "http://localhost:8080/juddi/publish";
-
-
BusinessQueryManager bqm = null;
-
BusinessLifeCycleManager blm = null;
-
-
-
public BusinessQueryTest() {
-
setConnectionProperties();
-
}
-
-
-
String company = "PALMA IT";
-
-
try {
-
BusinessQueryTest bqt = new BusinessQueryTest();
-
-
-
bqt.executeQueryTest(company);
-
-
} catch (JAXRException e) {
-
}
-
-
}
-
-
throws JAXRException {
-
-
-
// First, create a ConnectionFactory, they create the
-
// Connection from it using the specified connection properties.
-
-
ConnectionFactory factory = ConnectionFactory.newInstance();
-
factory.setProperties(connProps);
-
-
// Next, obtain the registry service, and from that, obtain
-
// a business query manager object.
-
-
RegistryService rs = conn.getRegistryService();
-
bqm = rs.getBusinessQueryManager();
-
-
names.add(qString);
-
-
qualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
-
//qualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH);
-
-
-
// Find the organizations requested.
-
-
BulkResponse br = bqm.findOrganizations(qualifiers,
-
names, null, null, null, null);
-
-
// If we have results (including zero matches), then print out
-
// a success message, followed by the results if applicable.
-
-
if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
-
"registry for organization matching the " +
-
"name pattern: \"" + qString + "\"");
-
-
-
while (iter.hasNext()) {
-
Organization org = (Organization) iter.next();
-
getName(org));
-
getKey(org));
-
getDescription(org));
-
-
while (siter.hasNext()) {
-
Service service = (Service) siter.next();
-
getName(service));
-
getKey(service));
-
getDescription(service));
-
}
-
}
-
-
} else {
-
"occurred during the query operation:");
-
while (iter.hasNext()) {
-
}
-
}
-
-
}
-
-
protected void setConnectionProperties() {
-
-
// Static properties set for the connection to the UDDI server.
-
-
connProps.setProperty("javax.xml.registry.queryManagerURL", regUrli);
-
connProps.setProperty("javax.xml.registry.lifeCycleManagerURL", regUrlp);
-
connProps.setProperty("javax.xml.registry.factoryClass",
-
"com.sun.xml.registry.uddi.ConnectionFactoryImpl");
-
-
}
-
-
-
// Obtain the name from the registry object.
-
-
try {
-
return ro.getName().getValue();
-
return "";
-
}
-
}
-
-
-
// Obtain the description from the registry object.
-
-
try {
-
return ro.getDescription().getValue();
-
return "";
-
}
-
}
-
-
-
// Obtain the key from the registry object.
-
-
try {
-
return ro.getKey().getId();
-
return "";
-
}
-
}
-
}
The result of the last program is (after successful registration of the organization:
run:
Requesting data...
Successfully queried the registry for organization matching the name pattern: "PALMA IT"
Results found: 1Organization Name: PALMA IT
Organization Key: 298B4970-FC6A-11DD-8970-BE836B4D6233
Organization Description: My Company
Service Name: PALMA's JAXR Service
Service Key: 29A05810-FC6A-11DD-9810-848A3849CC94
Service Description: Services of XML Registry
BUILD SUCCESSFUL (total time: 1 second)
Now I can play around and hoping I remember enough of this stuff when taking the exam :-)


1 comment to 'Setting up a private UDDI Registry'
11 November 2009
[...] SCDJWS certificate to the list :-) 27 February 2009 Pascal Alma As posted here I have been busy last few weeks studying for my upcoming exam to become Sun Certified Developer for [...]