import weblogic.uddi.client.service.Inquiry;
import weblogic.uddi.client.service.Publish;
import weblogic.uddi.client.structures.exception.UDDIException;
import weblogic.uddi.client.structures.exception.XML_SoapException;
import weblogic.uddi.client.structures.datatypes.AccessPoint;
import weblogic.uddi.client.structures.datatypes.Address;
import weblogic.uddi.client.structures.datatypes.AddressLine;
import weblogic.uddi.client.structures.datatypes.AuthInfo;
import weblogic.uddi.client.structures.datatypes.BindingKey;
import weblogic.uddi.client.structures.datatypes.BindingTemplate;
import weblogic.uddi.client.structures.datatypes.BindingTemplates;
import weblogic.uddi.client.structures.datatypes.BusinessEntity;
import weblogic.uddi.client.structures.datatypes.BusinessKey;
import weblogic.uddi.client.structures.datatypes.BusinessService;
import weblogic.uddi.client.structures.datatypes.BusinessServices;
import weblogic.uddi.client.structures.datatypes.CategoryBag;
import weblogic.uddi.client.structures.datatypes.Contact;
import weblogic.uddi.client.structures.datatypes.Contacts;
import weblogic.uddi.client.structures.datatypes.Description;
import weblogic.uddi.client.structures.datatypes.DiscoveryURL;
import weblogic.uddi.client.structures.datatypes.DiscoveryURLs;
import weblogic.uddi.client.structures.datatypes.Email;
import weblogic.uddi.client.structures.datatypes.FindQualifier;
import weblogic.uddi.client.structures.datatypes.FindQualifiers;
import weblogic.uddi.client.structures.datatypes.HostingRedirector;
import weblogic.uddi.client.structures.datatypes.IdentifierBag;
import weblogic.uddi.client.structures.datatypes.InstanceDetails;
import weblogic.uddi.client.structures.datatypes.InstanceParms;
import weblogic.uddi.client.structures.datatypes.KeyValue;
import weblogic.uddi.client.structures.datatypes.KeyedReference;
import weblogic.uddi.client.structures.datatypes.Name;
import weblogic.uddi.client.structures.datatypes.OverviewDoc;
import weblogic.uddi.client.structures.datatypes.OverviewURL;
import weblogic.uddi.client.structures.datatypes.Phone;
import weblogic.uddi.client.structures.datatypes.ServiceKey;
import weblogic.uddi.client.structures.datatypes.TModel;
import weblogic.uddi.client.structures.datatypes.TModelBag;
import weblogic.uddi.client.structures.datatypes.TModelInstanceDetails;
import weblogic.uddi.client.structures.datatypes.TModelInstanceInfo;
import weblogic.uddi.client.structures.datatypes.TModelKey;
import weblogic.uddi.client.structures.datatypes.UploadRegister;
import weblogic.uddi.client.structures.datatypes.BusinessInfo;
import weblogic.uddi.client.structures.datatypes.BusinessInfos;
import weblogic.uddi.client.structures.datatypes.ErrInfo;
import weblogic.uddi.client.structures.datatypes.Result;
import weblogic.uddi.client.structures.datatypes.ServiceInfo;
import weblogic.uddi.client.structures.datatypes.ServiceInfos;
import weblogic.uddi.client.structures.datatypes.TModelInfo;
import weblogic.uddi.client.structures.datatypes.TModelInfos;
import weblogic.uddi.client.structures.request.DeleteBinding;
import weblogic.uddi.client.structures.request.DeleteBusiness;
import weblogic.uddi.client.structures.request.DeleteService;
import weblogic.uddi.client.structures.request.DeleteTModel;
import weblogic.uddi.client.structures.request.DiscardAuthToken;
import weblogic.uddi.client.structures.request.FindBinding;
import weblogic.uddi.client.structures.request.FindBusiness;
import weblogic.uddi.client.structures.request.FindService;
import weblogic.uddi.client.structures.request.FindTModel;
import weblogic.uddi.client.structures.request.GetAuthToken;
import weblogic.uddi.client.structures.request.GetBindingDetail;
import weblogic.uddi.client.structures.request.GetBusinessDetail;
import weblogic.uddi.client.structures.request.GetBusinessDetailExt;
import weblogic.uddi.client.structures.request.GetRegisteredInfo;
import weblogic.uddi.client.structures.request.GetServiceDetail;
import weblogic.uddi.client.structures.request.GetTModelDetail;
import weblogic.uddi.client.structures.request.SaveBinding;
import weblogic.uddi.client.structures.request.SaveBusiness;
import weblogic.uddi.client.structures.request.SaveService;
import weblogic.uddi.client.structures.request.SaveTModel;
import weblogic.uddi.client.structures.request.ValidateCategorization;
import weblogic.uddi.client.structures.response.AuthToken;
import weblogic.uddi.client.structures.response.BindingDetail;
import weblogic.uddi.client.structures.response.BusinessDetail;
import weblogic.uddi.client.structures.response.BusinessDetailExt;
import weblogic.uddi.client.structures.response.BusinessList;
import weblogic.uddi.client.structures.response.DispositionReport;
import weblogic.uddi.client.structures.response.RegisteredInfo;
import weblogic.uddi.client.structures.response.ServiceDetail;
import weblogic.uddi.client.structures.response.ServiceList;
import weblogic.uddi.client.structures.response.TModelDetail;
import weblogic.uddi.client.structures.response.TModelList;
import java.util.Vector;
public class TestClientWebPub{
private static Inquiry inq;//创建查询对象
private static Publish pub;//创建发布对象
public TestClientWebPub()
{
inq = new Inquiry();
pub = new Publish();
}
public static void main(String arg[]){
System.out.println("\nTesting clientP.......\n");
TestClientWebPub t = new TestClientWebPub();
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
inq.setURL("http://localhost:7001/uddi/uddilistener");//设置查询地址:weblogic提供的UDDI注册中心
pub.setURL("http://localhost:7001/uddi/uddilistener");//设置发布地址:weblogic提供的UDDI注册中心
// t.addBusiness();//向uddi中添加一个企业实体并注册相关信息。
// t.testSaveBusiness();//通过指定的bussinessKey来,更新企业实体对象的名称等信息
// t.testSaveService();//根据指定的BusinessKey来设定服务,自动生成serviceKey和bindingKey,设定TModelKey
// t.testDelService();//删除发布的web服务
t.testDelBusiness();//删除一个企业商业实体
}
private AuthInfo testLogin() throws Exception//对于发布服务而言,都需要进行用户验证
{
GetAuthToken gat = new GetAuthToken();//获得一个验证token
gat.setUserID("gaolong1");//用户名
gat.setCred("19831001");//密码
AuthToken at = pub.getAuthToken(gat);
AuthInfo ai = at.getAuthInfo();
return ai;//返回用户验证信息
}
private void testLogout(AuthInfo ai) throws Exception
{
//清除当前用户的验证信息
DiscardAuthToken dat = new DiscardAuthToken();
dat.setAuthInfo(ai);
pub.discardAuthToken(dat);
}
/*向uddi中添加一个企业实体并注册相关信息
思路:
创建AuthInfo对象获得用户验证信息,创建Contact设置合约信息并添加到合约对象Contactz,创建BussinessEntity对象,
设定其相关信息,创建SaveBussiness对象,附上用户验证信息,登记注册者并调用publish.saveBussiness()完成注册商业实体。
运行结果:
Testing clientP.......
Logging in ..... Done : 3D9E891A-FFA6-EB10-ED55-AC93E707B716
Done.
Done.
Info on business saved :
Name = sharetop.com
Key = 515cf23e-cebd-4b08-9740-00ad7df85d2f
Logging out ..... Done.
请按任意键继续. . .
*/
private void addBusiness()
{
try{
System.out.print("Logging in ..... ");
AuthInfo ai = testLogin();//获得用户验证信息
System.out.println("Done : "+ ai.getValue());
Contact contact = new Contact();//定义合约信息
contact.addDescription("yancheng contact");
contact.addEmail("webmaster@sharetop.com");
contact.addPhone("1012032");
Address ad=new Address();
ad.addAddressLine("biti");
contact.addAddress(ad);
contact.setPersonName("gaolong1");
Contacts contacts = new Contacts();
contacts.addContact(contact);//添加合约信息
BusinessEntity bEntity = new BusinessEntity();//注册商业实体的信息
bEntity.setName(new Name("sharetop.com"));//组织或商业实体名
bEntity.addDescription("sharetop software studio");
bEntity.setAuthorizedName("gaolong1");//发布bussiness数据的个人的通过验证的名称
bEntity.setOperator("gaolong1");//操作者节点名称
bEntity.setBusinessKey("");
bEntity.setContacts(contacts);//添加合约信息到商业实体
SaveBusiness sb = new SaveBusiness();
sb.setAuthInfo(ai);//附上用户验证信息
sb.addUploadRegister(new UploadRegister("gaolong1"));//登记注册者
sb.addBusinessEntity(bEntity);System.out.println("Done.");
BusinessDetail bdtls = pub.saveBusiness(sb);//注册商业实体
System.out.println("Done.");
/*获得一些相关信息*/
BusinessEntity be = (BusinessEntity)bdtls.getBusinessEntityVector().elementAt(0);
System.out.println("Info on business saved :");
System.out.println("Name = " + be.getName().getValue() + "\nKey = " + be.getBusinessKey());
System.out.print("Logging out ..... ");
testLogout(ai);//退出登陆
System.out.println("Done.");
}
catch(UDDIException ue)
{
System.out.println("dfdd");
System.out.println("**** UDDIEXception ***");
System.out.println("Fault Actor : " + ue.getFaultActor());
System.out.println("Fault Error : " + ue.getFaultCode());
DispositionReport dr = ue.getDispositionReport();
Vector res = dr.getResultVector();
Result r = (Result)res.elementAt(0);
ErrInfo ei = r.getErrInfo();
System.out.println("ErrInfo : "+ ei.getValue());
}
catch (XML_SoapException exp){
System.out.println("XML_SoapException");
System.out.println(exp.getMessage());
exp.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
}
/*根据提供的BussinessKey提供企业实体信息的更新
思路:创建AuthInfo对象获得用户验证信息,创建BussinessEntity对象,指定的BussinessKey,设置相关的更新信息,
创建SaveBussiness对象,附上用户验证信息,并把设置信息添加到该对象上,调用publish.saveBussiness()完成企业实体信息更新。
运行结果:
Testing clientP.......
Logging in ..... Done : 3571C00D-B7D6-9B8B-DF82-2F336E5222F3
Saving Business .....Done.
Info on business saved :
Name = JavaLab
Key = 515cf23e-cebd-4b08-9740-00ad7df85d2f
Logging out ..... Done.
请按任意键继续. . .
*/
private void testSaveBusiness()
{
try
{
System.out.print("Logging in ..... ");
AuthInfo ai = testLogin();
System.out.println("Done : "+ ai.getValue());
BusinessEntity be = new BusinessEntity();
be.setBusinessKey("515cf23e-cebd-4b08-9740-00ad7df85d2f");//根据提供的BussinessKey提供企业实体更新实体信息
be.setName("JavaLab");
be.addDescription("My New Test Description");
Vector vbe = new Vector();
vbe.add(be);
System.out.print("Saving Business .....");
SaveBusiness sb = new SaveBusiness();
sb.setAuthInfo(ai);
sb.setBusinessEntityVector(vbe);
BusinessDetail bdtls = pub.saveBusiness(sb);//实体信息更新
System.out.println("Done.");
be = (BusinessEntity)bdtls.getBusinessEntityVector().elementAt(0);
System.out.println("Info on business saved :");
System.out.println("Name = " + be.getName().getValue() + "\nKey = " + be.getBusinessKey());
// log out
System.out.print("Logging out ..... ");
testLogout(ai);
System.out.println("Done.");
}
catch(UDDIException ue)
{
System.out.println("");
System.out.println("**** UDDIEXception ***");
System.out.println("Fault Actor : " + ue.getFaultActor());
System.out.println("Fault Error : " + ue.getFaultCode());
DispositionReport dr = ue.getDispositionReport();
Vector res = dr.getResultVector();
Result r = (Result)res.elementAt(0);
ErrInfo ei = r.getErrInfo();
System.out.println("ErrInfo : "+ ei.getValue());
}
catch (XML_SoapException exp){
System.out.println("XML_SoapException");
System.out.println(exp.getMessage());
exp.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
}
/*商业服务注册与更新
思路:
创建AuthInfo对象获得用户验证信息,创建Bussiness对象,BindingTemplate对象,设定BussinessKey,Bindingkey;
如果是添加服务,使用.setServerce(""),.setBindingKey()添加空ServiceKey,空BindingKey,如果是更新服务,
就指定ServiceKey和BindingKey;创建AccessPoint对象,指定服务入口,并添加到BindingTemplate对象,创建TModelInstanceInfo
对象,设定tmodelKey,添加到创建TModelInstaceInfo对象中,然后把TModelInstaceInfo添加到BindingTemplate模板中,然后加入
到模板库BindingTemplates中,再把BindingTemplates添加到BussinessService中,创建SaveService对象,附上用户验证信息,
并添加服务信息BussinessService到该对象上,创建ServiceDetail,调用publish.saveBussiness()完成商业服务注册与更新。
运行结果:
Testing clientP.......
Logging in ..... Done : D21A644C-51BC-DBBC-A16D-49700ABF005E
Saving Service ..... Done.
Logging out ..... Done.
请按任意键继续. . .
*/
private void testSaveService()//根据指定的setBusinessKey来设定服务,自动生成serviceKey和bindingKey,设定TModelKey
{
try{
System.out.print("Logging in ..... ");
AuthInfo ai = testLogin();//获得验证信息
System.out.println("Done : "+ ai.getValue());
BusinessService bs = new BusinessService();//创建BussinessService对象
bs.setBusinessKey("515cf23e-cebd-4b08-9740-00ad7df85d2f");//设定Bussinesskey
//bs.setServiceKey("2F06C420-38E0-11D5-9E50-002035229C64");
bs.setServiceKey("");//需要根据获得的Servicekey,如果指定已有的ServiceKey,就相当于更新服务
bs.setName(new Name("Msdn Msdn Msdn Testing Service for UDDI one"));//设定服务名
bs.addDescription("Empowering people.Use this service.");
BindingTemplate btemp = new BindingTemplate();//服务绑定模板
btemp.addDescription("Testing binding template");
btemp.setBindingKey("");
AccessPoint acpt = new AccessPoint("http://localhost:7001/axis/services/HelloWorldG?wsdl", "http");//访问入口设置
btemp.setAccessPoint(acpt);
TModelInstanceInfo tminfo = new TModelInstanceInfo();
tminfo.addDescription("Sample TModelInstanceInfo Description");
tminfo.setTModelKey("UUID:68DE9E80-AD09-469D-8A37-088422BFBC36");//tmodel的中有关服务行为,服务遵循的约定以及期望找到的数据格式
TModelInstanceDetails tmidls = new TModelInstanceDetails();
tmidls.addTModelInstanceInfo(tminfo);
btemp.setTModelInstanceDetails(tmidls);//把tmodel绑定到模板
BindingTemplates btemps = new BindingTemplates();
btemps.addBindingTemplate(btemp);//添加到模板库中
bs.setBindingTemplates(btemps);
Vector bss = new Vector();
bss.add(bs);//添加到BussinessService中
System.out.print("Saving Service ..... ");
SaveService ss = new SaveService();//创建一个服务结构
ss.setAuthInfo(ai);//添加验证信息
ss.setBusinessServiceVector(bss);//添加服务信息
ServiceDetail sd = pub.saveService(ss);//发布服务,并保存
System.out.println("Done.");
System.out.print("Logging out ..... ");
testLogout(ai);//退出登陆验证
System.out.println("Done.");
}
catch(UDDIException ue)
{
System.out.println("");
System.out.println("**** UDDIEXception ***");
System.out.println("Fault Actor : " + ue.getFaultActor());
System.out.println("Fault Error : " + ue.getFaultCode());
DispositionReport dr = ue.getDispositionReport();
Vector res = dr.getResultVector();
Result r = (Result)res.elementAt(0);
ErrInfo ei = r.getErrInfo();
System.out.println("ErrInfo : "+ ei.getValue());
}
catch (XML_SoapException exp){
System.out.println("XML_SoapException");
System.out.println(exp.getMessage());
exp.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
}
/*删除发布的web 服务
思路:
创建AuthInfo对象获得用户验证信息,创建DeleteService对象,添加ServiceKey到DeleteService对象,创建DispositionReport
调用publish对象的.deleteService对象删除对应的商业服务
运行结果:
Testing clientP.......
Logging in ..... Done : 2C282FC1-0FFC-1631-B984-280BB874881E
Deleting Service .....Done.
Logging out ..... Done.
请按任意键继续. . .
*/
private void testDelService()//删除发布的web 服务
{
try
{
System.out.print("Logging in ..... ");
AuthInfo ai = testLogin();
System.out.println("Done : "+ ai.getValue());
Vector vbkeys = new Vector();
vbkeys.add(new ServiceKey("515cf23e-cebd-4b08-9740-00ad7df85d2f"));//添加需要删除的服务的serviceKey
System.out.print("Deleting Service .....");
DeleteService ds = new DeleteService();//创建删除服务对象
ds.setAuthInfo(ai);
ds.setServiceKeyVector(vbkeys);
DispositionReport drpts = pub.deleteService(ds);//删除服务
System.out.println("Done.");
System.out.print("Logging out ..... ");
testLogout(ai);
System.out.println("Done.");
}
catch(UDDIException ue)
{
System.out.println("");
System.out.println("**** UDDIEXception ***");
System.out.println("Fault Actor : " + ue.getFaultActor());
System.out.println("Fault Error : " + ue.getFaultCode());
DispositionReport dr = ue.getDispositionReport();
Vector res = dr.getResultVector();
Result r = (Result)res.elementAt(0);
ErrInfo ei = r.getErrInfo();
System.out.println("ErrInfo : "+ ei.getValue());
}
catch (XML_SoapException exp){
System.out.println("XML_SoapException");
System.out.println(exp.getMessage());
exp.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
}
/*删除发布的商业实体
思路:
创建AuthInfo对象获得用户验证信息,创建DeleteBusiness对象,添加BussinessKey到DeleteBussiness对象,
创建DispositionReport,调用publish对象的.deleteBussiness对象删除对应的商业实体
运行结果:
Testing clientP.......
Logging in ..... Done : 937B6163-4B90-ADF2-51E0-666C75F8B86B
Deleting Business .....Done.
Logging out ..... Done.
请按任意键继续. . .
*/
private void testDelBusiness()
{
try
{
System.out.print("Logging in ..... ");
AuthInfo ai = testLogin();
System.out.println("Done : "+ ai.getValue());
Vector vbkeys = new Vector();
vbkeys.add(new BusinessKey("72cc3d3b-a243-4de4-91d7-ae5ef1fedd41"));//创建删除的BussinessKey
System.out.print("Deleting Business .....");
DeleteBusiness db = new DeleteBusiness();//创建删除企业实体对象
db.setAuthInfo(ai);
db.setBusinessKeyVector(vbkeys);
// pass the structure to the publish function
DispositionReport drpts = pub.deleteBusiness(db);//删除企业服务实体
System.out.println("Done.");
// log out
System.out.print("Logging out ..... ");
testLogout(ai);
System.out.println("Done.");
}
catch(UDDIException ue)
{
System.out.println("");
System.out.println("**** UDDIEXception ***");
System.out.println("Fault Actor : " + ue.getFaultActor());
System.out.println("Fault Error : " + ue.getFaultCode());
DispositionReport dr = ue.getDispositionReport();
Vector res = dr.getResultVector();
Result r = (Result)res.elementAt(0);
ErrInfo ei = r.getErrInfo();
System.out.println("ErrInfo : "+ ei.getValue());
}
catch (XML_SoapException exp){
System.out.println("XML_SoapException");
System.out.println(exp.getMessage());
exp.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
}
}