WSO2 EI Sequence failing when calling a Data Service - wso2

Running WSO2 EI 6.2.0
My sequence is very simple:
Receive 1 parameter (mac) from initial request
Call a DS to extract a second parameter (time_hour)
Call a DS with both parameters (mac) and (time_hour)
When calling both DS manually, it works perfectly.
When calling the second DS through ESB I get a strange error.
The sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="somesq" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$url:mac" name="uri.var.mac" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="mac" scope="default" type="STRING" value="get-property('uri.var.mac')"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var={uri.var.mac}"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target action="replace" property="payload" type="property"/>
</enrich>
<log level="custom">
<property expression="get-property('payload')" name="bbb" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<property expression="$ctx:payload//ns2:hour" name="time_hour"
scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns2="http://ws.wso2.org/dataservice"/>
<header action="remove" name="Content-Type" scope="transport"/>
<log level="custom">
<property expression="get-property('uri.var.mac')" name="mac" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<log level="custom">
<property expression="get-property('time_hour')"
name="time_hour" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var={uri.var.mac}&hour={time_hour}"/>
</endpoint>
</call>
<log level="custom">
<property name="xxx" value="FIM"/>
</log>
<respond/>
</sequence>
I try to log the parameters before calling the DS and they are correctly printed, but when I use it in the DS Call, the hour={time_hour} parameter is empty.
The output and error:
(...)
TID: [-1234] [] [2018-12-05 12:24:02,562] INFO {org.apache.synapse.mediators.builtin.LogMediator} - mac = 000000000000 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-12-05 12:24:02,562] INFO {org.apache.synapse.mediators.builtin.LogMediator} - time_hour = 2018-12-03T11:00:00.000+00:00 {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2018-12-05 12:24:02,569] ERROR {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver} - Error in in-out message receiver {org.wso2.carbon.dataservices.core.DBInOutMessageReceiver}
DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processPreNormalQuery': DS Fault Message: Error processing parameter - hour, Error - DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
DS Code: UNKNOWN_ERROR
Nested Exception:-
DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
DS Code: DATABASE_ERROR
Source Data Service:-
Name: some_seq
Location: /some_seq.dbs
Description: Some Seq
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: somesq
Current Params: {hour=, mac=000000000000}
Nested Exception:-
DS Fault Message: Error processing parameter - hour, Error - DS Fault Message: Empty string or null value was found as timeStamp.
DS Code: UNKNOWN_ERROR
(...)
Anyone knows how to correctly reference the time_hour parameter to the data services in the ESB Sequence?
Explanation of why the variable time_hour was not being evaluated
From WSO2 Documentation:
The URI templates allow a RESTful URI to contain variables that can be
populated during mediation runtime using property values whose names
have the "uri.var" prefix.
The Final Sequence that is working based on Jan's response:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="some_seq" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$url:mac" name="uri.var.mac" scope="default"
type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var=={uri.var.mac}"/>
</endpoint>
</call>
<enrich>
<source clone="true" type="body"/>
<target action="replace" property="payload" type="property"/>
</enrich>
<property expression="$ctx:payload//ns2:hour"
name="uri.var.time_hour" scope="default" type="STRING"
xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns2="http://ws.wso2.org/dataservice"/>
<header action="remove" name="Content-Type" scope="transport"/>
<call>
<endpoint>
<http method="GET" uri-template="http://somedomain.internal.com/someservice?var=={uri.var.mac}&hour={uri.var.time_hour}"/>
<property name="time_h" value="{time_hour}"/>
</endpoint>
</call>
<respond/>
</sequence>

It needs 'uri.var' as variable name for it to be usable as uri-template variable.
So create a property with the current time. (I'm surprised btw that 'time_hour' works for you, in my case I used SYSTEM_DATE, time_hour reverts to 'null' )
<property expression="get-property('SYSTEM_DATE')" name="uri.var.time_hour"/>
and use that in your endpoint.

Related

SOAPProcessingException occurred when execute the artifact in WSO2 ESB

I used WSO2 ESB 5.0. I used two soap endpoints to get the response. Below mention the proxy service code.
<?xml version="1.0" encoding="UTF-8"?>
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<log/>
<property expression="//sam:getCertificateID/sam:vehicleNumber"
name="getVehicleNo" scope="default" type="STRING" xmlns:sam="http://sample.esb.org"/>
<log>
<property expression="get-property('default','getVehicleNo')" name="VehicleNo"/>
</log>
<call>
<endpoint>
<wsdl port="EmissionTestServiceHttpSoap11Endpoint"
service="EmissionTestService" uri="http://172.17.0.1:9763/services/EmissionTestService?wsdl"/>
</endpoint>
</call>
<property expression="//ns:getCertificateIDResponse/ns:return"
name="getCertificateIDResponse" scope="default" type="STRING" xmlns:ns="http://sample.esb.org"/>
<log>
<property
expression="get-property('default','getCertificateIDResponse')" name="CertificateID"/>
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:sam="http://sample.esb.org" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sam:getPolicyID>
<sam:vehicleNumber>$1</sam:vehicleNumber>
</sam:getPolicyID>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="get-property('default','getVehicleNo')"/>
</args>
</payloadFactory>
<log/>
<property name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<call>
<endpoint>
<wsdl port="InsuranceServiceHttpSoap11Endpoint"
service="InsuranceService" uri="http://172.17.0.1:9763/services/InsuranceService?wsdl"/>
</endpoint>
</call>
<property expression="//ns:getPolicyIDResponse/ns:return"
name="getPolicyIDResponse" scope="default" type="STRING" xmlns:ns="http://sample.esb.org"/>
<log>
<property
expression="get-property('default','getPolicyIDResponse')" name="PolicyID"/>
</log>
</inSequence>
First endpoint is working fine and gave the specific log messages. But when going to call second endpoint, below error message is occurred.
Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found faultstring
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:305)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:252)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createNextOMElement(StAXSOAPModelBuilder.java:234)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
at org.apache.synapse.transport.passthru.util.DeferredMessageBuilder.getDocument(DeferredMessageBuilder.java:148)
at org.apache.synapse.transport.passthru.util.RelayUtils.builldMessage(RelayUtils.java:137)
... 14 more
Can you help me to solve this issue. Any help or workarounds are really appreciated.
Your endpoint is not returning an soap Envelope. You can see what's happening if you set 'configure->logging->apache.synapse.tranport.http.wire' to 'debug'.
Because the endpoint is not returning SOAP, but likely plain old XML you can try setting
<property name="messageType" value="application/xml" scope="axis2"/>
<property name="ContentType" value="application/xml" scope="axis2"/>
before sending the message.

wso2 Return property value from insequence

I'm creating an wso2 that call an endpoint and then filter the response just to send back one field, but for some reason the esb answer with all the json
I have something like that:
<resource methods="POST" uri-template="/ESB">
<inSequence>
<call description="">
<endpoint key="CountryEP"/>
</call>
<property description="" expression="json-eval($.zones[0].countryCode)" name="uri.var.countryCode" scope="default" type="STRING"/>
<log description="">
<property expression="fn:concat('countryCode ', get-property('uri.var.countryCode')) " name="property_name"/>
</log>
<send buildmessage="true" description=""/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
And my Endpoint
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="CountryEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" trace="enable" uri-template="http://api.timezonedb.com/v2/list-time-zone?key=6HW6EJUENX9T&format=json&country={uri.var.country}"/>
</endpoint>
So as you can see above, i send a parameter to the API, and the API answers with a json, then i try to parse just one field (using the property) and i have the correct value:
INFO - LogMediator To:
http://www.w3.org/2005/08/addressing/anonymous, WSAction: ,
SOAPAction: , MessageID:
urn:uuid:97744789-8c88-41ff-9475-870761016834, Direction: request,
property_name = countryCode CA
But i can't return just that value, the esb return all json... ideas?
Thanks in advance,
EDIT: also tried with RESPONSE attribute on the property mediator
Try something like this:
<call description="">
<endpoint key="CountryEP"/>
</call>
<property description="" expression="json-eval($.zones[0].countryCode)" name="uri.var.countryCode" scope="default" type="STRING"/>
<log description="">
<property expression="fn:concat('countryCode ', get-property('uri.var.countryCode')) " name="property_name"/>
</log>
<payloadFactory media-type="json">
<format>{ "Country Code": $1}</format>
<args>
<arg expression="$.zones[0].countryCode.text" evaluator="json"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<respond/>

wso2 esb sending dss error

I have a proxy inside wso2 esb. I used call and I want to send response from call to my outSequence. But it gives me Dss error.I do not use dss at all. Can anyone tell why this error happens and how can I solve this?
this is my proxy code:
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="FinaltestProxy"
startOnLoad="true"
statistics="disable"
trace="enable"
transports="https,http,vfs">
<target>
<inSequence>
<input type="text"/>
<output type="xml"/>
</smooks>
<iterate attachPath="//csv-set"
continueParent="true"
expression="//csv-set/search"
preservePayload="true"
sequential="true">
<target>
<sequence>
<call>
<endpoint>
<address format="soap11"
uri="MyEndpoint"/>
</endpoint>
</call>
<respond/>
</sequence>
</target>
</iterate>
</inSequence>
<outSequence>
<property name="OUT_ONLY" value="true"/>
<aggregate>
<completeCondition>
<messageCount max="100000" min="0"/>
</completeCondition>
<onComplete xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope"
expression="//Guest">
<log level="full"/>
<send>
<endpoint name="FileEpr">
<address format="soap11"
uri="MyEndpoint"/>
<property name="ContentType" scope="axis2" value="text/xml"/>
</endpoint>
</send>
</onComplete>
</aggregate>
</outSequence>
</target>
/* some code*/
</proxy>
and this is my Error:
DS Code: DATABASE_ERROR
Nested Exception:-
javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processNormalQuery'
DS Code: DATABASE_ERROR
Source Data Service:-
Name: GuestIdentityService
Location: /ss.dbs
Description: N/A
Default Namespace: http://soa.ut.ac.ir/GuestIdentityService
Current Request Name: searchGuestIdentity
Current Params: {ID=}
Nested Exception:-
java.lang.NumberFormatException: For input string: ""
Looks like you have a dataservice called ss, and it's being called somehow. Remove it if you don't want it. You can remove it from either UI or file system. It's located in repository/deployment/server/dataservices/
there was a blank line in my input and that cause the problem.

WSO2 ESB Content is not allowed in prolog exception in a OutSecuence

I am developing a proxy service with a soap webservice that performs soap to rest conversion, the message is sent to a servlet that response with a string in flat format (not xml), just a secuence of characters like
OIUW|ECHNOWE|RFHQWIUE|FBPQW|EFHAO|IEFH
I am invoking with SOAP UI and I get this response fine, now I would like to receive it in "SOAP format", wrapping the message into a soap:body, I've tried with a XSLT and with a PayloadFactory Mediator, but as soon as I use any of them (even doing nothing) I get a
[2014-07-31 09:30:41,847] ERROR - RelayUtils Error while building Passthrough stream
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
What do I do wrong ? How can I achieve a message transformation without this exception?
Thank you!
UPDATE: My proxy as requested by Ratha
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SCL3"
transports="http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<log level="custom">
<property name="MyTrace" value="--- REQUEST ---"/>
</log>
<log level="full"/>
<property name="REST_URL_POSTFIX"
value="x4?msg=x4|0003|0000000021|0|0|0400002081020224849"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<property name="SOAPAction" scope="default" action="remove"/>
<header name="Action" scope="default" action="remove"/>
<send>
<endpoint>
<address uri="http://localhost:8087/X4" format="pox"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="custom">
<property name="MyTrace" value="--- RESPONSE ---"/>
</log>
<property name="ContentType"
value="application/soap+xml"
scope="transport"
type="STRING"/>
<property name="messageType"
value="application/soap+xml"
scope="transport"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<a xmlns="">$1</a>
</format>
<args>
<arg value="my value"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:/C:/wso2/wso2esb-4.8.1/repository/workspaces/myproject/SCL3.wsdl"/>
</proxy>
I've seen that my servlet was setting content type to "text/xml" instead of "text/plain", I've changed it to "text/plain" and everything is working fine now.
Therefore I deduce that the error message
"Content is not allowed in prolog"
actually means
"Unexpected content type"
When you have following outsequence configuration what your log prints?
<outSequence>
<log level="full">
<property name="MyTrace" value="--- RESPONSE ---"/>
</log>
<send/>
</outSequence>

Adding parameters to the endpoint url wso2 esb

I am new to the WSO2 esb. I want to create a api in which i want to add a dynamic parameter from api Url to endpoint url.
My end point url is like http://example.com/api/sync/{session_id}.json
I tried to create api like
<api name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<send>
<endpoint name="Mecars">
<http trace="enable"
method="get"
uri-template="http://example.com/sync/{+uri.var.session}.json"/>
</endpoint>
</send>
</inSequence>
</resource>
</api>
In log i get the value of uri.var.session But on the endpoint Uri-template it is not appending.
Please guid me how append the {id} value in the api uri-template to end point uri-template?
Check this sample
I recommend you to do string concatenation at property mediator adn use that directly at uri-template, rather adding "variable +.json" at uri-template.
That is;
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="get-property('uri.var.id')"
scope="axis2"/>
In the above for expression do string concatenation to construct full variable with ".json" ending.
Please remove the '+' symbol from your http end point.Its working fine to me
sample API
<api xmlns="http://ws.apache.org/ns/synapse" name="Elastic Search Using NPI" context="/api/npi/professional/npi.json">
<resource methods="OPTIONS GET" uri-template="/{npi}">
<inSequence>
<log level="full">
<property name="uri.var.npi" expression="get-property('uri.var.npi')"></property>
</log>
<send>
<endpoint>
<http method="get" uri-template="example.com/{uri.var.npi}"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
Change the http endpoint uri template like follows.
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
Following is the modified api configuration.
<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/sync">
<resource methods="GET" uri-template="/{id}">
<inSequence>
<log level="full">
<property xmlns:ns="http://org.apache.synapse/xsd" name="uri.var.session" expression="get-property('uri.var.id')"></property>
</log>
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
<send>
<endpoint name="Mecars">
<http trace="enable" method="get" uri-template="http://example.com/sync/{uri.var.id}.json"></http>
</endpoint>
</send>
</inSequence>
</resource>
</api>
You can do the string concatenation at the property mediator as follows.
<property xmlns:ns="http://org.apache.synapse/xsd"
name="uri.var.session"
expression="fn:concat(get-property('uri.var.id'),'.json')"
scope="axis2"/>