欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

servicemix 7安装使用及camel-cxf代理webservice 博客分类: servicemix  

程序员文章站 2024-02-12 20:13:22
...
前述:之前用servicemix3通过jbi代理webservice。由于smx版本升级较快,smx7已经弃用了jbi,转而通过camel转换协议。

servicemix 3安装及cxf-bc组件代理webservice服务
http://newjava-sina-cn.iteye.com/blog/2357092

这边文章主要是学习通过camel代理ws的学习过程。


1.安装使用servicemix7

2.camel-cxf代理webservice

3.常用命令





1.安装使用servicemix7
下载servicemix:
http://servicemix.apache.org/downloads/servicemix-7.0.0.M2.html

解压到某个路径下,如:D:\service\apache-servicemix-7.0.0.M2

配置系统变量 SERVICEMIX_HOME=D:\service\apache-servicemix-7.0.0.M2

进入bin目录下,运行servicemix.bat便可启动servicemix

servicemix 7安装使用及camel-cxf代理webservice
            
    
    博客分类: servicemix  

通过console shell,可以查看特性或控制servicemix,如:
bundle:list                    显示已安装的组件
bundle:list | grep camel       查找特定组件
log:display                    查看日志
log:display | grep DEBUG       查找debug日志
log:set INFO                   设置日志级别
feature:list                   查看特性(包括已安装和未安装)
feature:list | grep camel      查看感兴趣的特性

feature:install webconsole     安装web控制台

安装成功后,访问http://localhost:8181/system/console smx/smx。通过web页面,可以启动或停止组件,安装原有feature等。

由于安装一些组件可能要从maven库下载依赖的jar包,网速较慢。可以将maven库改成国内的(etc/org.ops4j.pax.url.mvn.cfg for the org.ops4j.pax.url.mvn.repositories)

servicemix 7安装使用及camel-cxf代理webservice
            
    
    博客分类: servicemix  




2.camel-cxf代理webservice
在eclipse新建一个普通的maven project项目(根据maven-archetype-quickstart原型)

在src/main/resources源文件下新建META-INF/spring/camel-config.xml(smx7能够识别的结构)。

配置camel-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
 
  <!-- this is the CXF web service we use as the front end -->
  <cxf:cxfEndpoint id="reportIncident"
                   address="http://0.0.0.0:8186/camel_0319_cxf/camel/CXF_HELLO_ObjectSpringService/IHello"
                   serviceName="s:HelloWorldService"
                   endpointName="s:HelloWorld" 
                   wsdlURL="http://localhost:8081/HelloWorld/services/HelloWorld?wsdl"
                   xmlns:s="http://ws.bill.com"/>
 
  <!-- this is the Camel route which proxies the real web service and forwards SOAP requests to it -->
  <camelContext xmlns="http://camel.apache.org/schema/spring">
 
    <!-- <endpoint id="callRealWebService" uri="http://localhost:${real.port}/real-webservice?throwExceptionOnFailure=false"/> --><!-- &amp; -->
    <endpoint id="callRealWebService" uri="http://localhost:8081/HelloWorld/services/HelloWorld?bridgeEndpoint=true"/>
 
    <route>
      <!-- CXF consumer using MESSAGE format -->
      <from uri="cxf:bean:reportIncident?dataFormat=MESSAGE"/> <!-- ?dataFormat=MESSAGE -->
      <setHeader headerName="SOAPAction" >
          <constant>FooSync</constant>
      </setHeader>
      <convertBodyTo type="String" />
      <!-- log input received -->
      <to uri="log:input?showHeaders=true"/>
      <!-- enrich the input by ensure the incidentId parameter is set -->
      <!-- <to uri="bean:enrichBean"/> -->
      <!-- Need to remove the http headers which could confuse the http endpoint -->
      <!-- <removeHeaders pattern="CamelHttp*"/> -->
      <!-- send proxied request to real web service -->
      <to ref="callRealWebService"/>
      <convertBodyTo type="String" />
      <!-- log answer from real web service -->
      <to uri="log:output?showHeaders=true"/>
    </route>
 
  </camelContext>
 
</beans>


注意事项:
a.该配置是根据camel官方实例(http://camel.apache.org/cxf-proxy-example.html)改造而来(见附件camel-example-cxf-proxy-2.11.1-sources.jar.7z),根据自己服务器地址设置callRealWebService的endpoint.uri

b.配置cxf:cxfendpoint端点时,xmlns:s应为自己的webservice的命令空间,wsdlUrl文件中的targetNamespace="http://ws.bill.com"。serviceName为服务的服务名,endpointName为服务的端口名

c.对于axis的ws,如果请求头部没有soapAction,则会报no soapAction header类似错误,cxf的ws不会有这个问题,可以去掉这个配置

d.读者可查询相关资料,调试route中的相关组件


配置完成后,右键项目run as - maven install 生成组件,在target文件夹下生成一个jar包,放到smx7的deploy文件夹下,自动部署完成

日志data/log/servicemix.log

访问http://localhost:8186/camel_0319_cxf/camel/CXF_HELLO_ObjectSpringService/IHello?wsdl
或通过soap-ui测试



改造实例源码,附件处可下载



3.常用命令
log:display   显示日志

feature:install camel-http





参考网站:
http://camel.apache.org/cxf-proxy-example.html

https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.0/html-single/Web_Services_and_Routing_with_Camel_CXF/index.html#Proxying-HTTP

  • servicemix 7安装使用及camel-cxf代理webservice
            
    
    博客分类: servicemix  
  • 大小: 47.8 KB
  • servicemix 7安装使用及camel-cxf代理webservice
            
    
    博客分类: servicemix  
  • 大小: 111.2 KB