I used ESB to transform the XML message to CEP http receiver, the XML:
<result>
<event>
<tag>0101A01B001</tag>
<time>10:00:01</time>
<value>30.45</value>
</event>
<event>
<tag>0101A01B001</tag>
<time>10:00:02</time>
<value>33.7</value>
</event>
<event>
<tag>0101A01B001</tag>
<time>10:00:03</time>
<value>23.4</value>
</event>
<event>
<tag>0101A01B001</tag>
<time>10:00:04</time>
<value>33.15</value>
</event>
</result>
And the http receiver in CEP :
<?xml version="1.0" encoding="UTF-8"?>
<eventReceiver name="recv_dss1" statistics="disable" trace="enable" xmlns="http://wso2.org/carbon/eventreceiver">
<from eventAdapterType="http">
<property name="transports">all</property>
</from>
<mapping customMapping="enable" type="xml">
<property>
<from xpath="/result/data/tag"/>
<to name="tag" type="string"/>
</property>
<property>
<from xpath="/result/data/time"/>
<to name="time" type="long"/>
</property>
<property>
<from xpath="/result/data/value"/>
<to name="value" type="double"/>
</property>
</mapping>
<to streamName="dss_stream3" version="1.0.0"/>
</eventReceiver>
The http receiver only receive the first "event" node every time, so how to config the receiver can receive all the "event" nodes one time ?
In the configuration you need to configure "Parent Selector XPath Expression" to indicate the parent element of the events, in this case its /result.
Then elements of the event should be referred from the parent tag, e.g. /data/time
Refer to WSO2 CEP 4.1 XML input mapping documentation for details : https://docs.wso2.com/display/CEP410/Input+Mapping+Types#InputMappingTypes-XMLinputmappingXMLInputMapping
Related
I am trying to schedule a task wherein I want to call a proxy which does not take any input payload. This is the code I've tried:
<?xml version="1.0" encoding="UTF-8"?>
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="ScheduleOrderCreation" xmlns="http://ws.apache.org/ns/synapse">
<trigger count="2" interval="5"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" value="" name="message">
</property>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="proxyName" value="CreateOrders"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="injectTo" value="proxy"/>
</task>
Since I don't want to pass any input payload, I've set value ="" in "message" property. But I get the following error:
ERROR {MessageInjector} - message or registry-key not set
How can I handle this in my task? Should I write a separate class implementing the Tasks interface to call this proxy?
Just add an Empty Payload there.
<?xml version="1.0" encoding="UTF-8"?>
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="ScheduleOrderCreation" xmlns="http://ws.apache.org/ns/synapse">
<trigger cron="0 0/1 * 1/1 * ? *"/>
<property name="injectTo" value="proxy" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="proxyName" value="CreateOrders" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
<sfdc xmlns=""/>
</property>
</task>
I am trying to connect a WSO2 CEP server to a WSO2 Message Broker server.
I have created a jndi.properties file:
connectionfactory.TopicConnectionFactory = amqp://admin:admin#clientid/carbon?brokerlist='tcp://192.168.11.2:5673'
topic.testTopic = testTopic
an input event adaptor:
<?xml version="1.0" encoding="UTF-8"?>
<inputEventAdaptor name="MBJMSInputAdaptor" statistics="enable"
trace="enable" type="jms" xmlns="http://wso2.org/carbon/eventadaptormanager">
<property name="java.naming.provider.url">repository/conf/jndi.properties</property>
<property name="transport.jms.SubscriptionDurable">false</property>
<property name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</property>
<property name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</property>
<property name="transport.jms.DestinationType">topic</property>
</inputEventAdaptor>
a stream definition:
<streamDefinitions xmlns="http://wso2.org/carbon/databridge">
<streamDefinition>
{
"name":"testStream",
"version":"1.0.0",
"payloadData":[
{"name":"id","type":"INT"},
{"name":"name","type":"STRING"}
]
}
</streamDefinition>
</streamDefinitions>
and an event builder:
<?xml version="1.0" encoding="UTF-8"?>
<eventBuilder name="testBuilder" statistics="enable" trace="enable" xmlns="http://wso2.org/carbon/eventbuilder">
<from eventAdaptorName="MBJMSInputAdaptor" eventAdaptorType="jms">
<property name="topic">testTopic</property>
</from>
<mapping customMapping="enable" type="json">
<property>
<from jsonPath="id"/>
<to name="id" type="int"/>
</property>
<property>
<from jsonPath="name"/>
<to name="name" type="string"/>
</property>
</mapping>
<to streamName="testStream" version="1.0.0"/>
</eventBuilder>
Unfortunately, the WSO2 CEP server does not receive messages from the WSO2 Message Broker server, and throws the following exception:
[2014-11-28 13:00:00,226] INFO - {JMSEventAdaptorType} JMS input event adaptor loading listeners
Exception in thread "Thread-29" java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:988)
at org.wso2.carbon.event.input.adaptor.jms.JMSEventAdaptorType.createJMSAdaptorListener(JMSEventAdaptorType.java:291)
at org.wso2.carbon.event.input.adaptor.jms.JMSEventAdaptorType.tryStartAdaptor(JMSEventAdaptorType.java:262)
at org.wso2.carbon.event.input.adaptor.jms.internal.ds.JMSEventAdaptorServiceHolder.loadLateStartEventAdaptors(JMSEventAdaptorServiceHolder.java:66)
at org.wso2.carbon.event.input.adaptor.jms.internal.ds.JMSEventAdaptorServiceHolder$1.run(JMSEventAdaptorServiceHolder.java:43)
at java.lang.Thread.run(Thread.java:745)
Could you help me debugging this exception?
If you like to debug the code then you can checkout the source from below location [1].. But I think below blog [2] will help you to achieve the usecase.
[1]https://svn.wso2.org/repos/wso2/carbon/platform/branches/turing/components/event-stream/event-input-adaptor/org.wso2.carbon.event.input.adaptor.jms/1.0.1
[2] http://sajithr.blogspot.com/2014/04/sample-on-using-wso2-mb-with-wso2-cep.html
i am using wso2cep 3.0.0 and activemq5.8.0
As per CEP documents i wish to Publish events using CEP.
For that i started activemq with 2 define QUEUES with the name jmsProxy for incoming message and JmsProxy for out message.I added required jars in CEP lib activemq-broker-5.8.0.jar,activemq-client-5.8.0.jar,axiom.jar,geronimo-j2ee-management_1.1_spec-1.0.1.jar,geronimo-jms_1.1_spec-1.1.1.jar,hawtbuf-1.2.jar,xpp3-1.1.4c.jar,xstream-1.4.4.jar
my configuration is like this
InputEventAdaptor
<?xml version="1.0" encoding="UTF-8"?>
<inputEventAdaptor name="jmsProxy" statistics="disable" trace="enable"
type="jms" xmlns="http://wso2.org/carbon/eventadaptormanager">
<property name="java.naming.provider.url">tcp://localhost:61616</property>
<property name="transport.jms.SubscriptionDurable">true</property>
<property name="transport.jms.DurableSubscriberName">jmsProxy</property>
<property name="transport.jms.UserName">admin</property>
<property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
<property name="transport.jms.Password">admin</property>
<property name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</property>
<property name="transport.jms.DestinationType">queue</property>
</inputEventAdaptor>
above for incoming messages which will pick the messages from jmsProxy queue
But its unable to pick the message from jmsProxy Queue.How would i initiate this to get the message into CEP and
outputEventAdaptor
<?xml version="1.0" encoding="UTF-8"?>
<outputEventAdaptor name="JmsProxy" statistics="disable" trace="disable"
type="jms" xmlns="http://wso2.org/carbon/eventadaptormanager">
<property name="java.naming.security.principal">admin</property>
<property name="java.naming.provider.url">tcp://localhost:61616</property>
<property name="java.naming.security.credentials">admin</property>
<property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
<property name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</property>
<property name="transport.jms.DestinationType">queue</property>
</outputEventAdaptor>
event builder configuration like this
<?xml version="1.0" encoding="UTF-8"?>
<eventBuilder name="ReadingsDtoBuilder" statistics="disable"
trace="disable" xmlns="http://wso2.org/carbon/eventbuilder">
<from eventAdaptorName="jmsProxy" eventAdaptorType="jmsProxy">
<property name="transport.jms.Destination">JmsProxy</property>
</from>
<mapping customMapping="disable"
parentXpath="//ReadingsLiteTaildtos" type="xml">
<property>
<from xpath="//ReadingsLiteTaildto/ParameterId"/>
<to name="meta_parameterId" type="string"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/Slno"/>
<to name="meta_slno" type="string"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/FinalValue"/>
<to name="finalValue" type="int"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/InputText"/>
<to name="inputText" type="string"/>
</property>
<property>
<from xpath="//ReadingsLiteTaildto/InputValue"/>
<to name="inputValue" type="double"/>
</property>
</mapping>
<to streamName="org.sample.readings.dto.stream" version="1.0.0"/>
</eventBuilder>
The execution plan can be as follows.like this
<?xml version="1.0" encoding="UTF-8"?>
<executionPlan name="ReadingsAnalyzer" statistics="disable"
trace="disable" xmlns="http://wso2.org/carbon/eventprocessor">
<description>This execution plan analyzes readings and triggers notifications based on threshold.</description>
<siddhiConfiguration>
<property name="siddhi.enable.distributed.processing">false</property>
<property name="siddhi.persistence.snapshot.time.interval.minutes">0</property>
</siddhiConfiguration>
<importedStreams>
<stream as="readings" name="org.sample.readings.dto.stream" version="1.0.0"/>
</importedStreams>
<queryExpressions><![CDATA[from readings[finalValue > 100]
select *
insert into notificationStream;]]></queryExpressions>
<exportedStreams>
<stream name="notificationStream" valueOf="notificationStream" version="1.0.0"/>
</exportedStreams>
</executionPlan>
I defined streams inside stream-manager-config.xml similar to the following.
<streamDefinition name="org.sample.readings.dto.stream" version="1.0.0">
<metaData>
<property name="parameterId" type="STRING"/>
<property name="slno" type="STRING"/>
</metaData>
<payloadData>
<property name="finalValue" type="INT"/>
<property name="inputText" type="STRING"/>
<property name="inputValue" type="DOUBLE"/>
</payloadData>
</streamDefinition>
<streamDefinition name="notificationStream" version="1.0.0">
<metaData>
<property name="parameterId" type="STRING"/>
<property name="slno" type="STRING"/>
</metaData>
<payloadData>
<property name="finalValue" type="INT"/>
<property name="inputText" type="STRING"/>
<property name="inputValue" type="DOUBLE"/>
</payloadData>
</streamDefinition>.
its look like all well while i am sending any message to my jmsProxy queue the message is not reflecting to CEP for event and i am getting this message in CEP
[2014-02-18 11:57:53,159] INFO - {EventBuilderDeployer} Event Builder undeployed successfully : ReadingsDtoBuilder.xml
[2014-02-18 11:57:53,160] INFO - {EventBuilderDeployer} Event builder deployment held back and in inactive state :ReadingsDtoBuilder, Waiting for Input Event Adaptor dependency :jmsProxy
[2014-02-18 12:03:58,006] INFO - {InputEventAdaptorConfigurationFilesystemInvoker} Input Event Adaptor configuration deleted from file system : jmsProxy.xml
[2014-02-18 12:03:58,006] INFO - {InputEventAdaptorDeployer} Input Event Adaptor undeployed successfully : jmsProxy.xml
[2014-02-18 12:03:58,008] INFO - {InputEventAdaptorConfigurationFilesystemInvoker} Input Event Adaptor configuration saved in th filesystem : jmsProxy
[2014-02-18 12:03:58,009] INFO - {InputEventAdaptorDeployer} Input Event Adaptor deployed successfully and in active state : jmsProxy
[2014-02-18 12:03:58,009] INFO - {EventBuilderDeployer} Event Builder undeployed successfully : ReadingsDtoBuilder.xml
[2014-02-18 12:03:58,009] INFO - {EventBuilderDeployer} Event builder deployment held back and in inactive state :ReadingsDtoBuilder, Waiting for Input Event Adaptor dependency :jmsProxy
Looking at your configuration, it seems that the event builder configuration is incorrect. Event adaptor type should be 'jms' in the event builder configuration.
<from eventAdaptorName="jmsProxy" eventAdaptorType="jms">
Please correct this as above to get it working. You can enable tracing [1] to see if messages come to a particular component of CEP.
[1] https://docs.wso2.org/display/CEP300/CEP+Event+Tracer
In wso2 esb 4.5.1, i don't have option of direct task scheduling for sequence or proxy service. so, i try to use property name SoapAction and to in task scheduling but iam getting the below error,
ERROR - TaskManagementHelper Invalid XML has been provided for property : message
ERROR - TaskManagementHelper Invalid XML has been provided for property : format
Here is a sample "Scheduled Task" that inject 2 times an XML message
<root>
<node1>value1</node1>
</root>
It works with ESB 4.5.1
<?xml version="1.0" encoding="UTF-8"?>
<task xmlns="http://ws.apache.org/ns/synapse"
name="TestTask"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger count="2" interval="5"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="format"
value="application/xml"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="to"
value="TestTaskProxy"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<root xmlns="">
<node1>value1</node1>
</root>
</property>
</task>
format and to properties are literal types
message property is an XML type
Would anyone be able to advise me on the best way of handling access to multiple Rest web services using Springs RestTemplate?
I know that the RestTemplate object has a message converter reference (MarshallingHttpMessageConverter) which in turn has a reference to an unmarshaller. In my case I am using the Spring Frameworks CastorMarshaller object with associated mapping file.
Normally I could have just added all my mappings to one Castor mapping file. However in my case all the web services are of this format (block below) with the < rows ... /> holding different entities depending on the service called.
<data>
<output>
<dataset>
<row id="" .... />
<row id="" .... />
<row id="" .... />
<row id="" .... />
<row id="" .... />
</dataset>
</output>
<nextUpdate><nextUpdate/>
</data>
The CastorMarshaller is injected into the MessageConverter which itself is injected into the RestTemplate in the application context configuration file.
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="castorMarshaller"/>
<property name="unmarshaller" ref="castorMarshaller"/>
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="application"/>
<constructor-arg index="1" value="xml"/>
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="text"/>
<constructor-arg index="1" value="xml"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation" value="classpath:oxm-mapping-worldweather.xml"/>
</bean>
Possible options that I have been thinking about:
1 Create multiple RestTemplates for each Rest service.
2 Create multiple MessageConverters for the different services and change the message converters on the template when accessing a different service.
3 Create multiple CasterMarshaller objects for the different services and update the message converter with the new unmarshaller
What is the best way to approach handling multiple services like this with the same root and sub elements?
Thanks in advance
Sman UK
If specifying multiple mapping files is the issue then below is the solution.
Use mappingLocations property instead of mappingLocation as given below,
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocations">
<list>
<value>classpath:oxm-mapping-worldweather.xml</value>
<value>classpath:sample-mapping.xml</value>
</list>
</property>
</bean>