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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 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; Properties connProps = new Properties(); public CreateOrganizationTest() { setConnectionProperties(); } public static void main(String[] args) { try { CreateOrganizationTest bqt = new CreateOrganizationTest(); bqt.executeCreation(); } catch (JAXRException e) { System.err.println("ERROR: Caught exception: " + 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); Connection conn = factory.createConnection(); // Next, obtain the registry service, and from that, obtain // a business query manager object. RegistryService rs = conn.getRegistryService(); blm = rs.getBusinessLifeCycleManager(); System.out.println("Got registry service and lifecycle manager"); // Set client authorization information for privileged registry operations PasswordAuthentication passwdAuth = new PasswordAuthentication("0", "pascal".toCharArray()); Set creds = new HashSet(); creds.add(passwdAuth); // Set credentials on the JAXR provider conn.setCredentials(creds); System.out.println("Established security credentials"); // Set communication preference conn.setSynchronous(true); Collection orgs = new ArrayList(); 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"); } private InternationalString getIString(String txt) { 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", ""); Collection postalAddresses = new ArrayList(); postalAddresses.add(address); Collection emailAddresses = new ArrayList(); EmailAddress emailAddress = blm.createEmailAddress("blog@redtream.nl"); emailAddresses.add(emailAddress); Collection numbers = new ArrayList(); numbers.add(telephoneNumber); user.setPersonName(personName); user.setPostalAddresses(postalAddresses); user.setEmailAddresses(emailAddresses); user.setTelephoneNumbers(numbers); ClassificationScheme cScheme = blm.createClassificationScheme("top-companies", ""); Key cKey = blm.createKey("uuid:001"); 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", ""); Key cKey1 = blm.createKey("uuid:002"); 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | /* * 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; Properties connProps = new Properties(); public BusinessQueryTest() { setConnectionProperties(); } public static void main(String[] args) { String company = "PALMA IT"; try { BusinessQueryTest bqt = new BusinessQueryTest(); bqt.executeQueryTest(company); } catch (JAXRException e) { System.err.println("ERROR: Caught exception: " + e); } } public void executeQueryTest(String qString) throws JAXRException { // First, create a ConnectionFactory, they create the // Connection from it using the specified connection properties. ConnectionFactory factory = ConnectionFactory.newInstance(); factory.setProperties(connProps); Connection conn = factory.createConnection(); // Next, obtain the registry service, and from that, obtain // a business query manager object. RegistryService rs = conn.getRegistryService(); bqm = rs.getBusinessQueryManager(); ArrayList names = new ArrayList(); names.add(qString); Collection qualifiers = new ArrayList(); qualifiers.add(FindQualifier.SORT_BY_NAME_DESC); //qualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); System.out.println("Requesting data..."); // 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) { System.out.println("Successfully queried the " + "registry for organization matching the " + "name pattern: \"" + qString + "\""); Collection orgs = br.getCollection(); System.out.println("Results found: " + orgs.size() + "\n"); Iterator iter = orgs.iterator(); while (iter.hasNext()) { Organization org = (Organization) iter.next(); System.out.println("Organization Name: " + getName(org)); System.out.println("Organization Key: " + getKey(org)); System.out.println("Organization Description: " + getDescription(org)); Collection services = org.getServices(); Iterator siter = services.iterator(); while (siter.hasNext()) { Service service = (Service) siter.next(); System.out.println("\tService Name: " + getName(service)); System.out.println("\tService Key: " + getKey(service)); System.out.println("\tService Description: " + getDescription(service)); } } } else { System.err.println("ERROR: One or more JAXRExceptions " + "occurred during the query operation:"); Collection exceptions = br.getExceptions(); Iterator iter = exceptions.iterator(); while (iter.hasNext()) { Exception e = (Exception) iter.next(); System.err.println(e.toString()); } } } 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"); } private String getName(RegistryObject ro) throws JAXRException { // Obtain the name from the registry object. try { return ro.getName().getValue(); } catch (NullPointerException npe) { return ""; } } private String getDescription(RegistryObject ro) throws JAXRException { // Obtain the description from the registry object. try { return ro.getDescription().getValue(); } catch (NullPointerException npe) { return ""; } } private String getKey(RegistryObject ro) throws JAXRException { // Obtain the key from the registry object. try { return ro.getKey().getId(); } catch (NullPointerException npe) { 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 :-)
Pingback: Added SCDJWS certificate to the list :-) | Redstream Blog
Pingback: Added SCDJWS certificate to the list :-) | Redstream Blog