环境:juddiv3+tomcat6.0+MySQL5.1+MyEclipse7.5
WSDL在UDDI中的注册:
我们有两种方法和UDDI进行通信:
一、用soapui工具直接编写SOAP消息和UDDI进行通信(它是Eclipse的一个插件);
二、通过编程进行通信。(UDDI4J是一个UDDI编程接口,但是只支持UDDIv2,对v3不支持。所以只能自己编写。)
下面是自己编写的把一个WSDL文件发布到UDDI注册中心的一段代码:
在该项目下需要加入juddiv3的lib下的jar包(需要在该项目下建一个/META-INF/uddi.xml)。
uddi.xml的内容为:
5000
default
Main jUDDI node
org.apache.juddi.v3.client.transport.JAXWSTransport
{serverName}:${serverPort}/juddiv3/services/custody-transfer?wsdl
{serverName}:${serverPort}/juddiv3/services/inquiry?wsdl
{serverName}:${serverPort}/juddiv3/services/publish?wsdl
{serverName}:${serverPort}/juddiv3/services/security?wsdl
{serverName}:${serverPort}/juddiv3/services/subscription?wsdl
{serverName}:${serverPort}/juddiv3/services/subscription-listener?wsdl
{serverName}:${serverPort}/juddiv3/services/juddi-api?wsdl
med
jUDDI node in other Department
org.apache.juddi.v3.client.transport.JAXWSTransport
http://med:8080/juddiv3/services/custody-transfer?wsdl
http://med:8080/juddiv3/services/security?wsdl
客户端代码为:
package com.juddiv3;
import org.apache.juddi.ClassUtil;
import org.apache.juddi.v3.client.config.UDDIClientContainer;
import org.apache.juddi.v3.client.transport.Transport;
import org.uddi.v3_service.UDDISecurityPortType;
import org.uddi.api_v3.GetAuthToken;
import org.uddi.api_v3.AuthToken;
import org.uddi.v3_service.UDDIPublicationPortType;
import org.uddi.api_v3.SaveBusiness;
import org.uddi.api_v3.BusinessEntity;
import org.uddi.api_v3.DiscoveryURLs;
import org.uddi.api_v3.DiscoveryURL;
import org.uddi.api_v3.Name;
import org.uddi.api_v3.SaveTModel;
import org.uddi.api_v3.TModel;
import org.uddi.api_v3.TModelDetail;
import org.uddi.api_v3.Description;
import org.uddi.api_v3.OverviewDoc;
import org.uddi.api_v3.OverviewURL;
import org.uddi.api_v3.TModelInstanceInfo;
import org.uddi.api_v3.TModelInstanceDetails;
import org.uddi.api_v3.BusinessService;
import org.uddi.api_v3.BusinessServices;
import org.uddi.api_v3.BindingTemplate;
import org.uddi.api_v3.BindingTemplates;
import org.uddi.api_v3.AccessPoint;
public class juddivClient {
public static void main(String args[])
{
try
{
String clazz = UDDIClientContainer.getDefaultTransportClass();
Class>transportClass=ClassUtil.forName(clazz, Transport.class);
if(transportClass!=null)
{
//获得authtoken
Transport transport=(Transport)transportClass.newInstance();
UDDISecurityPortType securityService=transport.getUDDISecurityService();
GetAuthToken getauthToken=new GetAuthToken();
getauthToken.setUserID("root");
getauthToken.setCred("root");
AuthToken authtoken=securityService.getAuthToken(getauthToken);
String authinfo=authtoken.getAuthInfo();
System.out.println(authinfo);
UDDIPublicationPortType publication = transport.getUDDIPublishService();
SaveBusiness sb = new SaveBusiness();
//添加BusinessEntity
BusinessEntity be=new BusinessEntity();
DiscoveryURLs urls=new DiscoveryURLs();
DiscoveryURL url=new DiscoveryURL();
url.setValue("");
urls.getDiscoveryURL().add(url);
be.setDiscoveryURLs(urls);
Name name=new Name();
name.setValue("TicketBooking");
be.getName().add(name);
//添加tModel
SaveTModel ST=new SaveTModel();
ST.setAuthInfo(authinfo);
TModel tm=new TModel();
Name n=new Name();
n.setValue("");
tm.setName(n);
Description des=new Description();
des.setValue("Ticket");
tm.getDescription().add(des);
OverviewDoc od=new OverviewDoc();
OverviewURL ou=new OverviewURL();
ou.setValue("");
od.setOverviewURL(ou);
tm.getOverviewDoc().add(od);
ST.getTModel().add(tm);
TModelDetail Tt=publication.saveTModel(ST);
//添加BusinessService;
BusinessServices bss=new BusinessServices();
BusinessService bs=new BusinessService();
Name na=new Name();
na.setValue("Ticket");
bs.getName().add(na);
BindingTemplate bt=new BindingTemplate();
BindingTemplates bts=new BindingTemplates();
AccessPoint ap=new AccessPoint();
ap.setUseType("http");
ap.setValue("");
bt.setAccessPoint(ap);
TModelInstanceDetails TD=new TModelInstanceDetails();
TModelInstanceInfo TI=new TModelInstanceInfo();
TI.setTModelKey(Tt.getTModel().get(0).getTModelKey());
TD.getTModelInstanceInfo().add(TI);
bt.setTModelInstanceDetails(TD);
bts.getBindingTemplate().add(bt);
bs.setBindingTemplates(bts);
bss.getBusinessService().add(bs);
be.setBusinessServices(bss);
sb.setAuthInfo(authinfo);
sb.getBusinessEntity().add(be);
publication.saveBusiness(sb);
System.out.println("注册成功");
}
else
{
System.out.println("false!!!");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
阅读(3023) | 评论(0) | 转发(0) |