VFS file processing in WSO2 Esb - wso2-esb

I am executing a sample given for VFS file processing, but during execution getting the error as "Cannot find the object for smooks config key: smooks".
Could you please let me know what I have missed out?
Configurations made are as below.
Local entry for smooke is created with below configuration in smooke-key.xml
<localEntry key="smooke" src="file:/development/Dev/wso2esb-4.8.0/repository/resources/smooks-config.xml"><description/></localEntry>
==================================================================================
Smooke-config.xml is as below
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
<!--Configure the CSVParser to parse the message into a stream of SAX events. -->
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.csv.CSVParser</resource>
<param name="fields" type="string-list">name,value</param>
</resource-config>
Proxy service is as below
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="FileProcessor"
transports="vfs"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log level="full"/>
<smooks config-key="smooke">
<input type="text"/>
<output type="xml"/>
</smooks>
<clone>
<target sequence="fileWriteSequence"/>
<target sequence="databaseSequence"/>
</clone>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///development/Dev/fileProcessing/sourcefiles</parameter>
<parameter name="transport.vfs.FileURI">file:///development/Dev/fileProcessing/in</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///development/Dev/fileProcessing/error</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</proxy>

create the smooks configuration at
wso2esb-4.8.0/repository/samples/resources/smooks/Smooke-config.xml
and restart the esb

change the localentry file like this
<localEntry key="smooke" src="file:repository/resources/smooks-config.xml"><description/></localEntry>

Related

Unable to read/consume message from ActiveMQ Queue in WSO2

I am trying to read message from activeMQ Queue. It is dequeuing at ActiveMQ but I am unable to read it at backend. Can anyone guide how to read/print the data on my Local Machine ?
Following is the code:
<proxy name="Listen_Queue" startOnLoad="true" transports="jms" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="full">
<property name="MSG" value="Receiving messages from Queue" />
</log>
<property action="set" name="OUT_ONLY" value="true"/>
<drop />
</inSequence>
<faultSequence />
</target>
<parameter name="transport.jms.Destination">WajihsCheck</parameter>
<parameter name="redeliveryPolicy.redeliveryDelay">2000</parameter>
<parameter name="transport.jms.ContentType">json</parameter>
<parameter name="transport.jms.ConnectionFactory">myQueueListener</parameter>
<parameter name="transport.jms.CacheLevel">consumer</parameter>
When I run the server of Wso2 MI I get this error too:
Unknown error processing message org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException:
Unexpected character '{' (code 123) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]
[![This is my backend where I believe message should come][1]][1]
[1]: https://i.stack.imgur.com/teDO4.png
Amyleads would mean a lot.
Change the content type parameter to below.
<parameter name="transport.jms.ContentType">application/json</parameter>

Parameters empty (or not supplied to CommandText) when using NLog with ASP.NET Core and SQLite

I've set up NLog in an ASP.NET Core MVC application using the examples in the documentation. Logging to a file (target=file) works without any problems.
However, logging to the Sqlite database results in an exception:
2018-10-30 20:04:41.4394 Error DatabaseTarget(Name=db): Error when
writing to database. Exception: System.InvalidOperationException: Must
add values for the following parameters: #MachineName, #Logged,
#Level, #Message, #Logger, #Callsite, #Exception at
Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior
behavior) at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at NLog.Targets.DatabaseTarget.WriteEventToDatabase(LogEventInfo
logEvent) at NLog.Targets.DatabaseTarget.Write(LogEventInfo
logEvent)
Any ideas why the values of these parameters are empty? Or maybe the parameters are not passed at all?
NLog configuration file:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="file" fileName="nlog-${shortdate}.log"
layout="${longdate}|${machinename}|${level:upperCase=true}|${logger}|${callsite}|${message} ${exception:tostring}" />
<target xsi:type="Database"
name="db"
dbProvider="Microsoft.Data.Sqlite.SqliteConnection, Microsoft.Data.Sqlite"
connectionString="Data Source=database.db;">
<commandText>
INSERT INTO Log (MachineName, Logged, Level, Message, Logger, CallSite, Exception)
VALUES (#MachineName, #Logged, #Level, #Message, #Logger, #Callsite, #Exception);
</commandText>
<parameter name="#MachineName" layout="${machinename}" />
<parameter name="#Logged" layout="${longdate}" />
<parameter name="#Level" layout="${level:upperCase=true}" />
<parameter name="#Message" layout="${message}" />
<parameter name="#Logger" layout="${logger}" />
<parameter name="#CallSite" layout="${callsite}" />
<parameter name="#Exception" layout="${exception:tostring}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
<logger name="*" minlevel="Info" writeTo="db" />
</rules>
</nlog>
Unable to fix the issue using Microsoft.Data.Sqlite I switched to using System.Data.SQLite (NuGet) instead, which fixed the issue right away.
Remove the Microsoft.Data.Sqlite reference and add a reference System.Data.SQLite (1.0.109.2 at the time of writing) in your .csproj file. Update the dbProvider attribute value in nlog.config to System.Data.SQLite.SQLiteConnection, System.Data.SQLite and you're set.
nlog.config snippet:
<target xsi:type="Database"
name="db"
dbProvider="System.Data.SQLite.SQLiteConnection, System.Data.SQLite"
connectionString="Data Source=database.db;">
...
</target>

How to get Digest vlue generated from Cache Mediator?

I am working on Cache Mediator in wso2esb. My requirement is to get Hash Digest value generated by org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator class in this mediator.
<sequence name="In_Seq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<cache collector="false"
hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator"
id="MyCache" maxMessageSize="2000" scope="per-host" timeout="120">
<onCacheHit/>
<implementation maxSize="1000" type="memory"/>
</cache></sequence>
<sequence name="Out_Seq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<cache collector="true" id="MyCache" scope="per-host"/>
</sequence>
Can you tell me how to do that?

Unable to find the requested .Net Framework Data Provider. It may not be installed

I am using Nlog for Error loggin. I have configured the Nlog using the following code in web.config but the programs throws error "Unable to find the requested .Net Framework Data Provider. It may not be installed."
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" internalLogFile="c:\nlog.txt" internalLogLevel="Debug">
<extensions>
<add assembly="NLog.Extended" />
</extensions>
<targets>
<target name="Console" xsi:type="Console" layout="${level:uppercase=true} ${message}"/>
<target name="DelivrosLogFile" xsi:type="File" fileName="C:\DelivrosLogs\Delivros.log" layout="${longdate} |${message}| ${stacktrace}"/>
<target xsi:type="Database" name="DelivrosDatabaseLogging" connectionStringName="DelivrosEntities"
commandText="INSERT INTO tbl_ErrorLogIn( Event_ID,Priority,Severity,Title,Timestamp,MachineName,AppDomainName,PocessID,ProcessName,ThreadName,Win32ThreadId,Message,FormattedMessage) VALUES (#Event_ID,#Priority,#Severity,#Title,#Timestamp,#MachineName,#AppDomainName,#PocessID,#ProcessName,#ThreadName,#Win32ThreadId,#Message,#FormattedMessage)">
<parameter name="#Event_ID" layout="0"/>
<parameter name="#Priority" layout="3"/>
<parameter name="#Severity" layout="${level}"/>
<parameter name="#Title" layout="Journal API"/>
<parameter name="#Timestamp" layout="${date}"/>
<parameter name="#MachineName" layout="${machinename}"/>
<parameter name="#AppDomainName" layout="Journal API"/>
<parameter name="#PocessID" layout="${processid}"/>
<parameter name="#ProcessName" layout="${processname}"/>
<parameter name="#ThreadName" layout="${threadname}"/>
<parameter name="#Win32ThreadId" layout="${threadid}"/>
<parameter name="#Message" layout="${exception}"/>
<parameter name="#FormattedMessage" layout="${message} "/>
</target>
</targets>
<rules>
<logger name="*" levels="Info,Warn,Error,Fatal" writeTo="Console"/>
<logger name="*" levels="Info,Warn,Fatal" writeTo="DelivrosLogFile"/>
<logger name="*" levels="Error" writeTo="DelivrosDatabaseLogging"/>
</rules>
I stuck with this for Four days...is there any one out there who can help me....
It was given providerName="System.Data.EntityClient" in connection string and i changed that to providerName="System.Data.SqlClient"
I can just add that if you already used EntityFramework you cannot simply change the provider in your connection string, as your Entity will not work. You can add another connection string for your error logging with providerName="System.Data.SqlClient".

WSO2 ESB Store and Forward Processor not obeying endpoint message format

We have been testing the message processors and queues on wso2 esb. We have been using the sampling processor quite successfully to just log data to a DB. This POX end to end. The sampling processor correctly dequeues a message and sends it to the endpoint. The endpoint is defined as POX and non-chunked, and all this works well.
We decided to try the store and forward processor as we wanted to test out the guaranteed delivery mechanism. So we created a new processor and defined it as store and forward. In the main sequence that stores the message, we added the target.endpoint property before storing the message. The property was set to the same endpoint that was being used in the sampling scenario.
However - what have found is that in this mode, the message transformation does not happen correctly. The content type is set to text/html and the output is chunked. This causes our service to return a 415 error.
We have tried adding messageType, contentType etc to multiple place, to the axis http sender transport, etc, but it seems to make no difference at all.
Any guidance on this would be appreciated
Define the following property in the sequence before sending to the endpoint
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
The JS code below simply inserts the messageID into the return payload to the caller. Using this with a sampling processor and sequence that simply sends to the same endpoint works fine.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
<parameter name="cachableDuration">15000</parameter>
</registry>
<endpoint name="test_e">
<address uri="http://192.168.45.168:8080/cgi-bin/esbcgi.pl" format="pox"/>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
</endpoint>
<sequence name="fault" trace="enable">
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
</log>
<drop/>
</sequence>
<sequence name="main" onError="fault" trace="enable">
<in>
<log level="full"/>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>
<script language="js">
var message = mc.getMessageID();
var messageId = message.substring(9,45);
var payload = mc.getPayloadXML().*;
mc.setPayloadXML(
<payload> <messageId>{messageId}</messageId>{payload}
</payload>);
</script>
<switch xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://org.apache.synapse/xsd" source="get-property('To')">
<case regex=".*/TEST/.*">
<property name="target.endpoint" value="test_e" scope="default"/>
<store messageStore="TEST"/>
</case>
<default/>
</switch>
<property name="OUT_ONLY" value="false"/>
<script language="js">var serviceMessageId = mc.getMessageID();
mc.setPayloadXML(
<tag xmlns="http://tagcmd.com">
<messageId>{serviceMessageId}</messageId> </tag>);
</script>
<send>
<endpoint key="MessageService"/>
</send>
</in>
<out>
<script language="js">
var messagePayload= mc.getPayloadXML().*.*;
mc.setPayloadXML(
<eventResponse> <messageId>{messagePayload}</messageId> </eventResponse>);
</script>
<send/>
</out>
<description>The main sequence for the message mediation</description>
</sequence>
<messageStore class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" name="TEST">
<parameter name="java.naming.factory.initial">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
<parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter>
<parameter name="store.jms.destination">APP8</parameter>
</messageStore>
<messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor" name="test_p2" messageStore="TEST">
<parameter name="max.deliver.attempts">1</parameter>
</messageProcessor>
</definitions>