osgi1——camel与cxf发布webservice
来源:互联网 发布:淘宝开店要注册商标吗 编辑:程序博客网 时间:2024/06/14 10:58
经过三个月的osgi学习,今天打算总结一下osgi与blueprint结合,并且使用camel、cxf等框架去做ESB.
camel是apache下面一个非常著名的框架,定义了一套路由规则,他的根本原理就是,一端进来——处理——另外一端出去,基于这个高度抽象模型,他扩展的范围非常广,可以去整合HTTP, ActiveMQ, JMS, JBI, SCA, MINA or CXF, WD等等。并且实现也非常简单,他可以用spring或者blueprint去简单配置即可使用。
首先先了解下camel与cxf发布webservice
webservice经常用于ESB,如果不用框架自己去实现的话会非常麻烦,所以我们要站在巨人的肩膀上去实现。请看下面blueprint.xml配置
<?xml version="1.0" encoding="UTF-8"?><blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:camel-cxf="http://camel.apache.org/schema/blueprint/cxf" xmlns:cxfcore="http://cxf.apache.org/blueprint/core" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/xmlns/jpa/v1.1.0 http://aries.apache.org/schemas/jpa/jpa_110.xsd http://aries.apache.org/xmlns/transactions/v1.0.0 http://aries.apache.org/schemas/transaction/transactionv10.xsdhttp://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsdhttp://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"><!--Web service--> <camel-cxf:cxfEndpoint id="myService" address="http://0.0.0.0:8018/myosgi/camelwebservice" serviceClass="com.cn.yyc.osgi.imywebservice" bindingId="http://www.w3.org/2003/05/soap/bindings/HTTP/"> <camel-cxf:properties> <entry key="dataFormat" value="POJO"/> </camel-cxf:properties> </camel-cxf:cxfEndpoint> <bean id="test1" class="com.cn.yyc.Test1"/> <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/blueprint" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> <route > <from uri="myService" /> <log message="Request:${in.header.operationName}"/> <choice> <when> <simple>${in.header.operationName} == 'test1'</simple> <to uri="bean:test1"/> </when> <otherwise><to uri="bean:test"/></otherwise> </choice></route> </camelContext></blueprint>上面配置中serviceClass的配置是一个接口,接口方法中可以定义接受的webservice参数和返回的参数,下面路由节点to到一个资源的时候,可以到很多地方,如果到bean的话,那么类就需要继承org.apache.camel.Processor,实现process方法
import org.apache.camel.Exchange;import org.apache.camel.Processor;/** * * @author Administrator */public class Test1 implements Processor{ @Override public void process(Exchange exchange) throws Exception { Response response=new Response(); exchange.getOut().setBody(response); } }
因此pom.xml,文件需要引入依赖
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.0.4</version>
<type>jar</type>
</dependency>
maven打包成bundle的时候,需要配置如下
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>deploy</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> <configuration> <skip>false</skip> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.10.3</version> <configuration> <aggregate>true</aggregate> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7.2</version> <configuration> <skip>false</skip> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <Class-Path>.</Class-Path> <Built-By>yyc</Built-By> <Bundle-ManifestVersion>2</Bundle-ManifestVersion> <Bundle-Name>${project.groupId}.${project.ArtifactId}</Bundle-Name> <Bundle-SymbolicName>${project.groupId}.${project.ArtifactId}</Bundle-SymbolicName> <Bundle-Version>${project.version}</Bundle-Version> <Bundle-Vendor>${project.groupId}</Bundle-Vendor> <Import-Package> org.osgi.framework,org.slf4j,org.apache.camel,org.apache.cxf.message </Import-Package> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build>
可以将打包好的jar包放入servicemix运行,即可拿soapui软件测试
- osgi1——camel与cxf发布webservice
- Spring与CXF结合发布WebService
- WebService —— JAX-WS 与 CXF
- Hello Mr.J——用CXF框架发布WebService
- cxf发布webservice与java客户端解析webservice
- cxf-dosgi 发布webservice
- cxf+spring发布webservice
- cxf发布webservice
- cxf+spring发布webservice
- CXF发布webservice入门
- Mule发布webservice--cxf
- CXF方式发布WebService
- cxf发布webservice
- cxf发布webservice
- cxf发布webservice
- cxf发布webservice 服务
- spring +cxf 发布webservice
- 使用CXF发布webService
- 非Windows平台的一个简单的开源的Rust IDE:SolidOak
- Java中的参数传递方式
- java实现字符串逆转
- C语言中32位和64位的数据类型长度
- 悠悠古舟渡,浅浅时光去
- osgi1——camel与cxf发布webservice
- 单双列集合
- 双击退出程序
- 【Python】 天气查询
- 系统签名 sharedUserId android.uid.system
- android.graphics.drawable.Drawable注释翻译
- Java集合使用
- Insertion Sort List
- UITextField