After upgrading from v5.0.20.6 to v5.0.21.6 method names are replaced with token in XML document - codeeffects

Version 5.0.21.6 introduced a breaking change to the rule XML content.
In version 5.0.20.6 methods are referenced by their names in the XML file as shown below:
<method name="AddReason"><value type="System.Int32">1</value></method>
But in version 5.0.21.6 methods are referenced by a "token" as shown below:
<method name="1064B76D73CE9F304CA588DF55C65438"><value type="System.Int32">1</value></method>
We do use the XML document to further validate rules provided by the user and v5.0.21.6 breaks our functionality due to this issue.
Complete v5.0.21.6 Rule XML:
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="https://codeeffects.com/schemas/rule/41"
xmlns:ui="https://codeeffects.com/schemas/ui/4">
<rule id="c11fc9b9-f60b-4b50-ac65-f46fb5c21471" webrule="5.0.21.2" utc="2020-08-11T18:42:06.3444" type="RuleModel.PermissibilityRuleModel, Rules.CodeEffects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" eval="false">
<name>__rule_name__</name>
<definition>
<if>
<clause>
<or>
<and ui:block="true">
<condition type="equal">
<property name="PortfolioType" />
<value type="numeric">1</value>
</condition>
<condition type="equal">
<property name="IndependenceRestrictionStandard" />
<value type="numeric">1</value>
</condition>
</and>
<condition type="equal">
<property name="IndependenceRestrictionStandard" />
<value type="numeric">1</value>
</condition>
</or>
</clause>
<then>
<set>
<property name="PermissibilityStatus" />
<value type="numeric">1</value>
</set>
<method name="1064B76D73CE9F304CA588DF55C65438">
<value type="System.Int32">1</value>
</method>
</then>
<else>
<if>
<clause>
<condition type="equal">
<property name="IndependenceRestrictionStandard" />
<value type="numeric">1</value>
</condition>
</clause>
<then>
<method name="23434FBDF0B4243BC14729C5D1539E7D">
<value type="System.Int32">1</value>
</method>
</then>
<else>
<set>
<property name="PermissibilityStatus" />
<value type="numeric">1</value>
</set>
<method name="1064B76D73CE9F304CA588DF55C65438">
<value type="System.Int32">1</value>
</method>
</else>
</if>
</else>
</if>
</definition>
<format>
<lines>
<line index="0" tabs="1" />
<line index="3" tabs="2" />
<line index="9" tabs="2" />
<line index="16" tabs="1" />
<line index="19" tabs="1" />
<line index="25" tabs="1" />
<line index="28" tabs="2" />
<line index="35" tabs="2" />
<line index="42" tabs="0" />
<line index="44" tabs="1" />
<line index="49" tabs="1" />
<line index="52" tabs="2" />
<line index="58" tabs="0" />
<line index="60" tabs="1" />
<line index="66" tabs="1" />
</lines>
</format>
</rule>
</codeeffects>

Related

Creating json but sending XML out instead in WSO2 ESB

In WSO2 ESB 4.8.1, implemented an API, which receives json message, and will send new json payload to the backend. I debug the API and I saw that it is convert my json payload to xml and then send it to the backend.
FYI: I have un-commented the json stream formatter and builder in axis2 config files.
the api source is:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="SdpProductStatus" context="/SdpServices/1/Aggregator/Product/Status">
<resource methods="POST">
<inSequence>
<property name="messageType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<property name="ContentType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<property name="productId" expression="json-eval($.productId)" scope="default" type="STRING" />
<property name="customerId" expression="json-eval($.customerId)" scope="default" type="STRING" />
<property name="description" expression="json-eval($.description)" scope="default" type="STRING" />
<property name="time" expression="json-eval($.time)" scope="default" type="STRING" />
<property name="state" expression="json-eval($.state)" scope="default" type="STRING" />
<log />
<property name="time" expression="concat(substring($ctx:time,1,4),'-',substring($ctx:time,5,2),'-',substring($ctx:time,7,2),' ',substring($ctx:time,10,2),':',substring($ctx:time,12,2),':',substring($ctx:time,14,2))" scope="default" type="STRING" />
<script language="js">mc.setProperty("state", mc.getProperty("state").replace("0","deactive")); mc.setProperty("state", mc.getProperty("state").replace("1","active"));</script>
<property name="POST_TO_URI" value="true" scope="axis2" />
<property name="REST_URL_POSTFIX" value="ActiveOrDeactive" scope="axis2" type="STRING" />
<property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2" type="STRING" />
<property name="messageType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<property name="ContentType" value="application/json; charset=utf-8;" scope="axis2" type="STRING" />
<header name="Accept" scope="transport" value="application/json" />
<header name="Content-Type" scope="transport" value="application/json" />
<header name="ContentType" scope="transport" value="application/json" />
<payloadFactory media-type="json">
<format>{"productID":"$1","CustomerID":"$2", "Time":"$3","State":"$4","tempData":"$5","Description":"$6","Username":"$7","Password":"$8", "Instruction":"$9"}</format>
<args>
<arg evaluator="xml" expression="$ctx:productId" />
<arg evaluator="xml" expression="$ctx:customerId" />
<arg evaluator="xml" expression="$ctx:time" />
<arg evaluator="xml" expression="$ctx:state" />
<arg evaluator="xml" value="temp" />
<arg evaluator="xml" expression="$ctx:description" />
<arg value="test1" />
<arg value="test1" />
<arg value="create" />
</args>
</payloadFactory>
<log>
<property name="body" expression="json-eval($.)" />
</log>
<send buildmessage="true">
<endpoint>
<address uri="http://10.8.10.10:8080/service1.svc/" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log />
<property name="message" expression="json-eval($.MESSAGE)" scope="default" type="STRING" />
<filter source="json-eval($.STATUS)" regex="-?\d.*">
<then>
<property name="statusCode" value="200" scope="default" type="STRING" />
</then>
<else>
<property name="statusCode" expression="json-eval($.STATUS)" scope="default" type="STRING" />
</else>
</filter>
<property name="messageType" value="application/json" scope="axis2" type="STRING" />
<header name="Accept" scope="transport" value="application/json" />
<payloadFactory media-type="json">
<format>{"productId":$1,"id":"$2","customerId":"$3","status":{"statusCode":$4,"message":"$5"}}</format>
<args>
<arg evaluator="xml" expression="$ctx:productId" />
<arg evaluator="xml" value="55" />
<arg evaluator="xml" expression="$ctx:customerId" />
<arg evaluator="xml" expression="$ctx:statusCode" />
<arg evaluator="xml" expression="$ctx:message" />
</args>
</payloadFactory>
<header name="Content-Type" scope="transport" value="application/json" />
<send />
</outSequence>
</resource>
</api>
And this is what I get in the backend:
<jsonobject>....my payload converted to xml...</jsonobject>
Can you <header name="Content-Type" scope="transport" value="application/json" /> before building payloadFactory?
<property name="messageType" value="application/json" scope="axis2" type="STRING" />
<header name="Accept" scope="transport" value="application/json" />
<header name="Content-Type" scope="transport" value="application/json" />
OR
Try like following, here I skip the "evaluator="xml"".
<args>
<arg expression="$ctx:productId"/>
<arg value="55"/>
<arg expression="$ctx:customerId"/>
</args>

Mule loses payload after data mapper call

I am using Mule 3.6.1 and have a flow that reads a CSV file and then splits the file and passes in each record to the datamapper. I can see that the record is present prior to data mapper but once the message leaves the datamapper, the payload is empty.
How can I fix this? Please note that the Choice will have 3 possible datamappers to select in the completed flow.
The flow is:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">
<context:property-placeholder location="mule-app.properties" />
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="true">
<import class="org.mule.util.StringUtils" />
<import class="org.mule.util.ArrayUtils" />
</expression-language>
</configuration>
<data-mapper:config name="test_mapper" transformationGraphPath="csv_to_json_1.grf" doc:name="test_mapper"/>
<flow name="read-file" >
<file:inbound-endpoint path="${file.unprocessed.location}" moveToPattern="#[message.inboundProperties['originalFilename']]" moveToDirectory="${file.processed.location}" responseTimeout="10000" doc:name="Files" mimeType="text/csv" >
<file:filename-regex-filter pattern="test.csv" caseSensitive="true"/>
</file:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<splitter expression="#[rows=StringUtils.split(message.payload,'\n\r'); ArrayUtils.subarray(rows,1,rows.size())]" doc:name="Splitter"/>
<set-property propertyName="testFilename" value="#[flowVars.originalFilename]" doc:name="Set Filename"/>
<choice doc:name="Choice">
<when expression="#[message.outboundProperties.'testFilename'=='test.csv']">
<data-mapper:transform config-ref="CSV_To_JSON" doc:name="CSV To JSON"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<object-to-string-transformer doc:name="Object to String"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
and CSV input file:
DeptID,Dept,Staff
5LL/A,Human Resources,4.00
and GRF file showing data mappings:
<?xml version="1.0" encoding="UTF-8"?><Graph __version="3.5.0" author="" created="Wed May 25 14:20:34 BST 2016" description="CSV To JSON" guiVersion="3.4.4.P" id="1464184235950" licenseCode="Unlicensed" licenseType="Unknown" modified="Wed May 25 14:20:34 BST 2016" modifiedBy="" name="CSV_To_JSON" preview-file="C:/test.csv" revision="1.0" showComponentDetails="false">
<Global>
<Metadata __referenceCounter="1" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _type="Input" id="f79c6373-b266-4a78-91c9-3a731304eef1">
<Record fieldDelimiter="," name="test" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field containerType="SINGLE" label="DeptID" name="DeptID" size="10" type="string"/>
<Field containerType="SINGLE" label="Dept" name="Dept" size="10" type="string"/>
<Field containerType="SINGLE" eofAsDelimiter="true" label="Staff" name="Staff" size="10" type="string"/>
<Field __artificialType="_id" auto_filling="global_row_count" name="__id" type="long"/>
</Record>
</Metadata>
<Metadata __index="0" __referenceCounter="1" __sourcePath="{}/test" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _id="__id" _type="Output" id="4b092da3-e786-4f90-8e22-d9d5e8d7a7b1">
<Record fieldDelimiter="," name="test" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
<Field __index="1" __sourcePath="{}/test/Dept" containerType="SINGLE" label="Dept" name="Dept" type="string"/>
<Field __index="0" __sourcePath="{}/test/DeptID" containerType="SINGLE" label="DeptID" name="DeptID" type="string"/>
<Field __index="2" __sourcePath="{}/test/Staff" containerType="SINGLE" label="Staff" name="Staff" type="string"/>
</Record>
</Metadata>
<Dictionary>
<Entry id="DictionaryEntry0" input="true" name="inputPayload" output="false" type="object"/>
<Entry id="DictionaryEntry1" input="false" name="outputPayload" output="true" type="object"/>
</Dictionary>
</Global>
<Phase number="0">
<Node charset="UTF-8" enabled="enabled" fileURL="dict:inputPayload" guiName="CSV READER" guiX="20" guiY="20" id="DATA_READER0" quoteCharacter="both" quotedStrings="true" skipRows="1" trim="true" type="DATA_READER">
<attr name="_data_format"><![CDATA[CSV]]></attr>
<attr name="__dataSourceDefinition"><![CDATA[C:/test.csv]]></attr>
</Node>
<Node enabled="enabled" guiName="Foreach 'test' -> 'test'" guiX="460" guiY="20" id="FOREACH_TEST_TEST" transformClass="com.mulesoft.datamapper.transform.MelRecordTransform" type="REFORMAT">
<attr name="melScript"><![CDATA[//MEL
//START -> DO NOT REMOVE
output.__id = num2str(input.__id);
//END -> DO NOT REMOVE
output.DeptID = input.DeptID;
output.Dept = input.Dept;
output.Staff = input.Staff;
]]></attr>
</Node>
<Node cacheInMemory="true" charset="UTF-8" enabled="enabled" fileURL="dict:outputPayload" guiName="JSON WRITER" guiX="900" guiY="20" id="JSON_WRITER0" type="JSON_WRITER">
<attr name="mapping"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<clover:collection clover:name="test" xmlns:clover="http://www.cloveretl.com/ns/xmlmapping">
<item clover:inPort="0">
<DeptID>$0.DeptID</DeptID>
<Dept>$0.Dept</Dept>
<Staff>$0.Staff</Staff>
</item>
</clover:collection>]]></attr>
<attr name="_data_format"><![CDATA[JSON]]></attr>
</Node>
<Edge debugMode="true" fromNode="DATA_READER0:0" guiBendpoints="" id="Edge0" inPort="Port 0 (in)" metadata="f79c6373-b266-4a78-91c9-3a731304eef1" outPort="Port 0 (output)" toNode="FOREACH_TEST_TEST:0"/>
<Edge debugMode="true" fromNode="FOREACH_TEST_TEST:0" guiBendpoints="" id="Edge1" inPort="Port 0 (in)" metadata="4b092da3-e786-4f90-8e22-d9d5e8d7a7b1" outPort="Port 0 (out)" toNode="JSON_WRITER0:0"/>
</Phase>
</Graph>
In the splitter your are already stripping of the header.
In DataMapper you have the option 'Rows to Ignore' set to "1".
Set that to "0", or change the expression in your splitter.
Because now you tell DataMapper to ignore your one and only row!
You are ignoring the row coming into the datamapper and hence there is no mapping being done remove "rows to ignore".Then the mapper will work on the row coming inside

aggregating responses using wso2 esb api: no answer

In WSO2 ESB, I have created an rest API. This API needs to connect to two different services, and combine the results.
For this, I use an API, with in de insequence a clone mediator that sends out the appropriate messages. This works fine.
In the outsequence, I use a logger to see the incoming messages. Both are json and come back ok. I then want to use an aggregate mediator to combine the two. With this, I have two issues:
when using a rootElementProperty to place the two items under one parent, a NPE happens,
when using enrich mediators or whatever else to make a correct message, and ending with send, the resulting message is never sent back.
What can be the cause of this?
This is the actual API:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="Cale-StreetsAPI" context="/Cale-StreetsAPI">
<resource methods="GET" uri-template="/getStreets?lat={lat}&lon={lon}&radius={radius}">
<inSequence>
<property name="aggRoot" scope="default">
<red:jsonObject xmlns:red="redora"/>
</property>
<log description="">
<property name="lat" expression="get-property('uri.var.lat')"/>
<property name="lon" expression="get-property('uri.var.lon')"/>
<property name="radius" expression="get-property('uri.var.radius')"/>
</log>
<clone continueParent="true" id="deCartaStreets">
<target>
<sequence>
<sequence key="DeCartaDDS"/>
</sequence>
</target>
<target>
<sequence>
<sequence key="DeCartaReverseGeo"/>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<property name="messageType" value="application/xml" scope="axis2" type="STRING" description="messageType"/>
<log level="full" description="">
<property name="WSANSWER" value="true"/>
</log>
<aggregate>
<completeCondition>
<messageCount min="2" max="-1"/>
</completeCondition>
<onComplete expression="$body/jsonObject">
<enrich>
<source clone="true" xpath="$body//jsonObject"/>
<target type="property" property="ResultItems"/>
</enrich>
<log level="custom">
<property name="ResultItems" expression="get-property('ResultItems')"/>
</log>
<enrich>
<source type="inline" clone="true">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<JsonResponse xmlns="dummy"/>
</soapenv:Body>
</soapenv:Envelope>
</source>
<target type="envelope"/>
</enrich>
<enrich>
<source type="property" clone="true" property="ResultItems"/>
<target xmlns:red="dummy" action="child" xpath="//red:JsonResponse"/>
</enrich>
<log level="full" description="">
<property name="AGGREGATE_END" value="true"/>
</log>
<property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/>
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence>
<log level="full" category="WARN"/>
</faultSequence>
</resource>
</api>
I faced the same problem you did. According to number of posts over Internet APIs doesn't support aggregation.
So my solution was to introduce aggregating Proxy service which did all the job where API just made a call to that proxy service.
So if you modify your solution as follows you should be able to achieve what you expect:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AggregatingProxy" transports="local https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full"/>
<property name="enclosing_element">
<result xmlns=""/>
</property>
<clone continueParent="true">
<property name="aggRoot" scope="default">
<red:jsonObject xmlns:red="redora"/>
</property>
<log description="">
<property name="lat" expression="get-property('uri.var.lat')"/>
<property name="lon" expression="get-property('uri.var.lon')"/>
<property name="radius" expression="get-property('uri.var.radius')"/>
</log>
<clone continueParent="true" id="deCartaStreets">
<target>
<sequence>
<sequence key="DeCartaDDS"/>
</sequence>
</target>
<target>
<sequence>
<sequence key="DeCartaReverseGeo"/>
</sequence>
</target>
</clone>
</clone>
</inSequence>
<outSequence>
<property name="messageType" value="application/xml" scope="axis2" type="STRING" description="messageType"/>
<log level="full" description="">
<property name="WSANSWER" value="true"/>
</log>
<aggregate>
<completeCondition>
<messageCount min="2" max="-1"/>
</completeCondition>
<onComplete expression="$body/jsonObject">
<enrich>
<source clone="true" xpath="$body//jsonObject"/>
<target type="property" property="ResultItems"/>
</enrich>
<log level="custom">
<property name="ResultItems" expression="get-property('ResultItems')"/>
</log>
<enrich>
<source type="inline" clone="true">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<JsonResponse xmlns="dummy"/>
</soapenv:Body>
</soapenv:Envelope>
</source>
<target type="envelope"/>
</enrich>
<enrich>
<source type="property" clone="true" property="ResultItems"/>
<target xmlns:red="dummy" action="child" xpath="//red:JsonResponse"/>
</enrich>
<log level="full" description="">
<property name="AGGREGATE_END" value="true"/>
</log>
<property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/>
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence>
<log level="full" category="WARN"/>
</faultSequence>
</target>
</proxy>
API Configuration:
<api xmlns="http://ws.apache.org/ns/synapse" name="Cale-StreetsAPI" context="/Cale-StreetsAPI">
<resource methods="GET" uri-template="/getStreets?lat={lat}&lon={lon}&radius={radius}">
<inSequence>
<call>
<endpoint>
<address uri="http://localhost:8280/services/AggregatingProxy" format="soap12"></address>
</endpoint>
</call>
<respond/>
</inSequence>
</resource>
</api>
This actually worked out for me and hopefully will help you too.
Also consider using:
<property name="enclosing_element">
<result xmlns=""/>
</property>
...
<onComplete expression="$body/jsonObject" enclosingElementProperty="enclosing_element">
In case your service return different type of results.
Thanks,
Vladimir.

In Cobertura Report all the percentages are 0 and message is coming have you mentioned the correct path

Here is my build.xml. Here all the paths are mentioned.
In report all the percentages are 0(ZERO).
And It is also prompting me that "Have you mentioned the specified source directory"
Please suggest where is the mistake.
Either I have to change the build.xml or have to perform some steps.
First I ran all the junit test cases, then stoped the server and then run the build.xml as ant-build.
<project name="RFM2" default="cobertura_REPORT">
<property name="BASEDIR" value="D:/SIT/busnessservice" />
<property name="cobertura.dir" value="D:/SIT/JUNIT_jars/cobertura-1.9.1" />
<property name="src.dir" value="${BASEDIR}/src" />
<property name="build.dir" value="${BASEDIR}/build" />
<property name="dist.dir" value="${BASEDIR}/dist" />
<property name="lib.dir" value="D:/SIT/JUNIT_jars/jars" />
<property name="report.dir" value="${BASEDIR}/reports" />
<property name="cobertura.ser.file" value="${cobertura.dir}/cobertura.ser" />
<property name="server.ser.file" value="D:/Program Files/cobertura.ser" />
<property name="instrumentedDir" value="${cobertura.dir}/instrument" />
<property name="junit.data.dir" value="${report.dir}/junit/data" />
<property name="junit.report.dir" value="${report.dir}/junit/html" />
<property name="junit.dir" value="D:/SIT/JUNIT_jars/jars" />
<property name="test.dir" value="D:/SIT/JUNITTESTFILES" />
<!--class path for cobertula -->
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura-1.9.4.1.jar" />
<include name="*.jar" />
</fileset>
</path>
<!--class path for JUNIT -->
<path id="junit.classpath">
<fileset dir="${junit.dir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${junit.dir}/junit-4.1.jar" />
<pathelement location="${BASEDIR}/bin" />
<path refid="cobertura.classpath" />
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<!-- PATH FOR LIB -->
<path id="lib.classpath">
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<path id="runtime.classpath">
<pathelement location="${build.dir}" />
<path refid="lib.classpath" />
</path>
<!--Initialization -->
<target name="init">
<mkdir dir="${dist.dir}" />
</target>
<!-- Clean files-->
<target name="clean" description="Remove all generated files.">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Compile the java file -->
<!--Instrument the files -->
<target name="cobertura_instrument">
<cobertura-instrument todir="${instrumentedDir}" datafile="${server.ser.file}">
<fileset dir="${lib.dir}">
<include name="businessServices.jar" />
</fileset>
</cobertura-instrument>
<!-- Copy cobertula.ser file in server-->
</target>
<!--copy the instrumented file in class file-->
I have removed this block as I think it is not getting used .
But still my report is getting generated with zero percentage.
<!--Make EAR-->
<target name="making ear">
<echo>come in making ear</echo>
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war" />
</ear>
</target>
<!--Run the JUNIT Test Case-->
<target name="runJunitTest">
<junit fork="yes" dir="${test.dir}" failureProperty="test.failed">
<!--
Specify the name of the coverage data file to use.
The value specified below is the default.
-->
<sysproperty key="net.sourceforge.cobertura.datafile" file="${server.ser.file}" />
<classpath location="${instrumentedDir}" />
<classpath refid="junit.classpath" />
<classpath refid="cobertura.dir" />
<formatter type="plain" usefile="false" />
<formatter type="xml"/>
<test name="${test.dir}/ColorConfigurationTest" />
<batchtest todir="${report.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</target>
<!--rEPORTING-->
<target name="cobertura_REPORT">
<delete dir="${report.dir}" />
<mkdir dir="${report.dir}" />
<cobertura-report srcdir="${src.dir}" format="html" destdir="${report.dir}" datafile="${server.ser.file}">
</cobertura-report>
</target>
</project>
<!--Make EAR-->
<target name="making ear">
<echo>come in making ear</echo>
<ear destfile="${build.dir}/myapp.ear" appxml="${src.dir}/metadata/application.xml">
<fileset dir="${build.dir}" includes="*.jar,*.war" />
</ear>
</target>
<!--Run the JUNIT Test Case-->
<target name="runJunitTest">
<junit fork="yes" dir="${test.dir}" failureProperty="test.failed">
<!--
Specify the name of the coverage data file to use.
The value specified below is the default.
-->
<sysproperty key="net.sourceforge.cobertura.datafile" file="${server.ser.file}" />
<classpath location="${instrumentedDir}" />
<classpath refid="junit.classpath" />
<classpath refid="cobertura.dir" />
<formatter type="plain" usefile="false" />
<formatter type="xml"/>
<test name="${test.dir}/ColorConfigurationTest" />
<batchtest todir="${report.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</target>
I noticed one thing that should be easy to correct - that doesn't match the Cobertura doc or my working copy. Hopefully this will fix your problem.
Your JUnit task references <classpath refid="cobertura.dir" /> but the cobertura.dir is not a path id, it is the name of a property pointing to your cobertura directory. (IntelliJ IDEA flagged it in red, which caught my eye!)
In my script, I have:
Then my JUnit task references the cobertura.classpath like so:
<classpath refid="cobertura.classpath" />
Hope this helps!

Filtering in WSO2

I want to build one proxy that:
1. Call Service that do Authorize and give result OK or Fail (1st Service)
2. If Result ‘OK’ then call a Service
The Problem is, when The 1st Service give back the Message :
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<result>
<status>OK</status>
<message></message>
</result>
</soapenv:Body>
</soapenv:Envelope>
And I give “filtering” at Out Sequence. Here is the XML :
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
<target endpoint="AuthorizationService">
<outSequence>
<log level="full" />
<filter xpath="/result/status='OK'">
<then>
<send>
<endpoint>
<address uri="http://192.168.1.140:8080/axis2/services/TaskService.TaskServiceHttpEndpoint/getTask" />
</endpoint>
</send>
</then>
<else>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch" />
<reason value="1" />
<role>2</role>
<detail>3</detail>
</makefault>
</else>
</filter>
<log level="full" />
</outSequence>
</target>
</proxy>
When I run my Application, the ESB always give the message :
16:08:59,358 [-] [HttpClientWorker-4] INFO Start : Log mediator
16:08:59,361 [-] [HttpClientWorker-4] INFO To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0bc33821-c4f1-448e-a7dc-be4194be8e99, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><result><status>OK</status><message></message></result></soapenv:Body></soapenv:Envelope>
16:08:59,361 [-] [HttpClientWorker-4] INFO End : Log mediator
16:08:59,361 [-] [HttpClientWorker-4] INFO Start : Filter mediator
16:08:59,361 [-] [HttpClientWorker-4] INFO XPath expression : /result/status='OK' evaluates to false - executing the else path child mediators
Seems like the condition of the filtering is always false.What is the correct statement for the XPath in the filter?
Your proxy configuration should be look as follows
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
<target endpoint="AuthorizationService">
<outSequence>
<log level="full"/>
<filter source="/result/status" regex="ok">
<then>
<send>
<endpoint>
<address uri="http://192.168.1.140:8080/axis2/services/TaskService.TaskServiceHttpEndpoint/getTask"/>
</endpoint>
</send>
</then>
<else>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason value="1"/>
<role>2</role>
<detail>3</detail>
</makefault>
<send/>
</else>
</filter>
</outSequence>
</target>
<description></description>
</proxy>
It seems that you may have given a wrong xpath expression. You can't give an xpath and a boolean expression both for the xpath value, i.e. it can't be "/result/status='OK'", but has to be "/result/status". Then, according to your sequence, it would fire the section after then, if this element is present. Since, you need to evaluate a boolean condition as well based on the xpath, I'll present an alternative based on the switch mediator (Same can be done for the filter by setting a property):
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
<target endpoint="AuthorizationService">
<outSequence>
<log level="full" />
<switch source="//result/status">
<case regex="OK">
<send>
<endpoint>
<address uri="http://192.168.1.140:8080/axis2/services/TaskService.TaskServiceHttpEndpoint/getTask" />
</endpoint>
</send>
</case>
<default>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch" />
<reason value="1" />
<role>2</role>
<detail>3</detail>
</makefault>
</default>
</switch>
<log level="full" />
</outSequence>
</target>
</proxy>