SOCKET Technical blog for SOCKET http://www.agbooth.com/SOCKETBlog/www.socketelf.org_8080/roller/socket/feed/entries/atom 2008-05-06T18:15:30+01:00 Apache Roller (incubating) http://www.agbooth.com/SOCKETBlog/www.socketelf.org_8080/roller/socket/entry/punch_in_juddi.html Punch in jUDDI Brian Peter Clark 2006-07-09T06:16:06+01:00 2007-09-10T19:20:06+01:00 <p>This is a brief description of how to set up UDDI4J to communicate with a UDDI registry.</p> <p>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.</p> <p>For Axis, the following line of code should be used:</p> <p>System.setProperty("org.uddi4j.TransportClassName","org.uddi4j.transport.ApacheAxisTransport");</p> <p>Each transport option introduces its own set of dependencies. For Axis, the following resources should be on the classpath.</p> <p>uddi4j.jar<br/> axis.jar<br/> jaxrpc.jar<br/> saaj.jar<br/> jax-runtime.jar<br/> jax-rpi.jar<br/> commons-logging-1.0.4.jar<br/> commons-discovery-0.2.jar<br/> commons-httpclient-3.0-rc2.jar<br/> the five javamail jars<br/> activation.jar (JAF 1.1)</p> <p>These are the import statements I have used in my main class:</p> <p>import org.uddi4j.client.*;<br/> import org.uddi4j.datatype.*;<br/> import org.uddi4j.response.*;<br/> import org.uddi4j.util.*;<br/> import org.uddi4j.transport.*;<br/> import org.uddi4j.*;<br/> import org.uddi4j.datatype.business.*;<br/> import org.uddi4j.datatype.tmodel.*;<br/> import org.apache.axis.transport.*;<br/> import javax.xml.rpc.*;<br/> import javax.xml.soap.*;<br/> import org.apache.commons.logging.*;<br/> import javax.mail.internet.*;<br/> import javax.activation.*;<br/> import java.net.*;</p> <p>Here's a couple of basic Java classes to start playing around with:</p> <p>/**<br/> * <br/> * Main class for fiddling around with jUDDI.<br/> * <br/> * @author Clayton Moore<br/> * @version 0.7.0<br/> */<br/> public class UddiManager {</p> <p> UDDIProxy uddiProxy;<br/> SocketBusinessManager socketBusinessManager;</p> <p> public UddiManager() {</p> <p> //Sets SOAP transport system to Axis (alternatives are Apache Soap <br/> //and HPSoap.<br/> System.setProperty("org.uddi4j.TransportClassName","org.uddi4j.transport.ApacheAxisTransport");</p> <p> //Create a new UDDIProxy object on which all the UDDI methods can<br/> //be called.<br/> uddiProxy = new UDDIProxy();</p> <p> //Class to carry out some basic businessEntity functions<br/> socketBusinessManager = new SocketBusinessManager(uddiProxy);</p> <p> //Set publish and inquiry URLs: publish should be https, which <br/> //would require the use of JSSE.</p> <p> //Change localdomain to the domain name and path to the UDDI<br/> //implementation. <br/> uddiProxy.setPublishURL("http://localdomain/juddi/publish");<br/> uddiProxy.setInquiryURL("http://localdomain/juddi/inquiry");<br/> }</p> <p> public static void main(String[] args) {</p> <p> UddiManager uddiManager = new UddiManager();</p> <p> try<br/> {<br/> AuthToken token = null;<br/> //All publish operations on a jUDDI must be accompanied by <br/> //an authorisation token, a sort of mini-session object.<br/> token = uddiManager.uddiProxy.get_authToken("juddi", "juddi");</p> <p> System.out.println("Token received: " + token.getAuthInfoString());</p> <p> //Tokens will time out, but best create a new one for each task<br/> //or set of related tasks and invalidate the token afterwards.<br/> //This obviously means that no-one else can use it.</p> <p> //uddiManager.uddiProxy.discard_authToken(token.getAuthInfoString());<br/> //System.out.println("Token invalidated: " + token.getAuthInfoString());</p> <p> uddiManager.socketBusinessManager.addBusiness("SOCKET-Leeds", token);</p> <p> System.out.println("New business created.");</p> <p> }<br/> catch (TransportException ex)<br/> {<br/> System.out.println("We have a transport exception.");<br/> }<br/> catch (UDDIException ex)<br/> {<br/> System.out.println("We have a UDDI exception.");<br/> System.out.println(ex.toString());<br/> }</p> <p> }<br/> }</p> <p>Some of the code in the next class is taken from<br/> http://www-128.ibm.com/developerworks/webservices/library/ws-uddi4j.html?dwzone=webservices</p> <p>Doug Tidwell: UDDI4J Matchmaking for Web Services, Jan 2001.</p> <p>import java.util.ArrayList;<br/> import org.uddi4j.client.UDDIProxy;<br/> import java.util.Vector;<br/> import org.uddi4j.transport.*;<br/> import org.uddi4j.*;<br/> import org.uddi4j.datatype.business.BusinessEntity;<br/> import org.uddi4j.response.AuthToken;<br/> import org.uddi4j.response.BusinessDetail;<br/> import org.uddi4j.response.BusinessList;<br/> import org.uddi4j.response.BusinessInfo;<br/> import org.uddi4j.response.DispositionReport;</p> <p>/**<br/> * Class for carrying out basic business entity functions.<br/> *<br/> * @author Clayton Moore<br/> * @version 0.7.0<br/> */<br/> public class SocketBusinessManager<br/> {<br/> private UDDIProxy uddiProxy;</p> <p> public SocketBusinessManager()<br/> {<br/> }</p> <p> public SocketBusinessManager(UDDIProxy uddiProxy)<br/> {<br/> this.uddiProxy = uddiProxy;<br/> }</p> <p> public void addBusiness(String businessName, AuthToken token) <br/> {<br/> Vector entities = new Vector();</p> <p> BusinessEntity be = new BusinessEntity();</p> <p> Vector businessNames = new Vector();</p> <p> Name name = new Name(businessName);</p> <p> businessNames.add(name);</p> <p> be.setNameVector(businessNames);</p> <p> entities.addElement(be);</p> <p> try<br/> {</p> <p> BusinessDetail bd = uddiProxy.save_business(token.getAuthInfoString(),<br/> entities);</p> <p> Vector businessEntities = bd.getBusinessEntityVector();</p> <p> BusinessEntity returnedBusinessEntity = (BusinessEntity)(businessEntities.elementAt(0));</p> <p> System.out.println("Returned businessKey:" + returnedBusinessEntity.getBusinessKey());</p> <p> }<br/> catch (TransportException ex)<br/> {<br/> } <br/> catch (UDDIException ex)<br/> {<br/> }<br/> }<br/> }</p>