Note that there are some explanatory texts on larger screens.

plurals
  1. POCamel Route/ActiveMQ unmarshaling JSON and sending to methods
    primarykey
    data
    text
    <p>I have a JSON response being posted to my activemq topic.I have set up my route to unmarshal this response to a POJO. I then want to step through 3 different methods in succession which make use of the fields in the POJO that have been populated by the JSON object.</p> <p>That is basically what I am trying to do. My problem lies in the fact that I am still new to Camel and I am not sure what/how I should be passing the information from the route into my methods so that I can make use of the POJO that has been populated by the JSON values.</p> <p>If that makes any sense at all. I am going to post my Camel Route, and Java class below, I will hold off on the pojo because it is simple enough, just 10 fields varying between int and string with some getter/setter methods. </p> <p><strong>EnrollResponse</strong> is the name of the POJO.</p> <p>Any help or guidance/tips for this would be greatly appreciated!</p> <p><strong>EDIT/UPDATE:</strong></p> <p>In the console in eclipse I am getting the Sys out's from my "setup" method, so I know that it at least is getting to that step. In my Logs though here is where the errors start:</p> <p>15:38:11,919 DEBUG [read #0 - JmsConsumer[Test.Central]] SendProcessor : >>>> Endpoint[bean://TriggeredSendBean?method=setup] Exchange[JmsMessage[JmsMessageID: ID:LT_John-51650-1363715888983-3:2:1:1:1]]</p> <p>15:38:12,396 INFO [read #0 - JmsConsumer[Test.Central]] ReflectionServiceFactoryBean : Creating Service {<a href="http://testAPI.com/wsdl/partnerAPI" rel="nofollow">http://testAPI.com/wsdl/partnerAPI</a>}PartnerAPI from WSDL: file:resources/META-INF/framework.wsdl</p> <p>15:38:13,159 DEBUG [read #0 - JmsConsumer[Test.Central]] DefaultErrorHandler : Failed delivery for (MessageId: topic_Test.Central_ID_LT_John-51650-1363715888983-3_2_1_1_1 on ExchangeId: ID-LT-John-52743-1363721881958-0-1). On delivery attempt: 0 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:LT_John-51650-1363715888983-3:2:1:1:1]]</p> <p>15:38:13,160 ERROR [read #0 - JmsConsumer[Test.Central]] DefaultErrorHandler : Failed delivery for (MessageId: topic_Test.Central_ID_LT_John-51650-1363715888983-3_2_1_1_1 on ExchangeId: ID-LT-John-52743-1363721881958-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:LT_John-51650-1363715888983-3:2:1:1:1]]</p> <p>org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:LT_John-51650-1363715888983-3:2:1:1:1]]</p> <hr> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- Configures the Camel Context--&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt; &lt;!-- load properties --&gt; &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="locations" value="file:backend.properties" /&gt; &lt;/bean&gt; &lt;bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"&gt; &lt;property name="location" value="file:backend.properties" /&gt; &lt;/bean&gt; &lt;bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt; &lt;property name="brokerURL" value="tcp://0.0.0.0:61616?useLocalHost=true" /&gt; &lt;/bean&gt; &lt;bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"&gt; &lt;property name="maxConnections" value="8" /&gt; &lt;property name="maximumActive" value="500" /&gt; &lt;property name="connectionFactory" ref="jmsConnectionFactory" /&gt; &lt;/bean&gt; &lt;bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"&gt; &lt;property name="connectionFactory" ref="pooledConnectionFactory" /&gt; &lt;property name="transacted" value="false" /&gt; &lt;property name="concurrentConsumers" value="1" /&gt; &lt;/bean&gt; &lt;bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"&gt; &lt;property name="configuration" ref="jmsConfig" /&gt; &lt;/bean&gt; &lt;!-- Custom Loaded Beans --&gt; &lt;bean id="TriggeredSendBean" class="com.backend.trigger.ClientTest"/&gt; &lt;bean id="EnrollResponse" class="com.testObjects.EnrollResponse" /&gt; &lt;!-- camel configuration --&gt; &lt;camel:camelContext xmlns="http://camel.apache.org/schema/spring"&gt; &lt;camel:dataFormats&gt; &lt;json id="UnmarshalToPOJO" library="Jackson" unmarshalTypeName="com.testObjects.EnrollResponse" /&gt; &lt;/camel:dataFormats&gt; &lt;camel:route id="genericMessageHandler" streamCache="true"&gt; &lt;from uri="activemq:topic:Test.Central" /&gt; &lt;unmarshal ref="UnmarshalToPOJO" /&gt; &lt;to uri = "bean:TriggeredSendBean?method=setup" /&gt; &lt;to uri = "bean:TriggeredSendBean?method=addSubscriberAllList" /&gt; &lt;to uri = "bean:TriggeredSendBean?method=sendWelcomeEmail" /&gt; &lt;/camel:route&gt; &lt;/camel:camelContext&gt; </code></pre> <p></p> <hr> <pre><code>public class ClientTest { static String user = null; static String password = null; static String customerKeyWelcomeEmailTest = null; static String validFromAddress = null; static String validFromName = null; public static void setup(Exchange exchange) { System.out.println("Exchange " + exchange.toString()); //Retrieve settings from properties file Properties properties = getProperties(); user = properties.getProperty("user"); password = properties.getProperty("password"); customerKeyWelcomeEmailTest = properties.getProperty("customerKeyWelcomeEmailTest"); validFromAddress = properties.getProperty("validFromAddress"); validFromName = properties.getProperty("validFromName"); System.out.println("user==&gt; " + user); System.out.println("password==&gt; " + password); System.out.println("customerKey==&gt; " + customerKeyWelcomeEmailTest); System.out.println("validFromAddress==&gt; " + validFromAddress); System.out.println("validFromName==&gt; " + validFromName); //Create PartnerAPI stub. PartnerAPI service = new PartnerAPI(); Soap stub = service.getSoap(); } /** * Adding specific subscriber to the "All subscribers" list in */ private static void addSubscriberAllList(Soap stub, Exchange exchange, EnrollResponse enrollResponse) { // Checking to see if enrollResponse is being populated System.out.println(enrollResponse.getEmail()); System.out.println(enrollResponse.getFirstname()); System.out.println(enrollResponse.getLastname()); System.out.println(enrollResponse.getAcctid()); System.out.println(enrollResponse.getCid()); System.out.println(enrollResponse.getMyfridays()); System.out.println(enrollResponse.getPhone()); System.out.print(enrollResponse.getPoints()); Subscriber subscriber = new Subscriber(); subscriber.setEmailAddress(enrollResponse.getEmail()); subscriber.setSubscriberKey(enrollResponse.getAcctid()); subscriber.setStatus(SubscriberStatus.ACTIVE); Attribute a1 = new Attribute(); a1.setName("firstname"); a1.setValue(enrollResponse.getFirstname()); //Can add more attributes as needed Attribute[] AttributeLists = {a1}; subscriber.getAttributes().addAll(Arrays.asList(AttributeLists)); APIObject[] apiObjects = {subscriber}; try { CreateRequest createRequest = new CreateRequest(); createRequest.setOptions(new CreateOptions()); createRequest.getObjects().addAll(Arrays.asList(apiObjects)); CreateResponse createResponse = stub.create(createRequest); System.out.println("Subscriber created in all subscriber List: " + createResponse.getOverallStatus()); } catch (Exception e) { e.printStackTrace(); } } /** * Testing Triggered Send SPECIFIC SUBSCRIBER */ private static void sendWelcomeEmail(Soap stub, Exchange exchange, EnrollResponse enrollResponse) { Subscriber[] testArray = new Subscriber[1]; Owner ownerSubscriberValid = new Owner(); System.out.println("****************** STARTING TRIGGERED SEND TEST ******************"); //Specify TriggeredSendDefinition and initialize the TriggeredSend TriggeredSendDefinition triggeredSendDefinition = new TriggeredSendDefinition(); triggeredSendDefinition.setCustomerKey(customerKeyWelcomeEmailTest); TriggeredSend triggeredSend = new TriggeredSend(); triggeredSend.setTriggeredSendDefinition(triggeredSendDefinition); //Create a valid Subscriber Subscriber subscriberValid = new Subscriber(); subscriberValid.setEmailAddress(enrollResponse.getEmail()); subscriberValid.setSubscriberKey(enrollResponse.getAcctid()); ownerSubscriberValid.setFromAddress(validFromAddress); ownerSubscriberValid.setFromName(validFromName); subscriberValid.setOwner(ownerSubscriberValid); //Populate array of Subscribers testArray[0] = subscriberValid; java.util.List&lt;Subscriber&gt; list = Arrays.asList(testArray); triggeredSend.getSubscribers().addAll( list ); //Send the TriggeredSend using Create call try{ CreateRequest createRequest = new CreateRequest(); CreateOptions createOptions = new CreateOptions(); createRequest.setOptions(createOptions); java.util.List&lt;APIObject&gt; listAPIObject = Arrays.asList(new APIObject[] {triggeredSend}); createRequest.getObjects().addAll(listAPIObject); CreateResponse createResponse = stub.create(createRequest); System.out.println( "overall status message: " + createResponse.getOverallStatus() ); java.util.List&lt;CreateResult&gt; listCreateResult = createResponse.getResults(); CreateResult[] createResult = listCreateResult.toArray(new CreateResult[listCreateResult.size()]); for ( CreateResult status : createResult ) { System.out.println("create status message: " + status.getStatusMessage()); System.out.println("create status code: " + status.getStatusCode()); } //Validate the send and get failure information TriggeredSendCreateResult triggeredSendCreateResult = (TriggeredSendCreateResult)createResult[0]; assert(triggeredSendCreateResult.getSubscriberFailures() != null); System.out.println("size of failures array: " + triggeredSendCreateResult.getSubscriberFailures().size()); System.out.println("email address: " + triggeredSendCreateResult.getSubscriberFailures().get(0).getSubscriber().getEmailAddress()); System.out.println("error description: " + triggeredSendCreateResult.getSubscriberFailures().get(0).getErrorDescription()); System.out.println("error code: " + triggeredSendCreateResult.getSubscriberFailures().get(0).getErrorCode()); assert( createResult != null ); assert(createResult[0].getStatusMessage().equals("OK")); System.out.println( "****************** ENDING TRIGGERED SEND TEST ******************" ); } catch(Exception e) { e.printStackTrace(); } } /** * Retrieve properties file. * */ public static Properties getProperties() { Properties properties = new Properties(); try{ FileInputStream fileInputStream = new FileInputStream("properties.xml"); properties.loadFromXML(fileInputStream); } catch (Exception e){ e.printStackTrace(); } return properties; } </code></pre> <p>} </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload