环境:JBoss Fuse 6.2.0 + Maven 3.2.2
1. 学习重点
(1)从零开始构建 cxf JAX-WS Web Service。
2. 修改 settings.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<profiles>
<profile>
<id>fusesource-repository</id>
<repositories>
<repository>
<id>fusesource</id>
<url>http://repo.fusesource.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>apache-public</id>
<url>https://repository.apache.org/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases />
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>fusesource-plugin-repository</id>
<url>http://repo.fusesource.com/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>fusesource-repository</activeProfile>
</activeProfiles>
</settings>
注意,必须增加 pluginRepositories 部分,并指向 http://repo.fusesource.com/nexus/content/groups/public/,否则运行 mvn clean install 时会报告如下错误:
(1)[ERROR] Failed to execute goal org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133:java2ws (process-classes) on project cxf-basic: Execution process-classes of goal org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133:java2ws failed: A required class was missing while executing org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133:java2ws: org/apache/cxf/helpers/CastUtils
(2)[ERROR] Plugin org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133 or one of its dependencies could not be resolved: Failure to find org.apache.cxf:cxf-java2ws-plugin:jar:3.0.4.redhat-620133 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
错误(1)是由错误(2)引起的,根本原因是 org.apache.cxf:cxf-java2ws-plugin:jar:3.0.4.redhat-620133 无法下载,该文件实际在 http://repo.fusesource.com/nexus/content/groups/public/org/apache/cxf/cxf-java2ws-plugin/ 中,不在 http://repo.maven.apache.org/maven2 中,因此下载不了。增加 pluginRepositories 部分,并指向 http://repo.fusesource.com/nexus/content/groups/public/ 后,问题消失。
3. 使用 Maven 构建
(1)mvn archetype:generate -DarchetypeGroupId=io.fabric8.archetypes -DarchetypeArtifactId=karaf-soap-archetype -DarchetypeVersion=1.2.0.redhat-133 -DgroupId=org.fusesource.example -DartifactId=cxf-basic -Dversion=1.0-SNAPSHOT -Dfabric8-profile=cxf-basic-profile
(2)修改 cxf-basic/src/test/resources/request.xml,修改后内容如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:sayHi xmlns:ns2="http://example.fusesource.org/">
<arg0>John Doe</arg0>
</ns2:sayHi>
</soap:Body>
</soap:Envelope>
注意,必须修改,否则 mvn -Ptest 会报如下错误:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.293 sec <<< FAILURE! - in org.fusesource.example.SoapTest
sendRequest(org.fusesource.example.SoapTest) Time elapsed: 0.167 sec <<< ERROR!
java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8181/cxf/HelloWorld
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627)
at org.fusesource.example.SoapTest.sendRequest(SoapTest.java:83)
(3)cd cxf-basic
(4)mvn clean install
4. 部署 、卸载
(1)./fuse
(2)osgi:install -s mvn:org.fusesource.example/cxf-basic/1.0-SNAPSHOT
(3)osgi:list
(4)mvn -Ptest
(5)http://localhost:8181/cxf
(6)http://localhost:8181/cxf/HelloWorld?wsdl
(7)osgi:uninstall <id>
参考文献:
1. Red_Hat_JBoss_Fuse-6.2-Getting_Started-en-US.pdf
1. 学习重点
(1)从零开始构建 cxf JAX-WS Web Service。
2. 修改 settings.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<profiles>
<profile>
<id>fusesource-repository</id>
<repositories>
<repository>
<id>fusesource</id>
<url>http://repo.fusesource.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>apache-public</id>
<url>https://repository.apache.org/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases />
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>fusesource-plugin-repository</id>
<url>http://repo.fusesource.com/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>fusesource-repository</activeProfile>
</activeProfiles>
</settings>
注意,必须增加 pluginRepositories 部分,并指向 http://repo.fusesource.com/nexus/content/groups/public/,否则运行 mvn clean install 时会报告如下错误:
(1)[ERROR] Failed to execute goal org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133:java2ws (process-classes) on project cxf-basic: Execution process-classes of goal org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133:java2ws failed: A required class was missing while executing org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133:java2ws: org/apache/cxf/helpers/CastUtils
(2)[ERROR] Plugin org.apache.cxf:cxf-java2ws-plugin:3.0.4.redhat-620133 or one of its dependencies could not be resolved: Failure to find org.apache.cxf:cxf-java2ws-plugin:jar:3.0.4.redhat-620133 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
错误(1)是由错误(2)引起的,根本原因是 org.apache.cxf:cxf-java2ws-plugin:jar:3.0.4.redhat-620133 无法下载,该文件实际在 http://repo.fusesource.com/nexus/content/groups/public/org/apache/cxf/cxf-java2ws-plugin/ 中,不在 http://repo.maven.apache.org/maven2 中,因此下载不了。增加 pluginRepositories 部分,并指向 http://repo.fusesource.com/nexus/content/groups/public/ 后,问题消失。
3. 使用 Maven 构建
(1)mvn archetype:generate -DarchetypeGroupId=io.fabric8.archetypes -DarchetypeArtifactId=karaf-soap-archetype -DarchetypeVersion=1.2.0.redhat-133 -DgroupId=org.fusesource.example -DartifactId=cxf-basic -Dversion=1.0-SNAPSHOT -Dfabric8-profile=cxf-basic-profile
(2)修改 cxf-basic/src/test/resources/request.xml,修改后内容如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:sayHi xmlns:ns2="http://example.fusesource.org/">
<arg0>John Doe</arg0>
</ns2:sayHi>
</soap:Body>
</soap:Envelope>
注意,必须修改,否则 mvn -Ptest 会报如下错误:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.293 sec <<< FAILURE! - in org.fusesource.example.SoapTest
sendRequest(org.fusesource.example.SoapTest) Time elapsed: 0.167 sec <<< ERROR!
java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8181/cxf/HelloWorld
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627)
at org.fusesource.example.SoapTest.sendRequest(SoapTest.java:83)
(3)cd cxf-basic
(4)mvn clean install
4. 部署 、卸载
(1)./fuse
(2)osgi:install -s mvn:org.fusesource.example/cxf-basic/1.0-SNAPSHOT
(3)osgi:list
(4)mvn -Ptest
(5)http://localhost:8181/cxf
(6)http://localhost:8181/cxf/HelloWorld?wsdl
(7)osgi:uninstall <id>
参考文献:
1. Red_Hat_JBoss_Fuse-6.2-Getting_Started-en-US.pdf
没有评论:
发表评论