现在的位置: 首页 > 综合 > 正文

你所了解的ESB项目

2018年04月10日 ⁄ 综合 ⁄ 共 4658字 ⁄ 字号 评论关闭

2011.7-2011.10

根据公司的调整,介入到当时命名为ESB的项目中。只知其名,不明其意的我看了一下这里
http://baike.baidu.com/view/1224042.htm
呵呵,企业服务总线,看来有点东西。

 

自己进入之后,开始熟悉业务流程,然后步入开发,因为这个项目已经启动一段时间了。很多都已经有模型之类的东东了。自己负责订阅(创建、注册)服务一块的开发,比如自己创建,wsdl文件导入,wsdl连接创建等等方式

开发工具:SpringSource Tool Suite

这个有整体架构了,当时在公司还是挺看重的一个项目。

第一张,被命名为建设图

再来一张项目模块

大体的东西看到了,最终要总结的还是自己在这个项目中收获了什么?

1.       Struts2的validate()拦截、校验 validate介绍

2.      MD5加密

3.      Fusioncharts 点击打开链接

4.      程序分页

5.      WebService

6.      Spring Roo Project

7.      枚举的作用

8.      Zookeeper
zookeeper百科
  http://zookeeper.apache.org/

9.      Ajax异步请求

10.  心跳监控、请求报文、压力测试、jira管理bug、wsdl解析等好多以前没有接触过的

心跳监控:其中一种方式,每隔一段时间去请求监控的服务器,看是否有相应,来判断是否存活。

请求报文:http里的请求信息

压力测试:jmeter进行多线程并发访问

bug管理:jira

-------------------------------------分割一下呗-------------------------------

当时突然感觉知识爆棚,还来不急消化。大笑

下面也重要讲一下wsdl的解析吧

http://www.w3.org/TR/wsdl
这个是wsdl在w3c上面的介绍,有兴趣可以看看。

下面,show一段解析的java代码:

import javax.wsdl.Definition;
import javax.wsdl.Port;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;

       /*首先实例一个解析WSDL的工厂*/
        WSDLFactory factory = WSDLFactory.newInstance();
        /*设置解析器*/
        WSDLReader reader = factory.newWSDLReader();
        /*设置一些必要属性*/
        reader.setFeature("javax.wsdl.verbose", true);
        reader.setFeature("javax.wsdl.importDocuments", true);
        /*进行读http://localhost:8080/?wsdl*/
        Definition def = reader.readWSDL(wsdl);
        /*获取服务*/
        Map mapService = def.getServices();
        Iterator services = mapService.values().iterator();
        Service service = null;
        /*获取文档结构*/
        Element e1 = (Element) def.getDocumentationElement();
        // 加入 Documentation
        if (e1 != null) {
            wsd.setDocumentation(e1.getTextContent());
        } else {
            wsd.setDocumentation("NONE");
        }
       
        while (services.hasNext()) {
            service = (Service) services.next();
        }
        // 加入 Service
        wsd.setService(service.getQName().getLocalPart() + "[" + service.getQName().getNamespaceURI() + "]");
       /*获取端口*/
        Map ports = service.getPorts();
        Iterator iterPort = ports.values().iterator();

下面一段是对ports的迭代处理,再show一下:

            port = (Port) iterPort.next();
            // 加入Port
            wsdld.setPort(port.getName());
            
            List l = port.getExtensibilityElements();
            ExtensibilityElement element = (ExtensibilityElement) l.get(0);
            String s = element.toString();
            // 加入 Address
            wsdld.setAddress((s.substring(s.indexOf("location"))).substring(12));
            
            ExtensibilityElement e = (ExtensibilityElement) port.getExtensibilityElements().get(0);
            // 获取soap的版本
            String soapVersion = getSoapVersion(e.getElementType().getNamespaceURI());
            // 加入soapVersion
            wsdld.setSoapVersion(soapVersion);
            
            Map mapBind = def.getBindings();
            
            Iterator iterBind = mapBind.values().iterator();
            
            BindingImpl bindingImpl = (BindingImpl) iterBind.next();
            // 加入Binding
            wsdld.setBinding(bindingImpl.getQName().getLocalPart() + "[" + bindingImpl.getQName().getNamespaceURI() + "]");
            int leng = bindingImpl.getBindingOperations().size();
            // 加入PortType
            wsdld.setPortType(bindingImpl.getPortType().getQName().getLocalPart() + "[" + bindingImpl.getPortType().getQName().getNamespaceURI() + "]");
            
            for (int i = 0; i < leng; i++) {
                BindingOperationImpl ss = (BindingOperationImpl) bindingImpl.getBindingOperations().get(i);
                // 加入方法
                lm.add(ss.getName());
            }

通过上面的解析,最终我们会获得一下自己应用所想要的信息,这些信息包括:

  • Types– a container for data type definitions using some type system (such as XSD).
  • Message– an abstract, typed definition of the data being communicated.
  • Operation– an abstract description of an action supported by the service.
  • Port Type–an abstract set of operations supported by one or more endpoints.
  • Binding– a concrete protocol and data format specification for a particular port type.
  • Port– a single endpoint defined as a combination of a binding and a network address.
  • Service– a collection of related endpoints.

针对WSDL的一些框架,xfire,Axis2等发表WebService,生成Wsdl文件,有时间应该弄一个专题说说。

-------------------------------分割一下呗---------------------------------------得意

再说一个Struts2的validate()方法校验吧,那还是先show出代码,比较简单:

        @Override
	public void validate(){
		if(addOrUpdate==null){
		    //使用默认的
			super.validate();
		}else{
			//当添加,修改proxyService的时候,判断node、endpoint是否重复
			//且struts拦截时,让已经输入的node、endpoint不被置为null
			Boolean node =nodeRepeat();
			Boolean endpoint = endpoitExistOrRepeat();
			if(node||endpoint){
			    //设置一个标志变量
				update = true;
			}
		}
	}

只需要重写一下com.opensymphony.xwork2.ActionSupport的方法,加入自己的业务判断,这个还是比较靠谱简单。

不过Struts2的东西好用,当都是有配置的,配置如下:

文件名ServiceAction-save-validation.xml

内容

<validators>
	<field name="proxyService">
		<field-validator type="visitor">
			<param name="context">service</param>
			<param name="appendPrefix">true</param>
			<message>ProxyService'</message>
		</field-validator>
	</field>
</validators> 

针对proxyService变量做校验,这里是一个对象。大家可以看看文件名是很有意思的,而且还必须放在和类同样的包路径下,才生效。

下面展示所对应的Action配置:

<action name="save" class="serviceAction" method="addProxyService">
	<result name="success" type="redirect">list.action</result>
	<result name="input">/WEB-INF/jsp/service/service_addedit.jsp</result>
</action>

成功后,就跳转到List.action里面去,没通过校验就到添加\编辑页。

最后,来点总结:

发现好多东西,可以写成一个系列慢慢来讲,看来时间也不够,光靠闲暇时间回忆,毕竟好多东西还是有限的。

不过,好多东西,都有个印象,有过了解,再温故一下,上手也应该蛮容易的。

抱歉!评论已关闭.