文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>juddiv3的客户端代码实例

juddiv3的客户端代码实例

时间:2010-09-03  来源:feilong_zhan

环境: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.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.xiaozhu.com");
          urls.getDiscoveryURL().add(url);
          be.setDiscoveryURLs(urls);
          Name name=new Name();
          name.setValue("org.xiaozhan.test");
          be.getName().add(name);
          
          //添加BusinessService;
          BusinessServices bss=new BusinessServices();
          BusinessService bs=new BusinessService();
          Name na=new Name();
          na.setValue("MytestService");
          bs.getName().add(na);
          BindingTemplate bt=new BindingTemplate();
          BindingTemplates bts=new BindingTemplates();
          AccessPoint  ap=new AccessPoint();
          ap.setUseType("en");
          ap.setValue("http://localhost:8080/axis2");
          bt.setAccessPoint(ap);
          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.");
  }
 }
 
}
 
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载