Patrik Jonsson
Patrik Jonsson

Reputation: 75

Camel Fuse Route from JSON to JSON not working

I am playing with the Camel Fuse tooling to convert from JSON to JSON through a data mapper. I have been able to do conversions from XML to JSON using data mappers.

However, when I try to receive a json object and then data map it and then send it the data mapping fails with the below message.

Note that I am building something that will run on a Tomcat server, that is why I am using the camel-config.xml file.

Any thoughts on what might be amiss?

Patrik

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)

Here is my input .json

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

Here is my expected output:

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

Here is my transformation map:

<?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>

And finally here is my route config in the file: 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>

Upvotes: 2

Views: 1096

Answers (1)

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

Although it is great that JBoss Fuse is getting a graphical mapper I think since it is a new component you should probably give it some time before they fix eventual bugs and optimise the performance. At least for me when I was testing it, it ran quit slowly.

For pure json-to-json mapping perhaps you can look at the component camel-jolt. http://camel.apache.org/jolt.html

Upvotes: 1

Related Questions