Cxf 无法使用camel将消息发送到外部web应用程序

Cxf 无法使用camel将消息发送到外部web应用程序,cxf,apache-camel,fuseesb,cxfrs,Cxf,Apache Camel,Fuseesb,Cxfrs,我的要求是从一个web应用程序接收一个json对象的消息,并将它(json对象)路由到另一个web应用程序,为此我使用了camel,在一个相当简单的过程中,现在让我睡不着觉,我的camel路由如下所示 <camel:route> <camel:from uri="cxfrs://bean://lmrServer" /> <camel:to uri="log:output?showAll=true"/&

我的要求是从一个web应用程序接收一个json对象的消息,并将它(json对象)路由到另一个web应用程序,为此我使用了camel,在一个相当简单的过程中,现在让我睡不着觉,我的camel路由如下所示

                 <camel:route>
        <camel:from uri="cxfrs://bean://lmrServer" />
        <camel:to uri="log:output?showAll=true"/>
             <setHeader headerName="CamelHttpMethod">
         <constant>POST</constant>
        </setHeader> 
    <camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/> 
我有一种感觉,这是因为罐子,所以下面是我的pom.xml

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <camel.version>2.10.3</camel.version>
        <json.version>1.8.5</json.version>
        <cxf.version>2.5.0</cxf.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>${camel.version}</version>
        </dependency>


        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jetty</artifactId>
            <version>${camel.version}</version>
        </dependency> 
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cxf</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-script</artifactId>
            <version>${camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jaxb</artifactId>
            <version>${camel.version}</version>
        </dependency>

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cache</artifactId>
    <version>2.12.1</version>
</dependency>

        <!-- JSON -->
    <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${json.version}</version>
        </dependency> 
        <dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-jaxrs</artifactId>
    <version>${json.version}</version>
</dependency>



        <!-- CXF -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>${cxf.version}</version>
        </dependency>
          <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>  
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-policy</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-addr</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <!-- logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- testing -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-spring</artifactId>
            <version>2.10.3</version>
            <scope>test</scope>
        </dependency>


    </dependencies>

    <build>
        <defaultGoal>install</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <!-- allows the route to be ran via 'mvn camel:run' -->
            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>2.10.3</version>
            </plugin>
            <!-- -jetty -->
 <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${camel.version}</version>
            <configuration>
              <connectors>
                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                  <port>8081</port>
                </connector>
              </connectors>
              <stopPort>18080</stopPort>
            </configuration>
          </plugin>

        </plugins>
    </build>

</project>
我在骆驼环境中所做的更改如下

<dataFormats>
        <json library="Jackson" unmarshalTypeName="org.payment.camel.example.MemberApplication" id="jack"/>
    </dataFormats>


MemberApplication只是一个实现Serializable的pojo类。有人能指出我错在哪里吗。

exchange的主体包含一个对象

BodyType:org.apache.cxf.message.MessageContentsList, Body:[MemberApplication [name=xyz, organization=avc, nic=xyz, employeeId=5920]]
在发送到之前,不应该将其转换为json吗

<camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>

如果要发送JSON,必须在发送前对对象进行马歇尔处理

您可以这样做:

<dataFormats>
    <!-- here we define a Json data format with the id jack and that it should use the TestPojo as the class type when
         doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Map as the type -->
    <json id="jack" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
</dataFormats>

<camel:route>
     <camel:from uri="cxfrs://bean://lmrServer" />
        <camel:to uri="log:output?showAll=true"/>
             <setHeader headerName="CamelHttpMethod">
         <constant>POST</constant>
        </setHeader> 
     <camel:marshal ref="jack"/>
     <camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>
 </camel:route>

邮递

有关更多详细信息,请参阅文档:。

感谢您的回复,我的要求是将接收到的相同json对象发送到外部web应用程序,是否有任何方法可以执行此操作。
<camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>
<dataFormats>
    <!-- here we define a Json data format with the id jack and that it should use the TestPojo as the class type when
         doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Map as the type -->
    <json id="jack" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
</dataFormats>

<camel:route>
     <camel:from uri="cxfrs://bean://lmrServer" />
        <camel:to uri="log:output?showAll=true"/>
             <setHeader headerName="CamelHttpMethod">
         <constant>POST</constant>
        </setHeader> 
     <camel:marshal ref="jack"/>
     <camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>
 </camel:route>