ServiceMix环境配置
配置使用的ServiceMix版本是servicemix-3.3,在tomcat5.5以上运行。(因为依赖包大部分是需要jdk1.5)
ServiceMix有三种部署方式:单独程序方式,servlet方式,与Geronimo and JBoss.整合方式。这里主要介绍servlet方式,因为这样可以整合到任何servlet容器中。
Servlet部署需要在web.xml中配置spring加载文件,这种spring是和xbean整合的自定义配置文件。
配置文件说明:
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>ServiceMix Web Application</display-name>
<description>Deploys ServiceMix inside a Web Application</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/jmx.xml /WEB-INF/core.xml /WEB-INF/activemq.xml</param-value>
</context-param>
Spring配置文件
<context-param>
<param-name>contextClass</param-name>
<param-value>org.apache.xbean.spring.context.XmlWebApplicationContext</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Spring 监听器
<!-- servlet mappings -->
<!-- the main JMX servlet -->
<servlet>
<servlet-name>JMXServlet</servlet-name>
<servlet-class>org.apache.servicemix.web.jmx.JMXServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- the HTTP binding servlet -->
<!-- START SNIPPET: servicemix-http-->
<servlet>
<servlet-name>HttpManagedServlet</servlet-name>
<servlet-class>
org.apache.servicemix.http.HttpManagedServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
http bean组件(BC)servlet
<servlet-mapping>
<servlet-name>HttpManagedServlet</servlet-name>
<url-pattern>/jbi/*</url-pattern>
</servlet-mapping>
<!-- END SNIPPET: httpBinding -->
<servlet-mapping>
<servlet-name>JMXServlet</servlet-name>
<url-pattern>/jmx/*</url-pattern>
</servlet-mapping>
</web-app>
demo主要功能的配置在core.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
xmlns:http="http://servicemix.apache.org/http/1.0"
xmlns:my="http://servicemix.apache.org/demo/"
xmlns:foo="http://servicemix.apache.org/demo/">
<!-- the JBI container -->
<sm:container id="jbi"
rootDir="#rootDir"
useMBeanServer="true"
createMBeanServer="false"
MBeanServer="#jmxServer"
installationDirPath="#installDir"
deploymentDirPath="#deployDir"
monitorInstallationDirectory="true"
transactionManager="#transactionManager"
depends-on="broker">
<sm:activationSpecs>
<!-- an example HTTP binding for use by the SpringBindingServlet -->
<!-- START SNIPPET: http -->
<sm:activationSpec componentName="servicemix-http" service="foo:httpBinding" destinationService="foo:echo">
<sm:component>
<http:component>
<http:configuration managed="true" />
<http:endpoints>
<http:endpoint service="foo:httpBinding"
endpoint="endpoint"
targetService="foo:echo"
role="consumer"
locationURI="http://localhost/exampleUri/
配置url, 会被tomcat自动转换为serverapp/jbi/ exampleUri
"
defaultMep="http://www.w3.org/2004/08/wsdl/in-out
消息请求方式是in-out,即期望又返回消息
" />
</http:endpoints>
</http:component>
</sm:component>
</sm:activationSpec>
使用http BC,作为一个消费者(consumer)目标指向服务引擎(SE)foo:echo
<!-- END SNIPPET: http -->
<!-- a simple Echo service to test InOut message exchanges using HTTP-->
<sm:activationSpec componentName="echo" service="foo:echo" >
<sm:component>
<bean class="org.apache.servicemix.components.HelloWorldComponent">
<property name="property" value="name"/>
</bean>
</sm:component>
</sm:activationSpec>
SE foo:echo,这是一个简单的helloworld
</beans>
经过这样的配置和在web.xml中配置的servlet,那么uri pattern形如 /jbi/exampleUri会请求foo:httpBinding (BC),在ESB内部foo:httpBinding通过消息路由(normalized message router)与foo:echo通信。
Web测试页面链接为http://localhost:(tomcat端口)/ESB-ServerMix-Web/examples/
需要在firefox下测试。
测试页面使用ajax请求/jbi/exampleUri经过foo:httpBinding, foo:echo处理返回信息。