getting an exception on running sample of wso2cep - wso2

I am a beginner in wso2cep. I want to execute the first sample of WSO2 CEP documentation. I use windows10 as operating system. I type the following command but i getting following exeption in Console output:
c:\wso2cep-4.0.0\samples\producers\http>ant Durl=http://localhost:9763/endpoints/httpReceiver -Dsn=0001
Buildfile: c:\wso2cep-4.0.0\samples\producers\http\build.xml
init:
compile:
[javac] c:\wso2cep-4.0.0\samples\producers\http\build.xml:71: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to
false
for repeatable builds
[copy] Copying 1 file to c:\wso2cep-4.0.0\samples\producers\http\temp\classes
run:
[echo] Configure -Durl=xxxx and ( -DfilePath=xxxx or -Dsn='sample number')
optionally use -Dusername=xxxx -Dpassword=xxxx
[java] [main] INFO org.wso2.carbon.sample.http.Http - Starting WSO2 Http
Client
[java] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:4
[java] at org.wso2.carbon.sample.http.Http.main(Unknown Source)
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 3 seconds
I add this line: <property name="filePath" value=""""/> to the build.xml file but I still get above exception. My build.xml file become as following:
<property name="carbon.home" value="${basedir}"/>
<property name="lib" value="${carbon.home}/repository/lib"/>
<property name="tempdir" value="${carbon.home}/tmp/setup"/>
<property name="output.dir" value="${carbon.home}/tmp/wso2"/>
<property name="filePath" value=""""/>
Should i change "filePath" to another thing? Should i add this line to build.xml file or change other lines? Please help and explain to me.

Related

How to transfer multiple files to different directories at the same time

I have created a file transfer service using wso2 integration studio. This service works with a file connector. I have it working from one directory to another, however I want to change this method to work with multiple directories. Initially, I had 2 sequences and a task to do this process, namely, " "FileListenerSeq" sequence, "FileReadSeq" sequence and "FileTask" scheduled task.
I have now created 2 extra sequences and a new task to do the same process. Namely, "FileReplyListenerSeq" sequence, "FileReplyReadSeq" sequence and "ReplyTask" scheduled task.
I want these sequences to work at the same time but even after creating the new sequences and task, the micro-integrator only reads the first initial process. I tried adding the same process twice in one sequence and it works but works only after the first one is done (which makes sense)
Is there a way to do this concurrently with multiple sequences that work at the same time?
environment specs:
Integration studio : 8.1.0
wso2 micro integrator : 7.1.0
file connector : 4.0.11
process flow from directory to directory:
LOCATION 1: FOLDERA --> LOCATION 2: FOLDERB ( This is the process that was created initially and works)
LOCATION 1: FOLDERC --> LOCATION 2: FOLDERD ( This is the new process I want to work with the initial process)
Any assistance will be greatly appreciated.
FileReadSeq source code:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="FileReadSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property description="file name" expression="//file/text()" name="FILE_TO_READ" scope="default" type="STRING"/>
<log level="custom">
<property expression="$ctx:FILE_TO_READ" name="Files to read"/>
</log>
<file.read configKey="LocalFolderAConnection">
<path>{fn:concat('/OUTGOING/' , $ctx:FILE_TO_READ)}</path>
<readMode>Complete File</readMode>
<startLineNum>0</startLineNum>
<endLineNum>0</endLineNum>
<lineNum>0</lineNum>
<contentType>application/binary</contentType>
<includeResultTo>Message Body</includeResultTo>
<enableStreaming>true</enableStreaming>
<enableLock>false</enableLock>
</file.read>
<file.write configKey="LocalFolderBConnection">
<filePath>{$ctx:FILE_PATH}</filePath>
<mimeType>Automatic</mimeType>
<compress>false</compress>
<writeMode>Overwrite</writeMode>
<enableStreaming>true</enableStreaming>
<appendNewLine>false</appendNewLine>
<enableLock>false</enableLock>
<includeResultTo>Message Body</includeResultTo>
<updateLastModified>true</updateLastModified>
</file.write>
<file.read configKey="LocalFolderCConnection">
<path>{fn:concat('/Incoming/' , $ctx:FILE_TO_READ)}</path>
<readMode>Complete File</readMode>
<startLineNum>0</startLineNum>
<endLineNum>0</endLineNum>
<lineNum>0</lineNum>
<contentType>application/binary</contentType>
<includeResultTo>Message Body</includeResultTo>
<enableStreaming>true</enableStreaming>
<enableLock>false</enableLock>
</file.read>
<file.write configKey="LocalFolderDConnection">
<filePath>{$ctx:FILE_PATH}</filePath>
<mimeType>Automatic</mimeType>
<compress>false</compress>
<writeMode>Overwrite</writeMode>
<enableStreaming>true</enableStreaming>
<appendNewLine>false</appendNewLine>
<enableLock>false</enableLock>
<includeResultTo>Message Body</includeResultTo>
<updateLastModified>true</updateLastModified>
</file.write>
<filter regex="true" source="//writeResult/success/text()">
<then>
<log description="Status Log " level="custom">
<property expression="$ctx:FILE_TO_READ" name="files successfully moved"/>
</log>
</then>
<else>
<log description="Failed log">
<property name="message" value="Files failed to move"/>
</log>
</else>
</filter>
</sequence>
I think the best solution for the requirement would be to use file inbound endpoints[1]. You can create multiple inbound endpoints for each file location from where you need to process files. The inbound endpoint will be listening to the defined transport.vfs.FileURI location and the files will be processed parallelly from multiple inbound endpoints. Since the requirement is to transfer the files, you can set the transport.vfs.ActionAfterProcess parameter to MOVE and set the destination file location using the transport.vfs.MoveAfterProcess parameter.
Please refer to the documentation here[1] for more details.
[1] https://ei.docs.wso2.com/en/latest/micro-integrator/use-cases/examples/inbound_endpoint_examples/file-inbound-endpoint/

ESB WSO2 | Trying to send an email through email connector and getting "org.wso2.carbon.connector.email.send cannot be found" error

I'm trying to send an email using email connector from esb wso2 but I'm getting this error:
Invoking Target EIP Sequence org.wso2.carbon.connector.email.send paramNames : [from, to, subject, content, contentType]
[2022-07-22 10:52:14,113] ERROR {org.apache.synapse.mediators.template.InvokeMediator} - Sequence template org.wso2.carbon.connector.email.send cannot be found
[2022-07-22 10:52:14,121] DEBUG {org.apache.synapse.debug.SynapseDebugManager} - Mediation flow terminated for id urn:uuid:3f3f9864-bbc1-4e95-a4bf-1574196dfb8c
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.core.axis2.SynapseMessageReceiver} - Executing fault handler due to exception encountered
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.FaultHandler} - ERROR_CODE : 0
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.FaultHandler} - ERROR_MESSAGE : Sequence template org.wso2.carbon.connector.email.send cannot be found
[2022-07-22 10:52:14,122] WARN {org.apache.synapse.FaultHandler} - ERROR_DETAIL : org.apache.synapse.SynapseException: Sequence template org.wso2.carbon.connector.email.send cannot be found
This is my api which I use:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api/send/email" name="api.send.email" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property expression="json-eval($.from)" name="from" scope="default" type="STRING"/>
<property expression="json-eval($.to)" name="to" scope="default" type="STRING"/>
<property expression="json-eval($.subject)" name="subject" scope="default" type="STRING"/>
<property expression="json-eval($.content)" name="content" scope="default" type="STRING"/>
<property expression="json-eval($.contentType)" name="contentType" scope="default" type="STRING"/>
<log level="custom">
<property expression="$ctx:from" name="Log_from:"/>
<property expression="$ctx:to" name="Log_to:"/>
<property expression="$ctx:subject" name="Log_subject:"/>
<property expression="$ctx:content" name="Log_content:"/>
<property expression="$ctx:contentType" name="Log_contentType:"/>
</log>
<email.send configKey="TEST_SMTP_CONNECTION">
<from>{json-eval($.from)}</from>
<to>{json-eval($.to)}</to>
<subject>{json-eval($.subject)}</subject>
<content>{json-eval($.content)}</content>
<contentType>{json-eval($.contentType)}</contentType>
</email.send>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
I think the problem is based on the fact that I don't think I added the connector on my project in the correct way.
So, first of all I added a connector on my main project (where I have APIs, endpoints etc) - Right Click - Add or Remove Connector/Module - then I added the email connector)
Then I created a new Connector Exporter on my project (Right Click on an empty space on my Project Explorer - I named the exporter 'test' - and I think here is the problem:
What Group ID, Parent Group ID and Parent Artifact ID I should choose? (same question when I'm making Composite Application for connector)
LATER EDIT*:
When I'm deploying de car. app for the email connector I'm getting these errors:
Error in instantiating class : org.wso2.carbon.connector.operations.list.EmailGetAttachment java.lang.NoClassDefFoundError: org/wso2/carbon/connector/core/exception/ContentBuilderException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
Unable to update status for : {org.wso2.carbon.connector}email :: Template configuration : null cannot be builtfor Synapse Library artifact : getEmailAttachment org.apache.synapse.deployers.SynapseArtifactDeploymentException: Template configuration : null cannot be builtfor Synapse Library artifact : getEmailAttachment
To answer your questions, if you have a Maven MultiModule Project you can get the details of the parent project from the pom.xml of the parent project.(This is the root pom.xml typically)
The easiest way to resolve your problem is to create your project from an existing template which will make sure projects are created correctly. Inorder to do that, follow the steps below.
Open Integration Studio and Go to Help -> Getting Started.
Then select the Email Service sample project, give it a name and create the project.
Now you should have a full working project with a Connector Exported.
In the future for creating new projects, you can refer to this document.

The script mediator error in WSO2AM 1.5

I try to add a sequence which contains a java script mediator as below :
"<sequence name="response">
<script language="js">
mc.setPayloadXML(
<greeting>Hello World</greeting>
);
</script>
<header name="To" action="remove"/>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="RESPONSE" value="true"/>
<send/>
<log level="full"/>
</sequence>"
*Howerver,it occurs a error once I press the Update Button,the whole function stack is shown in the log, I check the jar "bsf-all,3.0.0.wso2v2" and it really contains the missing class and the jar is shown in the bundles info "bsf-all,3.0.0.wso2v2,../plugins/bsf-all_3.0.0.wso2v2.jar,4,true" :*
"com/sun/phobos/script/javascript/RhinoScriptEngineFactory {org.apache.axis2.rpc.receivers.RPCMessageReceiver}
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at ......
Caused by: java.lang.NoClassDefFoundError: com/sun/phobos/script/javascript/RhinoScriptEngineFactory
at org.apache.synapse.mediators.bsf.ScriptMediator.initScriptEngine(ScriptMediator.java:475)
at org.apache.synapse.mediators.bsf.ScriptMediator.initInlineScript(ScriptMediator.java:341)
at org.apache.synapse.mediators.bsf.ScriptMediator.(ScriptMediator.java:146)
at org.apache.synapse.mediators.bsf.ScriptMediatorFactory.createSpecificMediator(ScriptMediatorFactory.java:105)
at org.apache.synapse.config.xml.AbstractMediatorFactory.createMediator(AbstractMediatorFactory.java:91)
at org.apache.synapse.config.xml.MediatorFactoryFinder.getMediator(MediatorFactoryFinder.java:223)
at org.apache.synapse.config.xml.AbstractListMediatorFactory.addChildren(AbstractListMediatorFactory.java:41)
at org.apache.synapse.config.xml.SequenceMediatorFactory.createSpecificMediator(SequenceMediatorFactory.java:87)
at org.apache.synapse.config.xml.AbstractMediatorFactory.createMediator(AbstractMediatorFactory.java:91)
at org.wso2.carbon.mediation.configadmin.ConfigurationValidator.validateSequence(ConfigurationValidator.java:90)
at org.wso2.carbon.mediation.configadmin.ConfigurationValidator.validate(ConfigurationValidator.java:73)
at org.wso2.carbon.mediation.configadmin.ConfigAdmin.validateConfiguration(ConfigAdmin.java:180)
... 61 more
Caused by: java.lang.ClassNotFoundException: com.sun.phobos.script.javascript.RhinoScriptEngineFactory
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
atorg.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoa ..
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 73 more"
I look up the solution about the same issue you given to other person https://wso2.org/jira/browse/ESBJAVA-1685 but it doesn't take effect.And I search Google for the question for a long time ,someone said the error has been fixxed or it is something wrong with OSGI Frame when it sets up,but others has the same problem with me still stick in it , so please give us a complete solution about how to use script mediator in WSO2 AM 1.5,tks a lot !
There is an issue with the bsf jar which we use to provide scripting engine..As an alternative way, you can use enrich/payload factory mediator to achieve above task

WSO2 CEP agent broker (KPI Analyzer) sample is not working with aggragate queries

I am working on Apache WSO2 CEP and I am trying to do some scenarios that fits my requirements.
First I execute the sample that is explained in this link KPI Analyzer and I succced and see the result correctly. After that, I wanted to change the bucket in that sample a little bit from this
from phoneRetailStream[totalPrice>2500 and quantity>3]
insert into highPurchaseStream
buyer, brand, quantity, totalPrice;
to this
from phoneRetailStream#window.length(5)
insert into highPurchaseStream
sum(quantity) as quantitySum, sum(totalPrice) as totalpriceSum
group by brand;
and changed the tuple mappings accordingly. But this configuration always gives me the error
[java] Wrongly formatted event sent for carbon.super
[java] org.wso2.carbon.databridge.core.exception.EventConversionException: Error when converting org.wso2.high.purchase.buyers.new:1.6.0 of event bundle with events 4
[java] at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.createEventList(ThriftEventConverter.java:126)
[java] at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.toEventList(ThriftEventConverter.java:88)
[java] at org.wso2.carbon.databridge.core.internal.queue.QueueWorker.run(QueueWorker.java:72)
[java] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
[java] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
[java] at java.util.concurrent.FutureTask.run(FutureTask.java:138)
[java] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
[java] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[java] at java.lang.Thread.run(Thread.java:662)
[java] Caused by: java.lang.NullPointerException
[java] at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.toObjectArray(ThriftEventConverter.java:49)
[java] at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.createEventList(ThriftEventConverter.java:116)
[java] ... 8 more
I could not use aggration functions (sum, avg etc.) of siddhi language in these samples other than jmsbroker. What may be wrong with this scenario?
#Mohanadarshan
This is the last version of my bucket xml file
<bucket name="KPIAnalyzer" xmlns="http://wso2.org/carbon/cep">
<description>
Notifies when a user purchases more then 3 phones for the total price higher than $2500.
</description>
<engineProviderConfiguration engineProvider="SiddhiCEPRuntime">
<property name="siddhi.persistence.snapshot.time.interval.minutes">0</property>
<property name="siddhi.enable.distributed.processing">false</property>
</engineProviderConfiguration>
<input topic="org.wso2.phone.retail.store/1.2.0" brokerName="localAgentBroker">
<tupleMapping stream="phoneRetailStream" queryEventType="Tuple">
<property name="brand" inputName="brand" inputDataType="payloadData"
type="java.lang.String"/>
<property name="quantity" inputName="quantity" inputDataType="payloadData"
type="java.lang.Integer"/>
<property name="totalPrice" inputName="total" inputDataType="payloadData"
type="java.lang.Integer"/>
<property name="buyer" inputName="buyer" inputDataType="payloadData"
type="java.lang.String"/>
</tupleMapping>
</input>
<query name="KPIQuery">
<expression>
from phoneRetailStream#window.length(5)
insert into highPurchaseStream
sum(quantity) as quantitySum, sum(totalPrice) as totalpriceSum
group by brand;
</expression>
<output topic="org.wso2.high.purchase.buyers.new/1.6.0" brokerName="externalAgentBroker">
<tupleMapping>
<metaData>
</metaData>
<correlationData/>
<payloadData>
<property name="quantity" valueOf="quantitySum" type="java.lang.Integer"/>
<property name="purchasePrice" valueOf="totalpriceSum" type="java.lang.Integer"/>
</payloadData>
</tupleMapping>
</output>
</query>
</bucket>
thank you for your help.
I have checked your siddhi query, it is working properly with siddhi engine and there is no any issue with the query...
I have checked with the KPI analyser example, it is also working without any issue for your query... Please make sure whether you have proper configurations for output tuple mappings..
Again I need to mention, there are some issue with the "bucket editable UI". Please verify the bucket xml file which in the /repository/deployment/server/cepbuckets/ is correct... (some times when deleting a property, it will not delete properly)
Change
<property name="quantity" valueOf="quantitySum" type="java.lang.Long"/>
<property name="purchasePrice" valueOf="totalpriceSum" type="java.lang.Long"/>
Thanks,
Mohan

Glassfish Log4j JNDI: Cannot find appender

I am using Glassfish and I created a JNDI custom resource called log4j that has these properties:
Name: log4j.appender.LOG Value: org.apache.log4j.RollingFileAppender
Name: log4j.appender.LOG.layout Value: org.apache.log4j.PatternLayout
Name: log4j.rootLogger Value: WARN, LOG
Name: log4j.appender.LOG.layout.conversionPattern Value: %d{MMM dd, yyyy HH:mm:ss} %p %m%n
Name: log4j.appender.LOG.File Value: ${com.sun.aas.instanceRoot}/logs/RestWebServices.log
Name: log4j.appender.LOG.MaxFileSize Value: 10MB
Name: log4j.appender.LOG.MaxBackupIndex Value: 10
The JNDI resource type is java.util.Properties and my spring application context contains these lines to find them:
<jee:jndi-lookup id="log4jJndi" jndi-name="log4j" resource-ref="true" />
<jee:jndi-lookup id="configurationsJndi" jndi-name="configurations" resource-ref="true" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="propertiesArray">
<list>
<ref bean="configurationsJndi"/>
<ref bean="log4jJndi"/>
</list>
</property>
</bean>
It works fine for my configurations JNDI resource but log4j gives me this error when starting Glassfish:
SEVERE: log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
SEVERE: log4j:WARN Please initialize the log4j system properly.
SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
When debugging the root logger was not the one I set in the JNDI resource. I tried adding the spring Log4jConfigListener to resolve this but it did not work. The version of Glassfish I am using is 3.1.
Does anyone know why log4j is an issue?
Edit: Now I am try to use JNDI that has the file location to my log4j properties file and my Spring application context gets the value from JNDI. My problem is I keep getting this error all the time with log4j:
Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'log4jJndi': Invocation of init method failed;
nested exception is javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.IllegalAccessException: value cannot be null]|#]
Try the following see if that helps:
1- create a file call it log4j.properties and place it in /src/main/resources
2- Copy the following lines in that file:
# #Default log level
log4j.rootCategory=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %d [%t] %c: %m%n
################################################
# #You can set custom log levels per-package here
################################################
# #Apache Commons tend to make a lot of noise which can clutter the log.
log4j.logger.org.apache=WARN
# #Shuts up some innocuous messages if using the JBPM transport
log4j.logger.org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog=ERROR
# #Reduce startup noise
log4j.logger.org.springframework.beans.factory=WARN
# #Your custom classes if you have one
log4j.logger.com.mycompany=DEBUG