SOCKET

Sunday Jul 09, 2006

Punch in jUDDI

This is a brief description of how to set up UDDI4J to communicate with a UDDI registry.

In version 2, UDDI4J brought in a pluggable transport layer that can be set to Apache Soap, Apache Axis or an HP implementation of Soap.

For Axis, the following line of code should be used:

System.setProperty("org.uddi4j.TransportClassName","org.uddi4j.transport.ApacheAxisTransport");

Each transport option introduces its own set of dependencies. For Axis, the following resources should be on the classpath.

uddi4j.jar
axis.jar
jaxrpc.jar
saaj.jar
jax-runtime.jar
jax-rpi.jar
commons-logging-1.0.4.jar
commons-discovery-0.2.jar
commons-httpclient-3.0-rc2.jar
the five javamail jars
activation.jar (JAF 1.1)

These are the import statements I have used in my main class:

import org.uddi4j.client.*;
import org.uddi4j.datatype.*;
import org.uddi4j.response.*;
import org.uddi4j.util.*;
import org.uddi4j.transport.*;
import org.uddi4j.*;
import org.uddi4j.datatype.business.*;
import org.uddi4j.datatype.tmodel.*;
import org.apache.axis.transport.*;
import javax.xml.rpc.*;
import javax.xml.soap.*;
import org.apache.commons.logging.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.net.*;

Here's a couple of basic Java classes to start playing around with:

/**
*
* Main class for fiddling around with jUDDI.
*
* @author Clayton Moore
* @version 0.7.0
*/
public class UddiManager {

UDDIProxy uddiProxy;
SocketBusinessManager socketBusinessManager;

public UddiManager() {

//Sets SOAP transport system to Axis (alternatives are Apache Soap
//and HPSoap.
System.setProperty("org.uddi4j.TransportClassName","org.uddi4j.transport.ApacheAxisTransport");

//Create a new UDDIProxy object on which all the UDDI methods can
//be called.
uddiProxy = new UDDIProxy();

//Class to carry out some basic businessEntity functions
socketBusinessManager = new SocketBusinessManager(uddiProxy);

//Set publish and inquiry URLs: publish should be https, which
//would require the use of JSSE.

//Change localdomain to the domain name and path to the UDDI
//implementation.
uddiProxy.setPublishURL("http://localdomain/juddi/publish");
uddiProxy.setInquiryURL("http://localdomain/juddi/inquiry");
}

public static void main(String[] args) {

UddiManager uddiManager = new UddiManager();

try
{
AuthToken token = null;
//All publish operations on a jUDDI must be accompanied by
//an authorisation token, a sort of mini-session object.
token = uddiManager.uddiProxy.get_authToken("juddi", "juddi");

System.out.println("Token received: " + token.getAuthInfoString());

//Tokens will time out, but best create a new one for each task
//or set of related tasks and invalidate the token afterwards.
//This obviously means that no-one else can use it.

//uddiManager.uddiProxy.discard_authToken(token.getAuthInfoString());
//System.out.println("Token invalidated: " + token.getAuthInfoString());

uddiManager.socketBusinessManager.addBusiness("SOCKET-Leeds", token);

System.out.println("New business created.");

}
catch (TransportException ex)
{
System.out.println("We have a transport exception.");
}
catch (UDDIException ex)
{
System.out.println("We have a UDDI exception.");
System.out.println(ex.toString());
}

}
}

Some of the code in the next class is taken from
http://www-128.ibm.com/developerworks/webservices/library/ws-uddi4j.html?dwzone=webservices

Doug Tidwell: UDDI4J Matchmaking for Web Services, Jan 2001.

import java.util.ArrayList;
import org.uddi4j.client.UDDIProxy;
import java.util.Vector;
import org.uddi4j.transport.*;
import org.uddi4j.*;
import org.uddi4j.datatype.business.BusinessEntity;
import org.uddi4j.response.AuthToken;
import org.uddi4j.response.BusinessDetail;
import org.uddi4j.response.BusinessList;
import org.uddi4j.response.BusinessInfo;
import org.uddi4j.response.DispositionReport;

/**
* Class for carrying out basic business entity functions.
*
* @author Clayton Moore
* @version 0.7.0
*/
public class SocketBusinessManager
{
private UDDIProxy uddiProxy;

public SocketBusinessManager()
{
}

public SocketBusinessManager(UDDIProxy uddiProxy)
{
this.uddiProxy = uddiProxy;
}

public void addBusiness(String businessName, AuthToken token)
{
Vector entities = new Vector();

BusinessEntity be = new BusinessEntity();

Vector businessNames = new Vector();

Name name = new Name(businessName);

businessNames.add(name);

be.setNameVector(businessNames);

entities.addElement(be);

try
{

BusinessDetail bd = uddiProxy.save_business(token.getAuthInfoString(),
entities);

Vector businessEntities = bd.getBusinessEntityVector();

BusinessEntity returnedBusinessEntity = (BusinessEntity)(businessEntities.elementAt(0));

System.out.println("Returned businessKey:" + returnedBusinessEntity.getBusinessKey());

}
catch (TransportException ex)
{
}
catch (UDDIException ex)
{
}
}
}

Calendar

Feeds

Search

Links

Navigation

Referers