How we can count the objects in Iterator using wso2esb - wso2

I am getting array list from my front end that i need to insert into a table using Wso2esb and dss i have almost done that functionality using iterator.I need to give response to front end whenever insertion over of that array list. i wish to count the any obejects which is iterating number of times
my code is like this
<iterate continueParent="true"
id="QuestionListMobile"
expression="//QuestionsList">
<target>
<sequence>
<property name="ttemplateformid"
expression="get-property('ttemplateformid')"
scope="default"
type="STRING"/>
<payloadFactory>
<format>
<p:Insert_ttemplatedetails_Mobile_Op xmlns:p="http://ws.wso2.org/dataservice">
<xs:templateformid xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:templateformid>
<xs:formtemplatesectiondetailid xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:formtemplatesectiondetailid>
<xs:questionid xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:questionid>
<xs:weightage xmlns:xs="http://ws.wso2.org/dataservice">0</xs:weightage>
<xs:rank xmlns:xs="http://ws.wso2.org/dataservice">$4</xs:rank>
<xs:score xmlns:xs="http://ws.wso2.org/dataservice">$5</xs:score>
<xs:remarks xmlns:xs="http://ws.wso2.org/dataservice">$6</xs:remarks>
<xs:feedback xmlns:xs="http://ws.wso2.org/dataservice">$7</xs:feedback>
</p:Insert_ttemplatedetails_Mobile_Op>
</format>
<args>
<arg expression="get-property('ttemplateformid')"/>
<arg expression="//sectionQuestionMapId/text()"/>
<arg expression="//QuestionId/text()"/>
<arg expression="//Rank/text()"/>
<arg expression="//answer/text()"/>
<arg expression="//remark/text()"/>
<arg expression="//Feedback/text()"/>
</args>
</payloadFactory>
<log level="full"/>
<send receive="QuestionsInsertion_Seq3">
<endpoint>
<address uri="http://localhost:9764/services/ttemplatesectiondetail_DataService/"
format="soap11"/>
</endpoint>
</send>
<log level="full"/>
</sequence>
</target>
</iterate>
i am doing well how can i know above how many arrays i got
<sequence xmlns="http://ws.apache.org/ns/synapse"
name="QuestionsInsertion_Seq3"
onError="fault">
<property name="FORCE_ERROR_ON_SOAP_FAULT"
value="true"
scope="axis2"
type="STRING"/>
<property xmlns:f="http://ws.wso2.org/dataservice"
xmlns:ns="http://org.apache.synapse/xsd"
name="ttemplatedetailid"
expression="//f:ttemplatedetailid/text()"
scope="default"
type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Total"
expression="count(//QuestionId/text())"
scope="default"
type="STRING"/>
<property xmlns:f="http://ws.wso2.org/dataservice"
xmlns:ns="http://org.apache.synapse/xsd"
name="ttemplatedetailid"
expression="//f:ttemplatedetailid/text()"/>
</log>
I am loging QuesionId count but i am not getting i am getting as total is 1.0 only
i need to count in proxy only or in sequence
thanx in advance

You can not count the iteration..What you are trying now is, you are getting DS response in your receive sequence, and from the response you are trying to read a value. So, check your response, and see what you are getting from endpoint

Related

Filter mediator not working Properly in WSO2 EI 6.6

I'm trying to handle the response in the out sequence by using filter mediator with condition as (Vin number Updated Successfully) if it's satisfy Then block needs to be excluded but instead of Then block the else block is executed so Please tell me what did I mistaken in the below mentioned code. Thanks!
<outSequence>
<log level="custom">
<property expression="json-eval($.)" name="===Response from COMS==="/>
</log>
<log level="custom">
<property expression="json-eval($)" name="ComsResponse"/>
</log>
<property expression="json-eval($.ComsResponse)" name="Response" scope="default" type="STRING"/>
<filter regex="Vin number Updated Successfully" source="$ctx:Response">
<then>
<payloadFactory description="Form Response Payload" media-type="json">
<format>{"StatusCode":"$1","Message":"$2"}</format>
<args>
<arg value="200"/>
<arg value="Updated Sucessfully"/>
</args>
</payloadFactory>
</then>
<else>
<payloadFactory description="Form Response Payload" media-type="json">
<format>{"StatusCode":"$1","Message":"$2"}</format>
<args>
<arg value="400"/>
<arg value="Unable to Created or Vin Number already exist"/>
</args>
</payloadFactory>
</else>
</filter>
<respond/>
<property description="HTTPStatusCode" name="HTTP_SC" scope="axis2" type="STRING" value="200"/>
<property description="HttpMessageType" name="messageType" scope="axis2" type="STRING" value="application/json"/>
</outSequence>
The property ComsResponse is probably empty.
<property expression="json-eval($.ComsResponse)" name="Response" scope="default" type="STRING"/>
The json-eval statement is looking for a ComsResponse element/key within the message. This does not exist as the result of just $. is only a string.
So currently the filter is testing the regex against an empty string. Try setting the Response property as follows:
<property expression="json-eval($.)" name="Response" scope="default" type="STRING"/>
For more details on the json-eval function check the WSO2 documentation.

WSO2 ESB call not passing envelope

I have an API of the form
<api xmlns="http://ws.apache.org/ns/synapse" name="MyRestApi" context="/practice">
<resource methods="GET" uri-template="/{someValue}">
<inSequence>
<header name="Action" value="urn:sayHello"/>
<payloadFactory media-type="xml">
<format>
<p:sayHello xmlns:p="http://practice">
<p:inputString>$1</p:inputString>
</p:sayHello>
</format>
<args>
<arg evaluator="xml" expression="$ctx:uri.var.someValue"/>
</args>
</payloadFactory>
<log level="full"/>
<call>
<endpoint>
<address uri="http://192.168.0.105:9763/services/Practice/sayHello" format="soap12"/>
</endpoint>
</call>
<enrich>
<source type="body" clone="true"/>
<target type="property" action="child" property="body_of_first_call"/>
</enrich>
<property xmlns:ns="http://practice" name="response" expression="//ns:return" scope="default" type="STRING"/>
<property xmlns:ns="http://practice" name="response2" expression="//ns:sayHelloResponse" scope="default" type="STRING"/>
<log>
<property name="myValue" expression="$ctx:response"/>
<property name="myValue2" expression="$ctx:response2"/>
<property name="myValue3" expression="$ctx:body_of_first_call"/>
</log>
<payloadFactory media-type="xml">
<format>
<result>
<sentValue>$1</sentValue>
<returnedValue>$2</returnedValue>
</result>
</format>
<args>
<arg evaluator="xml" expression="$ctx:uri.var.someValue"/>
<arg evaluator="xml" expression="$ctx:response"/>
</args>
</payloadFactory>
<property name="messageType" value="application/xml" scope="axis2" type="STRING"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Based almost entirely on a guide found here
It's at this point just an attempt to grasp the concepts of connectors and APIs so I can apply it to what I'm doing at work, but I've hit a snag. Any attempts to communicate with an outside SOAP service, which my ESB will need to do, either fails to find the endpoint or fails to pass on the values in the SOAP envelope.
As written above the code will find the endpoint, but the input value inputString in the request is always null. It's essentially identical to putting that address into your browser which completely omits the SOAP envelope, however logging the call prints the envelope as expected to the console so the envelope is being generated but not making its way to the application server.
Things I have also tried:
1) Changing the endpoint address to be the service endpoint, rather than the specific operation. This causes an error from the AS claiming the operation cannot be found. This endpoint and operation work as expected in SoapUI.
2) Using a WSDL endpoint instead of address. Result is the same as in 1.
3) Adding/removing the header tag. All three endpoints have been tried with/without the header tag. Their results do not change.
At this point I've exhausted my admittedly poor understanding of ESBs.
To invoke my service I set up my mediator this way.
<call blocking="true">
<endpoint>
<address uri="http://169.254.193.10:9769/services/ServicePharmacy" format="soap11"/>
</endpoint>
</call>
the blocking property in true is to do synchronous messaging
<call blocking="true">
</call>
this is my API
<api xmlns="http://ws.apache.org/ns/synapse" name="showByIdCallMediator" context="/getByIdCall">
<resource methods="GET" uri-template="/{Id}">
<inSequence>
<property name="getId" expression="get-property('uri.var.Id')" scope="default" type="STRING"/>
<log>
<property name="ID" expression="get-property('getId')"/>
</log>
<payloadFactory media-type="xml">
<format>
<p:searchPharmacy xmlns:p="http://pharmacy.arce.org">
<ax22:pharmacy xmlns:ax22="http://pharmacy.arce.org">
<xs:id xmlns:xs="http://pharmacy.arce.org/xsd">$1</xs:id>
</ax22:pharmacy>
</p:searchPharmacy>
</format>
<args>
<arg evaluator="xml" expression="get-property('getId')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="urn:searchPharmacy"/>
<call blocking="true">
<endpoint>
<address uri="http://169.254.193.10:9769/services/ServicePharmacy" format="soap11"/>
</endpoint>
</call>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2','HTTP_SC')"/>
</log>
<log level="full"/>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="Ouput_Respose_Service"/>
</enrich>
<log level="custom" separator=",">
<property name="Service_Response" expression="get-property('Ouput_Respose_Service')"/>
</log>
<respond description=""/>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
<faultSequence>
<sequence key="{faultSEQ}"/>
</faultSequence>
</resource>
</api>

How to create a Global Variable in Wso2 ESB

I am new to the WSO2 esb,Am working with wso2esb 4.7.0,wso2dss 3.0.0.
I want to create a global variable and call that variable into my proxy services
My proxy is as shown below
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Get_details" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target endpoint="Endpoint">
<inSequence>
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<log>
<property name="username" expression="get-property('username')"/>
<property name="password" expression="get-property('password')"/>
</log>
<payloadFactory media-type="xml">
<format>
<p:select_login_op xmlns:p="http://ws.wso2.org/dataservice">
<p:username>$1</p:username>
<p:password>$2</p:password>
</p:select_login_op>
</format>
<args>
<arg evaluator="xml" expression="get-property('username')"/>
<arg evaluator="xml" expression="get-property('password')"/>
</args>
</payloadFactory>
<property name="Get" expression="fn:concat('http://192.168.1.201:9764/services/', 'Get_details')"/>
<header name="To" expression="get-property('Get')"/>
<send>
<endpoint>
<default/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
<description/>
</proxy>
In the above proxy i have used concat function to combine my Url and Service name,here what i want to do is i want to use a variable instead of url by creating a global variable and assign the url as its value and use that variable in the concat function instead of url in this proxy and several other proxy also.
How can this be done?
You can save the value as a Local Registry Entry and use it from inside proxy services. For example if I have a Local Entry called 'MyURL' I can use it as below
synapse:get-property('MyURL')
Another example;
<log level="custom">
<property name="MyURL" expression="synapse:get-property('MyURL')"/>
</log>
A sample for ESB 5.0.0:
Suppose we have the current time in a property named nowTimeProp.
<property name="nowTimeProp" expression="get-property('SYSTEM_TIME')" scope="default"/>
Storing the property in the registry:
<property name="conf:/resource/yourResourceName" type="STRING" expression="$ctx:nowTimeProp" scope="registry"/>
Later, we'd like to read the property from the registry:
<property name="lastStoredInstantProp" expression="get-property('registry', 'conf:/resource/yourResourceName')"/>

How to send to multiple endpoints in wso2esb

I am using wso2esb-4.8.1,
I wish to log the transaction details after response back to client.
For that I have written Proxy as well as sequence but wso2esb-4.8.1 is not supporting that with send mediator ,because I want t use load balance for every endpoint where as same logic is working in CallOUt mediator with URL option not with address endpoint .
proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test_Proxy" transports="https http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence onError="FaultSeq">
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="ProxyInRequest"
expression="/soapenv:Envelope"/>
</log>
<xquery key="ProxyRequestTransformation">
<variable xmlns:ns="http://org.apache.synapse/xsd" name="Operation" expression="//Operation/text()" type="STRING"/>
<variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceNameSpace" expression="//ServiceNameSpace/text()" type="STRING"/>
<variable name="Payload" type="DOCUMENT_ELEMENT"/>
<variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceName" expression="//Service/text()" type="STRING"/>
</xquery>
<send>
<endpoint>
<address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence onError="FaultSeq">
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property action="set" name="RESPONSE" scope="default" type="STRING" value="true"/>
<send/>
<sequence key="AuditSeq"/>
</outSequence>
</target>
<publishWSDL key="EaiEnvelope"/>
</proxy>
In above proxy i have used default send mediator after that trying to do audit in same flow ,My client is getting response back but details are not auditing even not getting any error.
My sequence
<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuditSeq"> <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_CODE" expression="get-property('ResultCode')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_MESSAGE" expression="get-property('ResultMessage')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="REFERENCE_ID" expression="get-property('ReferenceID')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="FAULT_DETAILS" expression="concat(get-property('ERROR_CODE'),get-property('ERROR_MESSAGE'))" scope="default" type="STRING"/>
<payloadFactory media-type="xml">
<format>
<open:processRequest xmlns:open="http://www.openuri.org/">
<aud:Auditor xmlns:aud="http://jhm.kkk.fff/Auditor">
<aud:Request>
<aud:Operation_Name>processRequest</aud:Operation_Name>
<aud:Auditor_InputData>
<aud:Result_Code>$1</aud:Result_Code>
<aud:Result_Message>$2</aud:Result_Message>
<aud:Reference_Id>$3</aud:Reference_Id>
</aud:Auditor_InputData>
</aud:Request>
</aud:Auditor>
</open:processRequest>
</format>
<args>
<arg evaluator="xml" expression="get-property('RESULT_CODE')"/>
<arg evaluator="xml" expression="get-property('RESULT_MESSAGE')"/>
<arg evaluator="xml" expression="get-property('REFERENCE_ID')"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="http://www.openuri.org/processRequest"/>
<send>
<endpoint>
<address uri="http://localhost:8081/middleware/services/AuditService" format="soap11"/>
</endpoint>
</send>
<log>
<property name="aftersend" value="message going out or not"/>
</log>
</sequence>
With above send mediator is not working .But after send my log is printing.
If i replace send mediator with CallOut URL option its working fine.
<callout serviceURL="http:///localhost:8081/middleware/services/AuditService">
<source type="envelope"/>
<target key="IsThisResponse"/>
</callout>
In above we are not able to use loadbalancing.For that I trying for send mediator.
Is any way to do this.
I thouhgt wso2esb-4.8.1 is become stable but again its having drawbacks.
Thanks in advance.
Please try by changing the send mediator in your proxy as mentioned here it may help you
<send receive="AuditSeq">
<endpoint>
<address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
</endpoint>
</send>

How Can I handle Error sequence in WSO2ESB

i want handle error using fault sequence but i wish to customize it with delete operation
my scenario is while i am inserting in 2 tables if error occurred in 2nd table insertion i need to delete 1 st row insertion also my config is below
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ErrorHandling" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target >
<inSequence onError="fault">
<property name="eno" expression="//eno/text()" scope="default" type="STRING"/>
<property name="ename" expression="//ename/text()" scope="default" type="STRING"/>
<property name="esal" expression="//esal/text()" scope="default" type="STRING"/>
<property name="deptname" expression="//deptname/text()" scope="default" type="STRING"/>
<property name="deptid" expression="//deptid/text()" scope="default" type="STRING"/>
<payloadFactory>
<format>
<p:insert_emp_operation xmlns:p="http://ws.wso2.org/dataservice">
<xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
<xs:ename xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:ename>
<xs:esal xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:esal>
</p:insert_emp_operation>
</format>
<args>
<arg expression="get-property('eno')"/>
<arg expression="get-property('ename')"/>
<arg expression="get-property('esal')"/>
</args>
</payloadFactory>
<send receive="Error_Seq">
<endpoint>
<address uri="http://localhost:9764/services/emp_DataService/" format="soap11"/>
</endpoint>
</send>
<log level="full"/>
</inSequence>
<outSequence onError="fault">
<send/>
<log level="full"/>
</outSequence>
</target>
<description></description>
</proxy>
and sequence is like this
<sequence xmlns="http://ws.apache.org/ns/synapse" name="Error_Seq" onError="fault">
<property xmlns:f="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" name="ID" expression="//f:ID/text()" scope="default" type="STRING"/>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="faisal" expression="get-property('ID')"/>
</log>
<payloadFactory>
<format>
<p:insert_dept_operation xmlns:p="http://ws.wso2.org/dataservice">
<xs:deptno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:deptno>
<xs:deptname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:deptname>
<xs:deptid xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:deptid>
</p:insert_dept_operation>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ID')"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('deptname')"/>
<arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('deptid')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="http://localhost:9764/services/dept_DataService/" format="soap11"/>
</endpoint>
</send>
</sequence>
fault sequenceis like this
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault">
<property xmlns:ns="http://org.apache.synapse/xsd" name="ID" expression="get-property('ID')" scope="default" type="STRING"/>
<log level="full">
<property name="MESSAGE" value="Executing default 'fault' sequence"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Property" expression="get-property('ID')"/>
</log>
<payloadFactory>
<format>
<p:Delete_Op xmlns:p="http://ws.wso2.org/dataservice">
<xs:eno xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:eno>
</p:Delete_Op>
</format>
</payloadFactory>
<send>
<endpoint>
<address uri="http://localhost:9764/services/dept_DataService/" format="soap11"/>
</endpoint>
</send>
</sequence>
but its not working its working while the DSS Is in OFF mode let me know when DSS is In Running mode how to delete the 1st table row
In your scenario when update fails at DSS, it will send back a SOAP fault to the ESB.
Since ESB this is still just another message response, and it will not goto the fault sequence, unless you explicitly check the message and do the necessary actions.
So you have to declare comming message is a SOAP_FAULT so you hace to say it is a SOAP_FAULT and force it to error sequance. This is explained in [1].
[1] http://maharachchi.blogspot.com/2012/09/now-you-can-send-soapfaults-to-fault.html