Camel与现有Web应用程序集成

时间:2014-03-21 14:24:29

标签: apache-camel

我有一个提供休息全服务的Web应用程序和另一个执行soap请求响应的独立(jar)应用程序(使用驼峰)

有人可以指点我如何整合两个应用程序

具体讲述在tomcat中部署war文件时如何踢camel路由,以及在特定HTTP请求到达时如何重新运行路由。

我正在使用camel DSL(xml)和spring。

更新1: 我关注了this

  1. 检查了web.xml是否有以下行:

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </context-param>
    
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.mycompany.server.Binder</param-value>
    </context-param>
    
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>
    
    
    <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
  2. 创建了一个/WEB-INF/applicationContext.xml文件,并将所有路由和bean放入其中(顺便说一下,我的bean文件以及src / main / resources中的bean文件正在被spring读取)。

            <?xml version="1.0" encoding="UTF-8"?>
    <beans 
           xmlns:camel="http://camel.apache.org/schema/spring"
           xmlns:cxf="http://camel.apache.org/schema/cxf"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://www.springframework.org/schema/beans"
           xsi:schemaLocation="
            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
            http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
            http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           ">
    
    
      <!--  Camel applicationContext -->
      <!-- this import needed to bring in CXF classes -->
      <import resource="classpath:META-INF/cxf/cxf.xml" />  
    
        <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
            <property name="location"  value="classpath:${env}/my.properties" />
        </bean>
    
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:${env}/my.properties</value>
                </list>
            </property>
        </bean>
    
        <camel:camelContext id="camelContext">
            <camel:contextScan/>
            <camel:template id="serviceConsumerTemplate" defaultEndpoint="direct:start" />
            <camel:threadPoolProfile defaultProfile="true" id="defaultThreadPool" poolSize="10" maxPoolSize="15" />
    
            <camel:route id="serviceGetAccount">
                <camel:from uri="timer://kickoff?repeatCount=1"/>
                <camel:to uri="bean:serviceGetAccountProcessor" />
                <camel:to uri="bean:serviceRequestHeaderCreator" />
                <camel:to uri="cxf:bean:serviceGetAccountEndpoint?dataFormat=POJO" />
                <camel:to uri="bean:serviceGetAccountResponseProcessor" />
            </camel:route>
        </camel:camelContext>
    
        <bean id="serviceRequestHeaderCreator" class="com.mycompany.service.soap.SOARequestHeaderCreator">
            <property name="serviceName" value="service" />
            <property name="spnValue" value="${nj.spn}" />
            <property name="securityTokenEnabled" value="true" />
            <property name="sendingApplication" value="NJ SERVICE" />
            <property name="serviceVersion" value="3.0.2" />
            <property name="sendingHost" ref="localHostName"/>
        </bean>
    
        <cxf:cxfEndpoint id="serviceGetAccountEndpoint"
            address="${request.endpoint}/serviceAccountRequestResponsePT"
            endpointName="s:serviceAccountRequestResponsePort"
            serviceName="s:serviceAccountRequestResponseHTTP"
            xmlns:s="http://soa.mycompany.com/services/service/wsdl/v3"
            serviceClass="com.mycompany.services.service.wsdl.v3.serviceAccountRequestResponsePT"
            loggingFeatureEnabled="true">
        </cxf:cxfEndpoint>
    
        <bean id="serviceGetAccountProcessor" class="com.mycompany.service.serviceGetAccountProcessor"/>
        <bean id="serviceGetAccountResponseProcessor" class="com.mycompany.service.serviceGetAccountResponseProcessor"/>
    
    </beans>
    
  3. 提高log4j.logger.org.apache.camel = DEBUG
  4. 的日志记录级别

    但是没有看到任何路线的驼峰日志行开始。

    更新2 : 我没有做mvn clean generate-sources。 一旦我开始做mvn clean并重建war文件,骆驼就开始了。

1 个答案:

答案 0 :(得分:0)

似乎你的春天环境并没有真正开火。确保它是! 应该有一些Spring信息日志事件告诉你这个。

尝试添加此内容:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
相关问题