67,543
社区成员




package com.kingtake.common.util;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import managedElementManager.ManagedElementMgr_I;
import nmsSession.NmsSession_I;
import nmsSession.NmsSession_IPOA;
import notifications.EventIterator_IHolder;
import notifications.EventList_THolder;
import notifications.PerceivedSeverity_T;
import org.omg.CORBA.IntHolder;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import CosNaming.NameComponent;
import CosNaming.NamingContext;
import CosNaming.NamingContextHelper;
import CosNotification.Property;
import CosNotification.StructuredEvent;
import common.Common_IHolder;
import emsMgr.EMSMgr_I;
import emsMgr.EMS_T;
import emsMgr.EMS_THolder;
import emsSession.EmsSession_I;
import emsSession.EmsSession_IHolder;
import emsSessionFactory.EmsSessionFactory_I;
import emsSessionFactory.EmsSessionFactory_IHelper;
import equipment.EquipmentInventoryMgr_I;
import globaldefs.ProcessingFailureException;
public class CorbaClientPtnHw {
static ORB orb;
static EMSMgr_I emsMgr = null;
static EquipmentInventoryMgr_I equipmentInventoryMgr = null;
static EmsSession_I emsSession=null;
static EMS_THolder emsHolder = null;
static EMS_T ems = null;
//static EventChannel notifChannel = null;
//static EventChannelHolder chanHolder = new EventChannelHolder();
//static ConsumerAdmin cadmin = null;
static IntHolder id = null;
//static ProxySupplier baseSupplier = null;
//static StructuredProxyPushSupplier structuredProxyPushSupplier = null;
static ManagedElementMgr_I managedElementMgr=null;
//static StructuredPushConsumerImpl structProxyPushConsumer = null;
static POA rpoa = null;
static POA poa = null;
static Date start_time=new Date();
static Date end_time=new Date();
public static void testCorba() throws UnsupportedEncodingException{
//建立连接登录、建立消息通道
try {
String[] args = new String[2];
args[0] = "-ORBInitRef";
args[1] = "NameService=corbaloc::10.29.131.155:12001/NameService";
orb = org.omg.CORBA.ORB.init(args, null);
} catch (SystemException ex) {
System.out.println("初始化ORB对象异常!");
}
NamingContext namingContext = null;
org.omg.CORBA.Object objRef = null;
try {
objRef = orb.resolve_initial_references("NameService");
namingContext = NamingContextHelper.narrow(objRef);
System.out.println("获取取名字服务成功:"+namingContext);
}catch (org.omg.CORBA.ORBPackage.InvalidName ex) {
System.out.println("获取名字服务索引异常!");
ex.printStackTrace();
}
NameComponent path[] = new NameComponent[5];
path[0] = new NameComponent("TMF_MTNM","Class");
path[1] = new NameComponent("HUAWEI","Vendor");
path[2] = new NameComponent("Huawei/U2000","EmsInstance");
path[3] = new NameComponent("2.0","Version");
path[4] = new NameComponent("Huawei/U2000","EmsSessionFactory_I");
EmsSessionFactory_I emsSessionFactory_I = null;
org.omg.CORBA.Object obj = null;
try{
obj = namingContext.resolve(path);
System.out.println("obj=>"+obj);
emsSessionFactory_I = EmsSessionFactory_IHelper.narrow(obj);
System.out.println("emsSessionFactory_I=>"+emsSessionFactory_I);
}catch(Exception e){
e.printStackTrace();
}
EmsSession_IHolder sessionHolder = new EmsSession_IHolder();
//Log In and Retrieve EmsSession
try {
NmsSession_IPOA pNmsSessionServant = new NmsSessionImpl();
NmsSession_I nmsSession = pNmsSessionServant._this(orb);
//用户名,密码
if (emsSessionFactory_I != null){
emsSessionFactory_I.getEmsSession("test","test", nmsSession, sessionHolder);
System.out.println("NMSsession ---" + nmsSession.toString()+"\nVersion:"+emsSessionFactory_I.getVersion());
emsSession = sessionHolder.value;
}
else{
return;
}
}catch (globaldefs.ProcessingFailureException ex) {
System.out.println("获取EmsSession引用对象,异常!---ProcessingFailureException---");
System.out.println("可能是用户名或者密码错误,或者权限不够[Corba OSS用户],或者已登陆的用户还未退出!");
System.out.println(ex.toString());
showMessage(ex.errorReason);
}
Common_IHolder common_IHolder = new Common_IHolder();
try {
//查询网管系统中所有未结束的告警和未结束的TCA 事件
String[] excludeProbCauseList=new String[0];
PerceivedSeverity_T[] excludeSeverityList=new PerceivedSeverity_T[0];
EventList_THolder eventList=new EventList_THolder();
EventIterator_IHolder eventIt=new EventIterator_IHolder();
int how_many=10;
start_time=new Date();
emsMgr.getAllEMSAndMEActiveAlarms(excludeProbCauseList, excludeSeverityList, how_many, eventList, eventIt);
end_time=new Date();
System.out.println("getAllEMSAndMEActiveAlarms:"+start_time.toString()+"-"+end_time.toString());
StructuredEvent[] events= eventList.value;
for (int i=0;i<events.length;i++){
Property[] propertyList= events[i].filterable_data;
showMessage("event:"+i);
for (int j=0;j<propertyList.length;j++){
try{
showMessage(" "+propertyList[j].name+","+ propertyList[j].value);
Object prop_obj=propertyList[j].value.extract_Object();
}
catch(Exception e){
continue;
}
}
}
} catch (ProcessingFailureException e) {
System.out.println("Processing Exception" + e.getMessage());
e.printStackTrace();
showMessage(e.errorReason);
}
finally{
emsSession.endSession();
}
}
/**
* @param msg
* @throws UnsupportedEncodingException
* 编码转换,以显示中文
*/
public static void showMessage(String msg) throws UnsupportedEncodingException {
byte[] bytes=msg.getBytes("ISO-8859-1");
String rlt = new String(bytes, "GBK");
System.out.println(rlt);
}
public static String decodeText(String src) throws UnsupportedEncodingException {
byte[] bytes=src.getBytes("ISO-8859-1");
String rlt = new String(bytes, "GBK");
return rlt;
}
public static void main(String[] args) throws UnsupportedEncodingException {
testCorba();
}
}
szbszb大侠,你好!想问下,你的程序,架构是怎么生成的。经理让我写个程序,能够连接华为U2000告警系统的Corba接口,获得数据。我在网上搜得,需要根据idl文件生成,基本架构其中包含可以调用的接口。可经理给我的资料里面没有idl文件,只有一个接口用户指南。联系华为的人,他说也不清楚什么idl文件,所以想问下大侠,是不是要根据idl文件才能生成基本的项目结构,再添加业务操作的?idl从哪儿来的?你程序里面的接口都是从哪来的。大侠,拜托了,真的好无助啊,大侠帮帮忙啊。