You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jeffz <jz...@hotmail.com> on 2016/09/27 21:04:47 UTC

Help with JSON to POJO using XML Routes

I'm using Camel - through ServiceMix - to retrieve data from a web service,
read the response and pass the data to another application.  This code was
inherited, so much of the framework already exists.  it used to read from a
database, but now needs to get its input from the web service response. 
Problem is, I can't figure out how to read the data into the bean and all my
log statements within the java code get ignored. This makes debugging
difficult.  I was hoping someone with more experience could shed some light
on my situation.  For those paying attention, I did post on the ServiceMix
board, but that was a different question in the same route.

Questions:
        1) How do I reference a set of java classes to unmarshal the message
using the Jackson API?
        2) How do I enable logging within the java bean?
        3)These messages are quite large.  How do I stream data into the
Exchange/POJO?


Here are my routes:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

	
	<cm:property-placeholder id=placeholder" persistent-id="com.example">
        <cm:default-properties>
        	<cm:property name="url" value="example.com"/>	
        </cm:default-properties>
    </cm:property-placeholder>
    
	 
	<bean id="espSendMailService" class="com.service.SendMailService">
		<property name="list" value="${list.id}" />
	</bean>
	<bean id="jack"
class="org.apache.camel.component.jackson.JacksonDataFormat">
	</bean>  
	
	<bean id="tst" class="com.example.RetailStoreReturnPOJO">
	</bean> 
	<bean id="StoreLoadBean" class="com.example.StoreLoad">
		<property name="dataSource" ref="DB" />
		<property name="silverpopTableIds" value="${ids}" />
	</bean>

    <camelContext id="camelroutes"
xmlns="http://camel.apache.org/schema/blueprint" trace="true">
    

		<route>
			<from uri="activemq:test"/>
			<from uri="http4://{{url}}"/>
			<to uri="activemq:retailout"/>
		</route>
		
		<route>
			<from uri="activemq:retailout"/>
			<doTry>
			<unmarshal ref="tst"/>
			<to uri="log:output"/>
			<to uri="bean:StoreLoadBean?method=loadRetailStoreDataFromMap"/>
			<log message="complete"/>
			<doCatch>
				<exception>java.lang.Exception</exception>
				<to uri="log:activemq.retailouterror?level=WARN"/>
			</doCatch>
			</doTry> 	
		</route>
    </camelContext>
    
</blueprint>



--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
If you put a log message right after the Netty call what does it show?

On Sep 27, 2016 4:04 PM, "jeffz" <jz...@hotmail.com> wrote:

> I'm using Camel - through ServiceMix - to retrieve data from a web service,
> read the response and pass the data to another application.  This code was
> inherited, so much of the framework already exists.  it used to read from a
> database, but now needs to get its input from the web service response.
> Problem is, I can't figure out how to read the data into the bean and all
> my
> log statements within the java code get ignored. This makes debugging
> difficult.  I was hoping someone with more experience could shed some light
> on my situation.  For those paying attention, I did post on the ServiceMix
> board, but that was a different question in the same route.
>
> Questions:
>         1) How do I reference a set of java classes to unmarshal the
> message
> using the Jackson API?
>         2) How do I enable logging within the java bean?
>         3)These messages are quite large.  How do I stream data into the
> Exchange/POJO?
>
>
> Here are my routes:
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint
>     xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>     xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>       http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
>
>
>         <cm:property-placeholder id=placeholder"
> persistent-id="com.example">
>         <cm:default-properties>
>                 <cm:property name="url" value="example.com"/>
>         </cm:default-properties>
>     </cm:property-placeholder>
>
>
>         <bean id="espSendMailService" class="com.service.SendMailService">
>                 <property name="list" value="${list.id}" />
>         </bean>
>         <bean id="jack"
> class="org.apache.camel.component.jackson.JacksonDataFormat">
>         </bean>
>
>         <bean id="tst" class="com.example.RetailStoreReturnPOJO">
>         </bean>
>         <bean id="StoreLoadBean" class="com.example.StoreLoad">
>                 <property name="dataSource" ref="DB" />
>                 <property name="silverpopTableIds" value="${ids}" />
>         </bean>
>
>     <camelContext id="camelroutes"
> xmlns="http://camel.apache.org/schema/blueprint" trace="true">
>
>
>                 <route>
>                         <from uri="activemq:test"/>
>                         <from uri="http4://{{url}}"/>
>                         <to uri="activemq:retailout"/>
>                 </route>
>
>                 <route>
>                         <from uri="activemq:retailout"/>
>                         <doTry>
>                         <unmarshal ref="tst"/>
>                         <to uri="log:output"/>
>                         <to uri="bean:StoreLoadBean?method=
> loadRetailStoreDataFromMap"/>
>                         <log message="complete"/>
>                         <doCatch>
>                                 <exception>java.lang.Exception</exception>
>                                 <to uri="log:activemq.
> retailouterror?level=WARN"/>
>                         </doCatch>
>                         </doTry>
>                 </route>
>     </camelContext>
>
> </blueprint>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Help with JSON to POJO using XML Routes

Posted by jeffz <jz...@hotmail.com>.
Thanks Ranx,

I was able to address logging by modifying the config file (it was set to
WARN).  Now, my next step is to actually read the JSON.  Since I can't read
it directly into POJO, I'm left using the generic unmarshal and reading the
data as a map.  Is that something you can help with?  My java method and
JSON are below.  If I can learn how to iterate this thing, it definitely
helps.  Also, any tips for processing large JSON are much appreciated.  My
experiments with streaming have not gone well.

public void loadRetailStoreDataFromMap(Exchange input, Registry
paramRegistry) throws Exception {
		final String METHODNAME = "loadRetailStoreDataFromMap()";
		LOGGER.warn(METHODNAME + " loading data from Map: ");
		Map body = (Map)input.getIn().getBody();
		String strData = "";
		strData = (String) body.get("​r​e​c​o​r​d​S​e​t​T​o​t​a​l​"); <-- RETURNS
NULL
		LOGGER.warn(METHODNAME + "Data " + body);
		// First load data into DB table
		List<RetailStorePOJO> storeData = loadStoreDataFromMessage(body);
		if(null != storeData && storeData.size() > 0) {
			//System.out.println("Before calling buildSPRetailStoreDataXML()...");
			List<String> retailStoresXMLStrList =
buildSPRetailStoreDataXML(storeData);
			//System.out.println("After calling buildSPRetailStoreDataXML()...");
			//System.out.println("Before calling loadSegmentDataIntoSP()...");
			for(int i = 0; i < retailStoresXMLStrList.size(); i++) {
				String retailStoresXML = retailStoresXMLStrList.get(i);
				loadRetailDataIntoSP(retailStoresXML, paramRegistry);
			}
			
			//System.out.println("After calling loadRetailDataIntoSP()...");
		}
		LOGGER.debug(METHODNAME + " exit: ");
	}

{recordSetTotal=2, recordSetCount=2, resourceId=host.com,
recordSetComplete=true, recordSetStartNumber=0,
PhysicalStore=[{telephone1=(555)555-5555                   ,
addressLine=[123 Fake, Shopping Center],
Description=[{displayStoreName=GARY, fullImage=store_82.jpg}],
stateOrProvinceName=NC, storeName=CARY, postalCode=12345                                  
, Attribute=[{name=StoreHours, value=10:00AM-7:00PM Monday-Friday,
displayName=Store hours, displayValue=10:00AM-8:00PM Monday-
Friday<br/>10:00AM-8:00PM Saturday<br/>12:00PM-6:00PM Sunday<br/>All stores
closed Thanksgiving Day and Christmas Day.}, {name=StoreIdentifier,
value=082, displayName=StoreIdentifier, displayValue=082}, {name=Type,
value=Regular Store, displayName=Type, displayValue=Regular Store}],
uniqueID=11557, longitude=-78.76756, latitude=99.7796, city=Gary,
country=USA}, {telephone1=(555)555-5555                   , addressLine=[123
Fake, Suite A, 1/2 Mile North of E. Woodlawn],
Description=[{displayStoreName=NEW YORK, fullImage=store_84.jpg}],
stateOrProvinceName=NY, storeName=NEW YORK, postalCode=45676                                  
, Attribute=[{name=StoreHours, value=10:00AM-6:00PM Monday- Friday,
displayName=Store hours, displayValue=10:00AM-7:00PM Monday-
Friday<br/>10:00AM-8:00PM Saturday<br/>12:00PM-6:00PM Sunday<br/>All stores
closed Thanksgiving Day and Christmas Day.}, {name=StoreIdentifier,
value=084, displayName=StoreIdentifier, displayValue=084}, {name=Type,
value=Regular Store, displayName=Type, displayValue=Regular Store}],
uniqueID=11559, longitude=-89.87635, latitude=89.18321, city=New York,
country=USA}], resourceName=storelocator}





--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788143.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
By the way, I think I used to use:

 < bean ref="StoreLoadBean" method="loadRetailStoreDataFromMap"/>

On Tue, Sep 27, 2016 at 6:26 PM, Brad Johnson <br...@mediadriver.com>
wrote:

> I'm going to assume that the method named there is on the bean.  The log
> messages may be getting ignored due to the logger not being set up
> correctly.  You can temporarily replace with System.out until you have time
> to go back and make sure the logger is setup up correctly.  As for the
> loading of the bean, try instead of:
>
>  <to uri="bean:StoreLoadBean?method=loadRetailStoreDataFromMap"/>
>
>  <to uri="StoreLoadBean?method=loadRetailStoreDataFromMap"/>
>
> You could also try:
>  <method ref="StoreLoadBean" method="loadRetailStoreDataFromMap"/>
>
> You may not even need to specify the method depending on what the data
> type it is getting and if it matches only one method on your bean.
>
> I've switched lately from using blueprint XML to the Java DSL so trying to
> dredge that up in my memory is a little difficult.
>
> On Tue, Sep 27, 2016 at 5:12 PM, jeffz <jz...@hotmail.com> wrote:
>
>> Hi Ranx,
>>
>> You are correct that I need to get call a web service, get the response,
>> transform it, and send it to another system.  The integration gets
>> information about stores and forwards it to a marketing system.  We are
>> making the change because the database is going away.
>>
>> Old: AutoStart -> Query database for store info -> Format & Send
>> New: AutoStart -> Hit URL for store info -> Format & Send
>>
>> My route replaces autostart with a queue so that I can test.  I built two
>> routes (one to call the service, the other to format), because I kept
>> getting stream closed when trying to unmarshal the web service response.
>>
>> When I hit the http4{url}, I am getting back a JSON string as a result; so
>> that part is working.
>> if I use the below defined "jack" bean, it will unmarshal the message and
>> appears to invoke the java bean.  I say appears because all of my log
>> statements inside the java method are ignored.
>>
>> If I use the "tst" bean, pointing to my java POJO, the route won't even
>> start.  There, I get: Caused by: java.lang.IllegalArgumentException:
>> Cannot
>> find data format in registry with ref: tst
>>
>>
>> Here is my trace from the jack invocation
>> 8 >>> (route665) bean://LoadBean?method=loadRetailStoreDataFromMap -->
>> log[complete] <<< Pattern:InOnly, Headers:{Transfer-Encoding=chunked,
>> JMSPriority=4, Cache-Control=max-age=86400, JMSDeliveryMode=2,
>> JMSXGroupID=null, JMSTimestamp=1475007004112, JMSMessageID=ID:,
>> Content-Type=application/json, JMSRedelivered=false,
>> X-Powered-By=Servlet/3.0, JMSType=null, Content-Language=en-US,
>> JMSReplyTo=null, CamelHttpResponseCode=200, JMSCorrelationID=null,
>> Connection=Keep-Alive, Keep-Alive=timeout=15, JMSExpiration=0,
>> JMSDestination=queue://retailout, Vary=Accept,Accept-Encoding, Date=Tue,
>> 27
>> Sep 2016 20:10:04 GMT, Expires=Wed, 28 Sep 2016 20:10:04 GMT,
>> breadcrumbId=ID-}, BodyType:java.util.HashMap, Body:{recordSetTotal=2,
>> recordSetCount=2, resourceId=http:url, recordSetComplete=true,
>> recordSetStartNumber=0, PhysicalStore=[{telephone1=(444)444-4444
>> , addressLine=[123 Fake Street,  Square Shopping Center],
>> Description=[{displayStoreName=GARY, fullImage=store_82.jpg}],
>> stateOrProvinceName=NC, storeName=GARY, postalCode=12344
>> , Attribute=[{name=StoreHours, value=10:00AM-7:00PM Monday-Friday,
>> displayName=Store hours, displayValue=10:00AM-8:00PM Monday-
>> Friday<br/>10:00AM-8:00PM Saturday<br/>12:00PM-6:00PM Sunday<br/>All
>> stores
>> closed Thanksgiving Day and Christmas Day.}, {name=StoreIdentifier,
>> value=082, displayName=StoreIdentifier, displayValue=082}, {name=Type,
>> value=Regular Store, displayName=Type, displayValue=Regular Store}],
>> uniqueID=11557, longitude=-78.76756, latitude=35.77546, city=Gary,
>> country=US... [Body clipped after 1000 chars, total length is 1811]
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.
>> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788139.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
I'm going to assume that the method named there is on the bean.  The log
messages may be getting ignored due to the logger not being set up
correctly.  You can temporarily replace with System.out until you have time
to go back and make sure the logger is setup up correctly.  As for the
loading of the bean, try instead of:

 <to uri="bean:StoreLoadBean?method=loadRetailStoreDataFromMap"/>

 <to uri="StoreLoadBean?method=loadRetailStoreDataFromMap"/>

You could also try:
 <method ref="StoreLoadBean" method="loadRetailStoreDataFromMap"/>

You may not even need to specify the method depending on what the data type
it is getting and if it matches only one method on your bean.

I've switched lately from using blueprint XML to the Java DSL so trying to
dredge that up in my memory is a little difficult.

On Tue, Sep 27, 2016 at 5:12 PM, jeffz <jz...@hotmail.com> wrote:

> Hi Ranx,
>
> You are correct that I need to get call a web service, get the response,
> transform it, and send it to another system.  The integration gets
> information about stores and forwards it to a marketing system.  We are
> making the change because the database is going away.
>
> Old: AutoStart -> Query database for store info -> Format & Send
> New: AutoStart -> Hit URL for store info -> Format & Send
>
> My route replaces autostart with a queue so that I can test.  I built two
> routes (one to call the service, the other to format), because I kept
> getting stream closed when trying to unmarshal the web service response.
>
> When I hit the http4{url}, I am getting back a JSON string as a result; so
> that part is working.
> if I use the below defined "jack" bean, it will unmarshal the message and
> appears to invoke the java bean.  I say appears because all of my log
> statements inside the java method are ignored.
>
> If I use the "tst" bean, pointing to my java POJO, the route won't even
> start.  There, I get: Caused by: java.lang.IllegalArgumentException:
> Cannot
> find data format in registry with ref: tst
>
>
> Here is my trace from the jack invocation
> 8 >>> (route665) bean://LoadBean?method=loadRetailStoreDataFromMap -->
> log[complete] <<< Pattern:InOnly, Headers:{Transfer-Encoding=chunked,
> JMSPriority=4, Cache-Control=max-age=86400, JMSDeliveryMode=2,
> JMSXGroupID=null, JMSTimestamp=1475007004112, JMSMessageID=ID:,
> Content-Type=application/json, JMSRedelivered=false,
> X-Powered-By=Servlet/3.0, JMSType=null, Content-Language=en-US,
> JMSReplyTo=null, CamelHttpResponseCode=200, JMSCorrelationID=null,
> Connection=Keep-Alive, Keep-Alive=timeout=15, JMSExpiration=0,
> JMSDestination=queue://retailout, Vary=Accept,Accept-Encoding, Date=Tue,
> 27
> Sep 2016 20:10:04 GMT, Expires=Wed, 28 Sep 2016 20:10:04 GMT,
> breadcrumbId=ID-}, BodyType:java.util.HashMap, Body:{recordSetTotal=2,
> recordSetCount=2, resourceId=http:url, recordSetComplete=true,
> recordSetStartNumber=0, PhysicalStore=[{telephone1=(444)444-4444
> , addressLine=[123 Fake Street,  Square Shopping Center],
> Description=[{displayStoreName=GARY, fullImage=store_82.jpg}],
> stateOrProvinceName=NC, storeName=GARY, postalCode=12344
> , Attribute=[{name=StoreHours, value=10:00AM-7:00PM Monday-Friday,
> displayName=Store hours, displayValue=10:00AM-8:00PM Monday-
> Friday<br/>10:00AM-8:00PM Saturday<br/>12:00PM-6:00PM Sunday<br/>All stores
> closed Thanksgiving Day and Christmas Day.}, {name=StoreIdentifier,
> value=082, displayName=StoreIdentifier, displayValue=082}, {name=Type,
> value=Regular Store, displayName=Type, displayValue=Regular Store}],
> uniqueID=11557, longitude=-78.76756, latitude=35.77546, city=Gary,
> country=US... [Body clipped after 1000 chars, total length is 1811]
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788139.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Help with JSON to POJO using XML Routes

Posted by jeffz <jz...@hotmail.com>.
Hi Ranx,

You are correct that I need to get call a web service, get the response,
transform it, and send it to another system.  The integration gets
information about stores and forwards it to a marketing system.  We are
making the change because the database is going away.

Old: AutoStart -> Query database for store info -> Format & Send
New: AutoStart -> Hit URL for store info -> Format & Send

My route replaces autostart with a queue so that I can test.  I built two
routes (one to call the service, the other to format), because I kept
getting stream closed when trying to unmarshal the web service response.

When I hit the http4{url}, I am getting back a JSON string as a result; so
that part is working.
if I use the below defined "jack" bean, it will unmarshal the message and
appears to invoke the java bean.  I say appears because all of my log
statements inside the java method are ignored.

If I use the "tst" bean, pointing to my java POJO, the route won't even
start.  There, I get: Caused by: java.lang.IllegalArgumentException: Cannot
find data format in registry with ref: tst


Here is my trace from the jack invocation
8 >>> (route665) bean://LoadBean?method=loadRetailStoreDataFromMap -->
log[complete] <<< Pattern:InOnly, Headers:{Transfer-Encoding=chunked,
JMSPriority=4, Cache-Control=max-age=86400, JMSDeliveryMode=2,
JMSXGroupID=null, JMSTimestamp=1475007004112, JMSMessageID=ID:,
Content-Type=application/json, JMSRedelivered=false,
X-Powered-By=Servlet/3.0, JMSType=null, Content-Language=en-US,
JMSReplyTo=null, CamelHttpResponseCode=200, JMSCorrelationID=null,
Connection=Keep-Alive, Keep-Alive=timeout=15, JMSExpiration=0,
JMSDestination=queue://retailout, Vary=Accept,Accept-Encoding, Date=Tue, 27
Sep 2016 20:10:04 GMT, Expires=Wed, 28 Sep 2016 20:10:04 GMT,
breadcrumbId=ID-}, BodyType:java.util.HashMap, Body:{recordSetTotal=2,
recordSetCount=2, resourceId=http:url, recordSetComplete=true,
recordSetStartNumber=0, PhysicalStore=[{telephone1=(444)444-4444                  
, addressLine=[123 Fake Street,  Square Shopping Center],
Description=[{displayStoreName=GARY, fullImage=store_82.jpg}],
stateOrProvinceName=NC, storeName=GARY, postalCode=12344                                  
, Attribute=[{name=StoreHours, value=10:00AM-7:00PM Monday-Friday,
displayName=Store hours, displayValue=10:00AM-8:00PM Monday-
Friday<br/>10:00AM-8:00PM Saturday<br/>12:00PM-6:00PM Sunday<br/>All stores
closed Thanksgiving Day and Christmas Day.}, {name=StoreIdentifier,
value=082, displayName=StoreIdentifier, displayValue=082}, {name=Type,
value=Regular Store, displayName=Type, displayValue=Regular Store}],
uniqueID=11557, longitude=-78.76756, latitude=35.77546, city=Gary,
country=US... [Body clipped after 1000 chars, total length is 1811]



--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788139.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
I didn't see in your initial code anything that set up the dataFormat.
That along with the unmarsal/marshal are what you need to get it to work
correctly, not just using a bean.

<dataFormats>
        <json id="jack" library="Jackson" unmarshalTypeName="com.example.
RetailStoreReturnPOJO""/>
</dataFormats>

Then in your route, right after your call* to* http4 you put:


 <unmarshal ref="jack"/>



On Wed, Sep 28, 2016 at 11:56 AM, Brad Johnson <brad.johnson@mediadriver.com
> wrote:

> Jackson works fine and I've used it many times.  So does JAXB for JSON.
> Just remember to put the @XmlRootElement annotation on your bean in that
> case (yeah, even it if is only being used for JSON). I really wouldn't fool
> with the gapping of strings to a hashmap. You'll just create headaches. You
> can also use XStream with jettison.  XStream is one of my favorite
> libraries though I don't usually use it to marshal/unmarshal JSON.
>
> Right after your call to http4 log the return data and post it.  One item
> I've seen in the past in the context of web service calls is that it will
> put the individual elements it gets back in an array and you have to fish
> the zeroeth element out of the array to get the actual item you're looking
> for.
>
> But if you just print out/log what you get right after the call TO http
> that should help.
>
> Brad
>
>
>
>
>
> On Wed, Sep 28, 2016 at 8:36 AM, jeffz <jz...@hotmail.com> wrote:
>
>> That's actually how it originally was, but I changed it while working on
>> my
>> older 'stream closed' issue.  I can switch that back.  I'm actually pretty
>> close now, just running into some issues reading certain fields within the
>> map object.
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.
>> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788158.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
Jackson works fine and I've used it many times.  So does JAXB for JSON.
Just remember to put the @XmlRootElement annotation on your bean in that
case (yeah, even it if is only being used for JSON). I really wouldn't fool
with the gapping of strings to a hashmap. You'll just create headaches. You
can also use XStream with jettison.  XStream is one of my favorite
libraries though I don't usually use it to marshal/unmarshal JSON.

Right after your call to http4 log the return data and post it.  One item
I've seen in the past in the context of web service calls is that it will
put the individual elements it gets back in an array and you have to fish
the zeroeth element out of the array to get the actual item you're looking
for.

But if you just print out/log what you get right after the call TO http
that should help.

Brad





On Wed, Sep 28, 2016 at 8:36 AM, jeffz <jz...@hotmail.com> wrote:

> That's actually how it originally was, but I changed it while working on my
> older 'stream closed' issue.  I can switch that back.  I'm actually pretty
> close now, just running into some issues reading certain fields within the
> map object.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788158.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Help with JSON to POJO using XML Routes

Posted by jeffz <jz...@hotmail.com>.
That's actually how it originally was, but I changed it while working on my
older 'stream closed' issue.  I can switch that back.  I'm actually pretty
close now, just running into some issues reading certain fields within the
map object.



--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788158.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with JSON to POJO using XML Routes

Posted by DariusX <da...@gmail.com>.
As Ranx mentioned, shouldn't the http4 component be a producer rather than a
consumer? (to rather than from?)
 i.e. <*to * uri="http4://{{url}}"/> 


Ranx wrote
> ... your route is receiving it (from) but that is followed by another
> (from) which would sit and wait for someone to call it.  That doesn't
> really do much with the incoming activemq message then.





--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130p5788157.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
Incidentally, this is where a bit of my confusion lies:

 to retrieve data from a web service,
read the response and pass the data to another application.  (make a
request and get the response?)  <*to *uri="http4://{{url}}"/>

 it used to read from a database, but now needs *to get its input from the
web service response*. (I take it you don't mean receiving input but making
a request and getting the response? That is calling to the http4 client to
some other server that is sending back a response?)

From what I see that seems to be what you want since you are sending
something over activemq and your route is receiving it (from) but that is
followed by another (from) which would sit and wait for someone to call
it.  That doesn't really do much with the incoming activemq message then.



On Tue, Sep 27, 2016 at 4:38 PM, Brad Johnson <br...@mediadriver.com>
wrote:

> By the way, which version of Camel are you using?  And maybe I'm not quite
> understanding what you're trying to do but it sound like you want to call *to
> *an http endpoint and aren't waiting to receive from the endpoint.
>
> On Tue, Sep 27, 2016 at 4:04 PM, jeffz <jz...@hotmail.com> wrote:
>
>> I'm using Camel - through ServiceMix - to retrieve data from a web
>> service,
>> read the response and pass the data to another application.  This code was
>> inherited, so much of the framework already exists.  it used to read from
>> a
>> database, but now needs to get its input from the web service response.
>> Problem is, I can't figure out how to read the data into the bean and all
>> my
>> log statements within the java code get ignored. This makes debugging
>> difficult.  I was hoping someone with more experience could shed some
>> light
>> on my situation.  For those paying attention, I did post on the ServiceMix
>> board, but that was a different question in the same route.
>>
>> Questions:
>>         1) How do I reference a set of java classes to unmarshal the
>> message
>> using the Jackson API?
>>         2) How do I enable logging within the java bean?
>>         3)These messages are quite large.  How do I stream data into the
>> Exchange/POJO?
>>
>>
>> Here are my routes:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <blueprint
>>     xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>>     xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0
>> "
>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>     xsi:schemaLocation="
>>       http://www.osgi.org/xmlns/blueprint/v1.0.0
>> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
>>
>>
>>         <cm:property-placeholder id=placeholder"
>> persistent-id="com.example">
>>         <cm:default-properties>
>>                 <cm:property name="url" value="example.com"/>
>>         </cm:default-properties>
>>     </cm:property-placeholder>
>>
>>
>>         <bean id="espSendMailService" class="com.service.SendMailSer
>> vice">
>>                 <property name="list" value="${list.id}" />
>>         </bean>
>>         <bean id="jack"
>> class="org.apache.camel.component.jackson.JacksonDataFormat">
>>         </bean>
>>
>>         <bean id="tst" class="com.example.RetailStoreReturnPOJO">
>>         </bean>
>>         <bean id="StoreLoadBean" class="com.example.StoreLoad">
>>                 <property name="dataSource" ref="DB" />
>>                 <property name="silverpopTableIds" value="${ids}" />
>>         </bean>
>>
>>     <camelContext id="camelroutes"
>> xmlns="http://camel.apache.org/schema/blueprint" trace="true">
>>
>>
>>                 <route>
>>                         <from uri="activemq:test"/>
>>                         <from uri="http4://{{url}}"/>
>>                         <to uri="activemq:retailout"/>
>>                 </route>
>>
>>                 <route>
>>                         <from uri="activemq:retailout"/>
>>                         <doTry>
>>                         <unmarshal ref="tst"/>
>>                         <to uri="log:output"/>
>>                         <to uri="bean:StoreLoadBean?method
>> =loadRetailStoreDataFromMap"/>
>>                         <log message="complete"/>
>>                         <doCatch>
>>                                 <exception>java.lang.Exception
>> </exception>
>>                                 <to uri="log:activemq.retailouterr
>> or?level=WARN"/>
>>                         </doCatch>
>>                         </doTry>
>>                 </route>
>>     </camelContext>
>>
>> </blueprint>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.
>> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: Help with JSON to POJO using XML Routes

Posted by Brad Johnson <br...@mediadriver.com>.
By the way, which version of Camel are you using?  And maybe I'm not quite
understanding what you're trying to do but it sound like you want to call *to
*an http endpoint and aren't waiting to receive from the endpoint.

On Tue, Sep 27, 2016 at 4:04 PM, jeffz <jz...@hotmail.com> wrote:

> I'm using Camel - through ServiceMix - to retrieve data from a web service,
> read the response and pass the data to another application.  This code was
> inherited, so much of the framework already exists.  it used to read from a
> database, but now needs to get its input from the web service response.
> Problem is, I can't figure out how to read the data into the bean and all
> my
> log statements within the java code get ignored. This makes debugging
> difficult.  I was hoping someone with more experience could shed some light
> on my situation.  For those paying attention, I did post on the ServiceMix
> board, but that was a different question in the same route.
>
> Questions:
>         1) How do I reference a set of java classes to unmarshal the
> message
> using the Jackson API?
>         2) How do I enable logging within the java bean?
>         3)These messages are quite large.  How do I stream data into the
> Exchange/POJO?
>
>
> Here are my routes:
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint
>     xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>     xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="
>       http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
>
>
>         <cm:property-placeholder id=placeholder"
> persistent-id="com.example">
>         <cm:default-properties>
>                 <cm:property name="url" value="example.com"/>
>         </cm:default-properties>
>     </cm:property-placeholder>
>
>
>         <bean id="espSendMailService" class="com.service.SendMailService">
>                 <property name="list" value="${list.id}" />
>         </bean>
>         <bean id="jack"
> class="org.apache.camel.component.jackson.JacksonDataFormat">
>         </bean>
>
>         <bean id="tst" class="com.example.RetailStoreReturnPOJO">
>         </bean>
>         <bean id="StoreLoadBean" class="com.example.StoreLoad">
>                 <property name="dataSource" ref="DB" />
>                 <property name="silverpopTableIds" value="${ids}" />
>         </bean>
>
>     <camelContext id="camelroutes"
> xmlns="http://camel.apache.org/schema/blueprint" trace="true">
>
>
>                 <route>
>                         <from uri="activemq:test"/>
>                         <from uri="http4://{{url}}"/>
>                         <to uri="activemq:retailout"/>
>                 </route>
>
>                 <route>
>                         <from uri="activemq:retailout"/>
>                         <doTry>
>                         <unmarshal ref="tst"/>
>                         <to uri="log:output"/>
>                         <to uri="bean:StoreLoadBean?method=
> loadRetailStoreDataFromMap"/>
>                         <log message="complete"/>
>                         <doCatch>
>                                 <exception>java.lang.Exception</exception>
>                                 <to uri="log:activemq.
> retailouterror?level=WARN"/>
>                         </doCatch>
>                         </doTry>
>                 </route>
>     </camelContext>
>
> </blueprint>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Help-with-JSON-to-POJO-using-XML-Routes-tp5788130.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>