CMDBuild安装及webservice接口的获取

近期项目组之前一直使用的OneCMDB出现了问题,在增删改数据时异常的慢。于是考虑能否够优化OneCMDB。由于本人水平有限,对OneCMDB进行代码级别的优化临时还有点难度。于是就对现有的其它开源CMDB进行调研,首先是CMDBuild(官方站点)。

对于CMDBuild,先上结论。

优缺点

长处

  • 全然自主的系统配置
  • 界面炫酷美观。AJAX让人操作十分便捷
  • 数据格式自由定制(在GLPI中。资产的数据格式都已经定义好了,用户非常难改动)
  • 有专门的团队在进行不断的维护。眼下最新的版本号是2015年6月公布的2.3.2
  • 内置工作流引擎,能够创建工作流
  • 报表系统:支持JasperReports、Alfresco
  • 提供基于SOAP和REST的webservice接口

缺点

  • 网上资料少,极其少!差点儿相同仅仅有安装的介绍!

  • 官方提供的代码演示样例差点儿没有。这让开发人员自己摸索么?还是我没找到?
  • 提供的webservice接口是wsdl和wadl形式的。不能给个jar包什么的吗?

安装

參考:
http://www.cnblogs.com/supakito/p/cmdbuild_install.html
http://20988902.blog.51cto.com/805922/1541289

安装要求

  • 硬件:
    • server-class computer (modern architecture)
    • 4GB of RAM
    • 80 GB of available hard disk space
  • 软件:
    • 不论什么支持下面应用的OS (推荐linux)
    • PostgreSQL 9.0 or higher (PostgreSQL 9.3 recommended)
    • Apache Tomcat 6.0 or higher(好像7.0不支持)
    • JDK 1.6

安装步骤

  1. 安装jdktomcat(不再赘述)
  2. 安装PostgreSQL并配置
  3. 将下载好的cmdbuild-2.3.2.zip解压,文件文件夹例如以下图所看到的,
    cmdbuild文件文件夹
  4. 将当中的cmdbuild-2.3.2.war复制到Tomcat的webapps文件夹下。将其重命名为cmdbuild.war
  5. cmdbuild-2.3.2extras omcat-libs6.0下的postgresql-9.1-901.jdbc4.jar复制到Tomcat的lib文件夹下
  6. 启动tomcat,開始解析cmdbuild.war
  7. tomcat启动成功后,在地址栏输入localhost:8080/cmdbuild,能够进入例如以下界面:
    cmdbuild配置1
  8. 点击next,进入下一个界面
    cmdbuild配置1
  9. 依照如图所看到的进行配置,能够測试下数据库连接能否够。

    假设没有错误出现。那么就能够进入到主界面了。炫酷!
    CMDBuild主界面

至此,CMDBuild的安装就完毕了。

webservice接口的获取

在找CMDBuild的接口时但是费了非常大劲,最后在一个角落里找到了一点痕迹,http://hostname:port/cmdbuild/services/rest/v1,于是依照这个地址拼接了自己的获取地址:http://localhost:8080/cmdbuild/services。就这样最终找到了所谓的webservice接口。但当中SOAP是WSDL形式的,REST是WADL形式的。

于是乎,又想着怎样将wsdl的接口变成java的。

WSDL2Java

利用jdk自带的工具wsimport.exe就能够实现:

wsimport http://127.0.0.1/TicketMobile/services/Cococ?wsdl  -keep -p com.llg.ws2 -s g:/ws

參数说明

于是。就能够将wsdl的接口变成java的,于是依照文档上的样例兴高採烈的開始写程序。。。

官方文档上仅仅有这么一点代码:

// 1. Create an instance in the ConfigurationContext class and indicate in it where the repository directory is. In the repository directory there are 2 directories: the modules directory which contains the rampart.mar file, and the conf directory which contains the file to define the safety policy which should be adopted.
ConfigurationContext configContext = ConfigurationContextFactory
        .createConfigurationContextFromFileSystem("/path/to/repository",//
                                                    null);//

// 2. Instance the WebservicesStub class moving in it the ConfigurationContext just created     
WebServicesStub stub = new WebServicesStub(configContext);

// 3.Set the authentication credentials
StAXOMBuilder builder = new StAXOMBuilder(
                            "/path/to/repository/conf/policy.xml");//
Options options = stub._getServiceClient().getOptions();
options.setUserName("username");
options.setPassword("password");
options.setProperty(//
        RampartMessageData.KEY_RAMPART_POLICY,//
        PolicyEngine.getPolicy(builder.getDocumentElement()//
            ));

// 4.Instance a GetCardList object and call the server
GetCardList list = new GetCardList();
list.setClassName("Computer");
GetCardListResponse response = stub.getCardList(list);
Card[] card = response.get_return();

// 5.At this point you can iterate on the array card content and extract the most interesting values. For example, if you want to recover the description of every Computer, the following method will be enough:
System.out.println(card[i].getDescription());

至此。官方代码提供完毕,但是WebServicesStub哪来的?其它的类还能够通过Google找到相关的jar包,但是WebServicesStub哪来的?

WebServicesStub的来头

最后。网上各种找啊,凡是相关的资料都试了。最终在stub调用WebService这里找到了管用的方法。

使用Axis2提供的wsdl2java.bat命令能够依据WSDL文件产生调用WebService的代码

详细操作,下载安装Axis2不说了。

进入到%AXIS2_HOME%in,运行

wsdl2java -uri http://localhost:8080/cmdbuild/services/soap/Webservices?wsdl -p client -s -o stub

当中-url參数指定了wsdl文件的路径,能够是本地路径,也能够是网络路径。-p參数指定了生成的Java类的包名。-o參数指定了生成的一系列文件保存的根文件夹。

在运行完上面的命令后,读者就会发如今当前文件夹下多了个stub 文件夹。在stub/src/client文件夹能够找到一个$Proxy146ServiceStub.java文件(奇怪的名字。由于提供的wsdl文件中就是这个名字),该文件复杂调用WebService。读者能够在程序中直接使用这个类。

最后的最后,最终能够用WebServicesStub了,但是问题还是有,等我先折腾折腾吧。有什么问题能够直接留言一起讨论。

总结

CMDBuild是由意大利的公司所开发的一款开源CMDB产品。网上相关的资料非常少,中文的资料就更少。仅仅有一些简单的安装介绍的文章。而关于其怎样使用的资料差点儿没有,仅仅有官方所提供的手冊。

然而其仅仅是给出了SOAP的WSDL格式的接口,并没有其它的jar文件。而且在其官方使用手冊中仅仅有简单的使用演示样例代码。对于当中一些类的来源也没有给出,没有一个完好的api开发文档,因此若要真正的使用起来尚有一定的困难,临时还不能进行代码级别的測试。

原文地址:https://www.cnblogs.com/jzssuanfa/p/7190558.html