Jboss Fuse 简明教程

JBoss Fuse - Apache CXF

在本章中,让我们讨论一下 Apache CXF 是什么,以及它如何在开发 SOAP 和 Rest Web 服务中有帮助。

What is Apache CXF?

Apache CXF 是一个 Web 服务开发框架,可用于开发 SOAP 和 Rest Web 服务。CXF 完全符合 JAX-RS and JAX-Ws 标准。

现在,它是最广泛使用的 Web 服务开发框架。 CXF 已经从 Axis2 中学习并进行了改进,现在 CXF 正在逐渐取代 Axis2。

CXF vs Axis2

CXF

Axis2

Improvements

CXF 现在是最常用的框架。它对 Axis2 进行了大量改进。

CXF 正在逐渐取代 Axis2。与 CXF 相比,它需要更多的代码。

Code required

与 Axis2 相比,CXF 需要更少的代码。

与 Axis2 相比,它需要更多的代码。

Standard Compliance

CSF 完全符合 JAX-RS 和 JAX-WS。

Axis2 并不完全符合 JAX-RS 和 JAX-WS。

Compatible with Spring

Yes

No

Separation of front-ends

与 JAX-WS 代码进行前台清洁分离。

不提供干净的分离。

SOAP

SOAP 代表简单对象访问协议。这是一种通过 Web 服务在两个系统之间交换结构化信息的协议。它主要依赖于 XML 来构建数据,并使用 HTTP 或 SMTP 来进行消息协商和传输。

有两种方法可以开发 SOAP Web 服务 −

  1. Code first − 在此方法中,WSDL 由代码生成。

  2. Contract first − 在契约优先的情况下,代码由 WSDL 生成。

SOAP Development Using CXF

Configure Maven

将以下个人资料添加到 Maven 的 settings.xml 中。

<profiles>
   <profile>
      <id>Jboss-Fuse</id>

      <activation>
         <activeByDefault>true</activeByDefault>
      </activation>

      <repositories>
         <repository>
            <id>fusesource</id>
            <url>http://repo.fusesource.com/nexus/content/groups/public/</url>
            <snapshots>
               <enabled>false</enabled>
            </snapshots>
            <releases>
               <enabled>true</enabled>
            </releases>
         </repository>
      </repositories>

   </profile>
</profiles>

Create Skeleton

mvn archetype:generate
-DarchetypeGroupId = org.apache.servicemix.tooling
-DarchetypeArtifactId = servicemix-cxf-code-first-osgi-bundle
-DarchetypeVersion=2012.01.0.redhat-60024
-DgroupId = org.fusesource.example
-DartifactId = cxf-basic
-Dversion = 1.0-SNAPSHOT

Build Web Service Project

mvn clean install

Install web-service into Fuse using the following command

JBossFuse:karaf@root>install -s mvn:org.fusesource.example/cxf-basic/1.0-SNAPSH

Check if bundle has registered SOQP web-service

soqp web service

Web 服务应按以下方式列出。

Testing Web-Service

mvn -Pclient

INFO − 从类 com.to 创建服务 { http://ws.totorials.com/ } PersonService

torials.ws.Person
Invoking getPerson...
getPerson._getPerson_personId = Guillaume
getPerson._getPerson_ssn = 000-000-0000
getPerson._getPerson_name = Guillaume
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.668 s
[INFO] Finished at: 2016-02-15T21:01:20+05:30
[INFO] Final Memory: 10M/37M
[INFO] ------------------------------------------------------------------------