osgi1——camel与cxf发布webservice

经过三个月的osgi学习,今天打算总结一下osgi与blueprint结合,并且使用camel、cxf等框架去做ESB.

camel是apache下面一个非常著名的框架,定义了一套路由规则,他的根本原理就是,一端进来——处理——另外一端出去,基于这个高度抽象模型,他扩展的范围非常广,可以去整合HTTPActiveMQJMSJBI, 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.xsd
http://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.xsd
http://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软件测试






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值