juddiv3 tmodel的代码

环境: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)。

import junit.framework.Assert;
import org.junit.Test;
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 test3 {
     
 @Test
 public void testAuthToken()
 {
  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(" http://www.xiaozhan.com ");
          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("http://www.tour.com ");
          tm.setName(n);
          Description des=new Description();
          des.setValue("Ticket");
          tm.getDescription().add(des);
          OverviewDoc od=new OverviewDoc();
          OverviewURL ou=new OverviewURL();
          ou.setValue("http://localhost:8080/axis2/services/Ticket?wsdl ");
          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(" http://localhost:8080/axis2/services/Ticket.TicketHttpSoap11Endpoint/ ");
          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);
      }
      else
      {
       Assert.fail();
      }
  }
  catch(Exception e)
  {
   e.printStackTrace();
   Assert.fail("Could not obtain authInfo token.");
  }
 }
 
}

你可能感兴趣的:(Model)