activemqトピックにJSON応答が投稿されています。この応答をPOJOにアンマーシャリングするためのルートを設定しました。次に、JSONオブジェクトによって入力されたPOJOのフィールドを利用する3つの異なるメソッドを連続して実行したいと思います。
それが基本的に私がやろうとしていることです。私の問題は、私がまだCamelに慣れていないという事実にあり、JSON値によって入力されたPOJOを利用できるように、ルートからメソッドに情報を渡す方法がわかりません。 。
それがまったく意味があるのなら。Camel RouteとJavaクラスを以下に投稿します。pojoは非常に単純で、いくつかのgetter / setterメソッドを使用してintとstringの間で10フィールドしか変化しないため、pojoを保留します。
EnrollResponseはPOJOの名前です。
これに関するヘルプやガイダンス/ヒントをいただければ幸いです。
編集/更新:
Eclipseのコンソールでは、「セットアップ」メソッドからSysを取得しているので、少なくともそのステップに到達していることがわかります。私のログでは、ここからエラーが始まります。
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]]
15:38:12,396 INFO [read#0 --JmsConsumer [Test.Central]] ReflectionServiceFactoryBean:サービスの作成{ http://testAPI.com/wsdl/partnerAPI } WSDLからのPartnerAPI:file:resources / META-INF / framework.wsdl
15:38:13,159 DEBUG [read#0 --JmsConsumer [Test.Central]] DefaultErrorHandler:(MessageId:topic_Test.Central_ID_LT_John-51650-1363715888983-3_2_1_1_1 on ExchangeId:ID-LT-John-52743-1363721881958-0- 1)。配信試行時:0キャッチ:org.apache.camel.CamelExecutionException:交換での実行中に例外が発生しました:Exchange [JmsMessage [JmsMessageID:ID:LT_John-51650-1363715888983-3:2:1:1:1]]
15:38:13,160エラー[読み取り#0-JmsConsumer [Test.Central]] DefaultErrorHandler:(MessageId:topic_Test.Central_ID_LT_John-51650-1363715888983-3_2_1_1_1 on ExchangeId:ID-LT-John-52743-1363721881958-0- 1)。配信試行後に使い果たされました:1がキャッチされました:org.apache.camel.CamelExecutionException:交換での実行中に例外が発生しました:Exchange [JmsMessage [JmsMessageID:ID:LT_John-51650-1363715888983-3:2:1:1:1]]
org.apache.camel.CamelExecutionException:交換での実行中に例外が発生しました:Exchange [JmsMessage [JmsMessageID:ID:LT_John-51650-1363715888983-3:2:1:1:1]]
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<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">
<!-- load properties -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="file:backend.properties" />
</bean>
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="file:backend.properties" />
</bean>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://0.0.0.0:61616?useLocalHost=true" />
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="maxConnections" value="8" />
<property name="maximumActive" value="500" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory" />
<property name="transacted" value="false" />
<property name="concurrentConsumers" value="1" />
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
<!-- Custom Loaded Beans -->
<bean id="TriggeredSendBean" class="com.backend.trigger.ClientTest"/>
<bean id="EnrollResponse" class="com.testObjects.EnrollResponse" />
<!-- camel configuration -->
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<camel:dataFormats>
<json id="UnmarshalToPOJO" library="Jackson" unmarshalTypeName="com.testObjects.EnrollResponse" />
</camel:dataFormats>
<camel:route id="genericMessageHandler" streamCache="true">
<from uri="activemq:topic:Test.Central" />
<unmarshal ref="UnmarshalToPOJO" />
<to uri = "bean:TriggeredSendBean?method=setup" />
<to uri = "bean:TriggeredSendBean?method=addSubscriberAllList" />
<to uri = "bean:TriggeredSendBean?method=sendWelcomeEmail" />
</camel:route>
</camel:camelContext>
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==> " + user);
System.out.println("password==> " + password);
System.out.println("customerKey==> " + customerKeyWelcomeEmailTest);
System.out.println("validFromAddress==> " + validFromAddress);
System.out.println("validFromName==> " + 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<Subscriber> 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<APIObject> 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<CreateResult> 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;
}
}