【发布时间】:2014-08-25 14:52:38
【问题描述】:
我有一条骆驼路线,前面有一个 CXF Web 服务消费者(来自)。我在 Glassfish 4.0 中进行部署,并且在使用 servlet 规范 2.4 时效果很好。我现在需要通过在使用 JPA 完成的过程中添加一些持久性来增强路由。这样做需要升级到 servlet 规范 2.5+(我已经升级到 3.0)
当 servlet 规范更改为 2.5+ 时,部署时会出现以下错误:java.lang.IllegalStateException:生命周期方法 [finalizeConfig] 不得抛出已检查异常。大多数解决方案都说要删除 cxf-rt-transports-http-jetty-2.7.11.jar。
当jetty jar被移除后,部署错误变为:java.io.IOException: Could not find destination factory for transport http://schemas.xmlsoap.org/soap/http
对此的解决方案,例如 CXF BusException No DestinationFactory for namespace http://cxf.apache.org/transports/http 或 org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://schemas.xmlsoap.org/soap/http/ 说要导入 cxf-servlet.xml 文件,然后需要包含 jar cxf-rt-transports-http-2.7.11.jar(我删除了这是当我取下码头罐子时的)。包含这些文件会导致以下部署错误:java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus。
这个错误的解决方案都说包括jar cxf-rt-transports-http-jetty-2.7.11.jar。这让我回到了由于 servlet 规范升级而不得不删除它的地方。
我已经能够创建一个小项目来演示这一点,并包含以下内容。我还尝试在 Glassfish 4.1 和不同 jar 版本的各种组合上进行部署(CXF 3.0 不包括来自骆驼的 2.7 jar 等),但我仍然无法在 Glassfish 中部署应用程序。
我可以使用 maven camel 插件 'mvm camel:run' 来运行它(这需要从测试中取消 cxf-rt-transports-http*.jar 文件的范围。当然这可行,因为我是在 glassfish 容器外面。
任何帮助将不胜感激。
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>camel-cxf-gf</artifactId>
<packaging>war</packaging>
<version>0.1</version>
<name>Camel with CXF in GF</name>
<properties>
<camel-version>2.13.1</camel-version>
<cxf-version>2.7.11</cxf-version>
<buildNumber>0.1</buildNumber>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- cxf using slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<!-- using Jetty with CXF -->
<!-- "The Google" says to exclude this when deploying to Glassfish (test scope only) -->
<!-- To run with mvn camel:run, comment out the test scope on BOTH cxf-rt dependencies -->
<!-- However, if present for GF deploy, you get the error: The lifecycle method [finalizeConfig] must not throw a checked exception -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
<!-- "The Google" says to exclude this (test scope only) -->
<!-- To run with mvn camel:run, comment out the test scope on BOTH cxf-rt dependencies -->
<!-- If present for GF deploy, you get the error: java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- allows the route to be executed via 'mvn camel:run', NOTE: must comment out the test scope on the cxf-rt-transports dependencies above.... -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>${camel-version}</version>
<configuration>
<fileApplicationContextUri>
classpath:META-INF/applicationContext.xml
</fileApplicationContextUri>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webXml>web/WEB-INF/web.xml</webXml>
<failOnMissingWebXml>true</failOnMissingWebXml>
<archive>
<manifestEntries>
<Build-Version>${project.version}</Build-Version>
<Build-Revision>${buildNumber}</Build-Revision>
<Build-Date>${maven.build.timestamp}</Build-Date>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Camel CXF, JMS Web Application</display-name>
<!-- location of spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/applicationContext.xml</param-value>
</context-param>
<!-- the listener that kick-starts Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
CXF 服务:
package com.example;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService(serviceName = "HelloMessage", targetNamespace = "http://example.com/")
public interface HelloMessageEndpoint {
@WebMethod(operationName = "sayHello")
@WebResult(name = "messageAnswer", targetNamespace = "http://example.com/", partName = "messageAnswer")
public String sayHello(@WebParam(name = "name") String name);
}
我的 applicationContext.xml 包含 Spring DSL 骆驼路线(在资源/META-INF 下):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.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
">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<!-- This doesn't seem to make a difference -->
<!--<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml"/>-->
<!-- When cxf-rt-transports-http is removed (test scope) cxf-servlet.xml is no longer available -->
<!--<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>-->
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<cxf:cxfEndpoint id="helloMessageEndpoint"
address="http://0.0.0.0:9000/HelloWS/"
serviceClass="com.example.HelloMessageEndpoint"
endpointName="HelloMessageEndpoint"
serviceName="HelloMessage"
loggingFeatureEnabled="false"/>
<camelContext id="messageContext" streamCache="true" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:helloMessageEndpoint"/>
<log loggingLevel="INFO" message="====> CXF Message Body: ${body}"/>
</route>
</camelContext>
</beans>
【问题讨论】:
标签: cxf apache-camel glassfish-4 servlet-3.0