从JSON到JSON的Camel Fuse Route无法正常工作

时间:2015-11-08 16:30:47

标签: json apache-camel jbossfuse

我正在玩Camel Fuse工具,通过数据映射器将JSON转换为JSON。我已经能够使用数据映射器从XML到JSON进行转换。

但是,当我尝试接收一个json对象然后对其进行数据映射然后发送它时,数据映射将失败并显示以下消息。

请注意,我正在构建可在Tomcat服务器上运行的东西,这就是我使用camel-config.xml文件的原因。

对可能有什么不妥之处的想法?

帕特里克

java.lang.NullPointerException
    at org.apache.camel.component.dozer.DozerProducer.process(DozerProducer.java:78)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
    at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:162)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
    at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:146)
    at org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Unknown Source)java.lang.NullPointerException
    at org.apache.camel.component.dozer.DozerProducer.process(DozerProducer.java:78)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
    at org.apache.camel.component.jetty.CamelContinuationServlet.service(CamelContinuationServlet.java:162)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
    at org.eclipse.jetty.servlets.MultiPartFilter.doFilter(MultiPartFilter.java:146)
    at org.apache.camel.component.jetty.CamelFilterWrapper.doFilter(CamelFilterWrapper.java:43)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:499)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
    at java.lang.Thread.run(Unknown Source)

这是我的输入.json

{
    "id": "138784",
    "fields":
    {
        "description": "Maxed",
        "summary": "Max is my name",
        "created": "2015-09-28",
        "duedate": "2015-09-28",
        "updated": "2015-09-28"
    }
}

这是我的预期输出:

{
  "theType" : "Transaction",
  "theId" : "0",
  "attributes" : {
    "valuationDate" : "",
    "amount" : "108.15",
    "valueDate" : "",
    "description" : "description 0",
    "type" : "withdrawal",
    "verificationId" : "verificationId 0"
  },
  "type" : "Transaction",
  "id" : "0"
}

这是我的转换图:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
    <configuration>
        <wildcard>false</wildcard>
    </configuration>
    <mapping>
        <class-a>input.Input</class-a>
        <class-b>transaction1.Transaction1</class-b>
        <field>
            <a>id</a>
            <b>attributes.verificationId</b>
        </field>
    </mapping>
    <mapping>
        <class-a>input.Fields</class-a>
        <class-b>transaction1.Attributes</class-b>
        <field>
            <a>description</a>
            <b>description</b>
        </field>
        <field>
            <a>created</a>
            <b>valuationDate</b>
        </field>
        <field>
            <a>duedate</a>
            <b>valueDate</b>
        </field>
        <field>
            <a>summary</a>
            <b>type</b>
        </field>
        <field>
            <a>updated</a>
            <b>amount</b>
        </field>
    </mapping>
    <mapping>
        <class-a>org.apache.camel.component.dozer.ExpressionMapper</class-a>
        <class-b>transaction1.Transaction1</class-b>
        <field custom-converter-id="_expressionMapping" custom-converter-param="constant:Transaction">
            <a>expression</a>
            <b>theType</b>
        </field>
        <field custom-converter-id="_expressionMapping" custom-converter-param="constant:0">
            <a>expression</a>
            <b>theId</b>
        </field>
        <field custom-converter-id="_expressionMapping" custom-converter-param="constant:2">
            <a>expression</a>
            <b>id</b>
        </field>
    </mapping>
</mappings>

最后这是我在文件中的路由配置:camel-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->


<!-- here we have the Camel route(s). -->
<!-- we must still use the http://camel.apache.org/schema/spring namespace so Camel can load the routes
     though Spring JARs is not required -->
<!-- incoming requests from the servlet is routed -->
<!-- is there a header with the key name? -->
<!-- yes so return back a message to the user -->
<!-- if no name parameter then output a syntax to the user -->

 <routes xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="jetty:http://localhost:8091/camel/input/input"/>
    <log message="Log1 ${body}"/>
    <to uri="dozer:transformation11?sourceModel=input.Input&amp;targetModel=transaction0.Transaction0&amp;mappingFile=transformation.xml"/>
    <log message="Log2 ${body}"/>
    <marshal>
      <json library="Jackson"/>
    </marshal>
    <to uri="jetty:http://localhost:8088/camel/transaction/output?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
  </route>
</routes>

1 个答案:

答案 0 :(得分:1)

尽管JBoss Fuse获得图形映射器非常棒,但我认为因为它是一个新组件,所以在修复最终错误并优化性能之前,您应该给它一些时间。至少对我来说,当我测试它时,它会慢慢退出。

对于纯json-to-json映射,您可以查看组件camel-jolt。 http://camel.apache.org/jolt.html