Wso2 developer studio 3.6.0 removing $ from XPATH variables after build - variables

From proxy service or sequence or rest API WSO2 developer studio 3.6.0 is removing $ from XPATH variables like $ctx, $trp, $body etc after build. Please advice me how to fix this issue or work around for this.
example sequence
<sequence xmlns="http://ws.apache.org/ns/synapse" name="XMFSequence">
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:np1="http://ws.apache.org/commons/ns/payload" xmlns:np="http://schemas.xmlsoap.org/soap/envelope/" xmlns:np2="http://services.www.up.com/xmf/2.0" name="serviceName" expression="//np:Envelope/np:Header/np2:request-header/np2:service-name" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:fn="http://www.w3.org/2005/xpath-functions" name="localEntryName" expression="fn:replace($ctx:serviceName,'/','-')" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="contractEnforcedVal" expression="get-property(get-property('localEntryName'))" scope="default" type="STRING"/>
<filter xmlns:ns="http://org.apache.synapse/xsd" xpath="fn:contains(get-property('contractEnforcedVal'),$trp:XMFRequestor)">
<then>
<filter xpath="fn:contains(get-property('contractEnforcedVal'),'isSecured=true')">
<then>
<class name="com.uprr.app.poc.esb.mediator.RequestHandler">
<property name="secValServiceURL" value="http://localhost:9080/SecurityService/secure-util"/>
</class>
<filter xpath="fn:contains(get-property('isAuthorized'),'true')">
<then>
<send>
<endpoint key-expression="get-property('serviceName')"/>
</send>
</then>
<else>
<drop/>
</else>
</filter>
</then>
<else>
<send>
<endpoint key-expression="get-property('serviceName')"/>
</send>
</else>
</filter>
</then>
<else>
<drop/>
</else>
</filter>

Please check the maven-car-plugin's version in the CAPP's pom file. It should be 2.0.8 as shown below
<groupId>org.wso2.maven</groupId>
<artifactId>maven-car-plugin</artifactId>
<version>2.0.8</version>
Also make sure the ESB project's pom file contains the version 2.0.8 as the sequence plugin version
<groupId>org.wso2.maven</groupId>
<artifactId>wso2-esb-sequence-plugin</artifactId>
<version>2.0.8</version>

Related

wso2esb 4.8.1 and 4.9.0 different behaviour onError

I have a registered onError sequence.
In version 4.8.1 SOAP envelop is available in onError sequence
while in 4.9.0 it is not.
in order to access SOAP message content in 4.9.0 after error (in onError sequence) I always have to copy it to some temp variable initially. it is very inconvenient.
could it be a bug or is it a new "feature" of 4.9.0?
this is my fault sequence. if i remove enrich mediator envelope comes empty from the sequence with an error. Without enrich mediator message contains empty soap envelope. It can be seen in the output of the log mediator and in the message stored in RabbitMQ backend. Actually, it is onError sequence of XXXXNotifySendSequence sequence (I added them both for the reference).
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="mssg" expression="get-property('mssg')"/>
<property name="retry_count" expression="get-property('retry_count')"/>
</log>
<filter xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xpath="get-property('mssg')">
<then>
<enrich>
<source clone="true" property="mssg" type="property"/>
<target type="envelope"/>
</enrich>
<property name="mssg" action="remove"/>
</then>
<else/>
</filter>
<filter xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://org.apache.synapse/xsd" xpath="get-property('retry_count')">
<then>
<property name="retry_count" expression="number(get-property('retry_count'))+1" scope="default" type="STRING"/>
<filter xpath="get-property('retry_count') > 5">
<then>
<log>
<property name="Dropping--Count" expression="get-property('retry_count')"/>
</log>
<drop/>
</then>
<else>
<sequence key="XXXXNotifySendSequence"/>
</else>
</filter>
</then>
<else>
<property name="retry_count" value="1" scope="default" type="STRING"/>
<clone continueParent="true">
<target>
<sequence>
<makefault version="soap11">
<code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/>
<reason expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</sequence>
</target>
</clone>
</else>
</filter>
<clone>
<target>
<sequence>
<log level="custom">
<property name="STORE" value="store the message"/>
</log>
<store messageStore="XXXXRabbitMQNative"/>
</sequence>
</target>
</clone>
</sequence>
this is the sequence calling onError sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifySendSequence"
onError="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="XXXX" value="request start"/>
</log>
<enrich>
<source clone="true" type="envelope"/>
<target property="mssg" type="property"/>
</enrich>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<call>
<endpoint key="HTTPEndpoint"/>
</call>
<log level="full">
<property name="XXXX" value="request end"/>
</log>
</sequence>
I am not much sure why you written fault sequence in that way. but when i change like bellow its working. no need to enrich and assign to other property
Sequence:(same as yours - untouched)
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifySendSequence"
onError="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="XXXX" value="request start"/>
</log>
<enrich>
<source clone="true" type="envelope"/>
<target action="replace" property="mssg" type="property"/>
</enrich>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<call>
<endpoint key="HTTPEndpoint"/>
</call>
<log level="full">
<property name="XXXX" value="request end"/>
</log>
</sequence>
fault sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XXXXNotifyErrorSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log>
<property expression="get-property('ERROR_CODE')"
name="========error-code=========" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="get-property('ERROR_MESSAGE')"
name="========error-message=========" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<makefault version="soap11">
<code value="soap11Env:VersionMismatch" xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/"/>
<reason expression="get-property('ERROR_MESSAGE')" xmlns:ns="http://org.apache.synapse/xsd"/>
<role>sample</role>
<detail>sample detail</detail>
</makefault>
<send/>
</sequence>
proxy: to call sequence
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="samplecall"
transports="http,https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target inSequence="XXXXNotifySendSequence"/>
<description/>
</proxy>
response: (since end point is not defined)
<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/">soap11Env:VersionMismatch</faultcode>
<faultstring>Couldn't find the endpoint with the key : HTTPEndpoint</faultstring>
<faultactor>sample</faultactor>
<detail>sample detail</detail>
</soapenv:Fault>
in log:
2015-11-08 17:19:55,250] INFO - LogMediator To: /services/samplecall.samplecallHttpSoap11Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:106d763f-cdc1-43d2-98a9-63d22d17eb81, Direction: request, XXXX = request start, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
[2015-11-08 17:19:55,252] INFO - LogMediator To: /services/samplecall.samplecallHttpSoap11Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:106d763f-cdc1-43d2-98a9-63d22d17eb81, Direction: request, ========error-code========= = 305100, ========error-message========= = Couldn't find the endpoint with the key : HTTPEndpoint

WSO2 ESB API configuration to send same post request to different Rest services

I need to send a post request to different REST services, below is the complete requirement.
I am using REST API configuration of WSO2 ESB
First I need to post a request to one service and based on successful posting then need to post this same to another service. But I need to obtain the response from first service and send it to fronend. But I do not need to obtain the response from second service.
Please find the API configuration below and help me.
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="POST DELETE PUT GET">
<inSequence>
<log level="custom">
<property name="Message Flow" value="Roovershof Plant Search API - IN"></property>
<property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"></property>
<property name="ip address" expression="get-property('axis2','REMOTE_ADDR')"></property>
<property name="Authorization" expression="get-property('transport','Authorization')"></property>
</log>
<property name="TIME_IN" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
<send>
<endpoint>
<address uri="service1"></address>
</endpoint>
</send>
<log level="custom">
<property name="Request Method :" expression="get-property('axis2', 'HTTP_METHOD')"></property>
</log>
<filter source="get-property('axis2', 'HTTP_SC')" regex="201">
<then>
<clone continueParent="true">
<target>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<property name="messageType" value="application/json" scope="axis2"></property>
<property name="HTTP_METHOD" value="POST" scope="axis2"></property>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"></property>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<send>
<endpoint>
<address uri="servicr2"></address>
</endpoint>
</send>
</target>
<target sequence="magento" />
</clone>
Your synapse configuration does not match your statement. You have to preserve the original message using enrich mediator and then make use the call mediator for your first endpoint invocation.
Then based on the results, you send the response back to your client and do the send call by reloading the message from the preservation.
<api xmlns="http://ws.apache.org/ns/synapse" name="TestApi" context="/TestContext">
<resource methods="POST GET">
<inSequence>
<log level="custom">
<property name="Message Flow" value="Roovershof Plant Search API - IN"></property>
<property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"></property>
<property name="ip address" expression="get-property('axis2','REMOTE_ADDR')"></property>
<property name="Authorization" expression="get-property('transport','Authorization')"></property>
</log>
<property name="TIME_IN" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
<enrich>
<source type="body" clone="true"></source>
<target type="property" property="INIT_MSG_PAYLOAD"></target>
</enrich>
<call>
<endpoint>
<address uri="service1"></address>
</endpoint>
</call>
<filter source="get-property('axis2', 'HTTP_SC')" regex="201">
<then>
<clone continueParent="true">
<target>
<sequence>
<respond></respond>
</sequence>
</target>
<target>
<sequence>
<enrich>
<source type="property" clone="true" property="INIT_MSG_PAYLOAD"></source>
<target type="body"></target>
</enrich>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<property name="messageType" value="application/json" scope="axis2"></property>
<property name="HTTP_METHOD" value="POST" scope="axis2"></property>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"></property>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
<send>
<endpoint>
<address uri="servicr2"></address>
</endpoint>
</send>
</sequence>
</target>
</clone>
</then>
<else>
<respond/>
</else>
</filter>
</inSequence>
</resource>
</api>

WSO2 ESB: Display dataService response

How do you display the response returned by calling a webservice endpoint on a sequence?
Below is the sequence that I use. I would like to display the return value from the dataservice called "CDServiceEndpoint" on the wso2carbon.log. Is that possible? If not, how can I get the data displayed.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="ConcurGetADPExtractFlow" onError="GeneralErrorHandler">
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="current-context-details" expression="concat(get-property('current-context-details'), ', ConcurGetADPExtractFlow')" />
<property name="scenario" value="ConcurGetADPExtractFlow" />
<log level="custom">
<property name="DEBUGGING" value="ConcurGetADPExtractFlow" />
<property name="start-date" value="2015-02-23" />
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="End Date" expression="get-property('current-date')" />
</log>
<xslt key="Concur_Get_ADP_Extract_Transformation">
<property name="start-date" value="2015-03-02" />
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="end-date" expression="get-property('current-date')" />
</xslt>
<property name="post-data-service-sequence" value="ConcurTransformADPExtractFlow" />
<property name="OUT_ONLY" value="false" />
<send receive="DataServiceInvocationErrorFlow">
<endpoint key="ConcurDataServiceEndpoint" />
</send>
<description>Sends a request to the data service for the ADP extract data.</description>
</sequence>
Below is how my DataServiceInvocationErrorFlow looks like.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="DataServiceInvocationErrorFlow">
<filter xmlns:ns="http://org.apache.synapse/xsd" xmlns:m="http://ws.wso2.org/dataservice" xmlns:ns3="http://org.apache.synapse/xsd" xpath="//m:DataServiceFault">
<then>
<log level="custom">
<property name="status" value="data-service-fault" />
</log>
<property name="error_message" expression="//m:DataServiceFault" />
<sequence key="GeneralErrorHandler" />
<drop />
</then>
<else>
<filter source="string-length(get-property('ERROR_MESSAGE'))" regex="0.0">
<then>
<filter xpath="//soapenv:Fault">
<then>
<log level="custom">
<property name="status" value="ERROR" />
</log>
<property name="error_message" expression="//soapenv:Fault" />
<sequence key="GeneralErrorHandler" />
<drop />
</then>
<else>
<log level="custom">
<property name="status" value="success response from DSS" />
</log>
<filter source="string-length(normalize-space(get-property('post-data-service-sequence')))" regex="0.0">
<then />
<else>
<property name="temp-post-data-service-sequence" expression="get-property('post-data-service-sequence')" />
<property name="post-data-service-sequence" value="" />
<sequence key="{get-property('temp-post-data-service-sequence')}" />
</else>
</filter>
</else>
</filter>
</then>
<else>
<property name="error_message" expression="get-property('ERROR_MESSAGE')" />
<sequence key="GeneralErrorHandler" />
<drop />
</else>
</filter>
</else>
</filter>
</sequence>
If by CDServiceEndpoint you meant ConcurDataServiceEndpoint, then you are already handling the response from that endpoint in your DataServiceInvocationErrorFlow sequence that you defined on the Send mediator, which by the way is confusingly named, since your receive sequence will run no matter if you get an error response or a good one. All you need to do is log it inside DataServiceInvocationErrorFlow using Log mediator.
Had you not defined a receive sequence on your Send mediator, the response would have gotten to your outSequence, where you can log it with Log mediator too.

Issue in getting response back while connecting to Oracle DB in WSO2 esb

I am working on sample application in WSO2 esb
which connects to Oracle Database and return the response of a query. Below mentioned is my service. Issue I am facing is I am not getting the response back after execution of service.However I am able to see the value returned as a query response, but not able to render it in response document.
Can anybody suggest, what I am missing?
DB credentials fields have been hashed.
Proxy :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="getEmployeeDetails"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true" scope="default" type="BOOLEAN"/>
<log level="full" category="DEBUG"/>
<dblookup>
<connection>
<pool>
<password>****</password>
<user>****</user>
<url>****</url>
<driver>oracle.jdbc.xa.client.OracleXADataSource</driver>
</pool>
</connection>
<statement>
<sql>select firstname from employee where lastname = 'pawar'</sql>
<result name="firstname" column="firstname"/>
</statement>
</dblookup>
<log level="custom">
<property name="firstname" expression="get-property('firstname')"/>
</log>
<payloadFactory media-type="xml">
<format>
<GetEmployeeDetailsResponse xmlns="">
<out>$1</out>
</GetEmployeeDetailsResponse>
</format>
<args>
<arg evaluator="xml" expression="get-property('firstname')"/>
</args>
</payloadFactory>
</inSequence>
<outSequence>
<log level="full" category="DEBUG"/>
</outSequence>
</target>
<publishWSDL uri="file:/development/data/wso2/wsdl/Employee.wsdl"/>
<description/>
</proxy>
You have to send back the message generated by your payloadFactory in your inSequence :
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<send/>
Your mediation is "OUT_ONLY", so, your outSequence will never been executed

How to add Authentication to my proxy service(get) in wso2 esb(4.6.0)please any one help me the procedure,i cant find much more on this?

These are the below proxy service and sequences...if i am running with empty curl command data is showing for get service,so that i want to authenticate that data
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Get_meter_Mobile" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence onError="fault">
<property name="CONTENT_TYPE" value="application/json" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<payloadFactory>
<format>
<mmeter xmlns=""/>
</format>
</payloadFactory>
<send receive="Get_meter_Mobile_seq">
<endpoint>
<address uri="http://localhost:9764/services/meter_DataService/" format="soap11"/>
</endpoint>
</send>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')" scope="axis2" type="STRING"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')" scope="axis2" type="STRING"/>
<log level="full"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
</inSequence>
<outSequence>
<property name="CONTENT_TYPE" value="application/json" scope="axis2"/>
<log level="full"/>
<send/>
</outSequence>
</target>
<description></description>
</proxy>
You can achice this by applying POX security to your Proxy service. The blog post [1] will show you the steps to follow.
[1]. http://evanthika.blogspot.com/2012/12/pox-security-with-wso2-esb-proxy.html
Thank You,
Dharshana.