why the response is strange in wso2 - wso2

I use postman to test
http://192.168.1.208:8090/jobsappName=sparkJoin001&classPath=com.mymoon.sql.SparkJoin
It's ok! It returns the message:
{
"status": "STARTED",
"result": {
"jobId": "3a47f931-f040-4e4a-a688-331f1918ae82",
"context": "6a171d9d-com.mymoon.sql.SparkJoin"
}
}
it's http status is 202!
I config in the wso2 esb and return some messages, but the browse shows the mixed message! It's stange!
The config is :
<api xmlns="http://ws.apache.org/ns/synapse" name="d" context="/dd">
<resource methods="GET" uri-template="/submit">
<inSequence>
<log level="full"/>
<payloadFactory media-type="text">
<format>{"uuid":"201456541","table": "aa/aa_table","condition":"names|91194185"}</format>
<args/>
</payloadFactory>
<send>
<endpoint>
<http method="POST" uri-template="http://192.168.1.208:8090/jobs?appName=CU&classPath=com.mymoon.ses.SparkCount"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="asdfsadf" expression="json-eval($.)"/>
</log>
<payloadFactory media-type="text">
<format>{"jobId":"$1", "table":"$2"}</format>
<args>
<arg evaluator="json" expression="$.result.jobId"/>
<arg value="test"/>
</args>
</payloadFactory>
<send/>
</outSequence>
</resource>
</api>
So I test http://192.168.1.101:8280/dd/submit . The browser shows such message.
{
"status": "STARTED",
"result": {
"jobId": "548e9590-e442-439f-9234-223bf5bf669e",
"context": "dd803c98-com.mymoon.ses.SparkCount"
}
}{"jobId":"548e9590-e442-439f-9234-223bf5bf669e", "table":"test"}
I hope message is this:
{"jobId":"548e9590-e442-439f-9234-223bf5bf669e", "table":"test"}
So I'm confused! Help me!Thanks!

i have tested using ESB 4.8.0. i have modified your API code as follows. I tested with mock service and its working. only change i made is change media-type json from text
<api xmlns="http://ws.apache.org/ns/synapse" name="d" context="/dd">
<resource methods="GET" uri-template="/submit">
<inSequence>
<log level="full"></log>
<payloadFactory media-type="json">
<format>{"uuid":"201456541", "table": "aa/aa_table", "condition":"names|91194185" }</format>
<args></args>
</payloadFactory>
<send>
<endpoint>
<http method="post" uri-template="http://demo2965385.mockable.io/test"></http>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full">
<property name="asdfsadf" expression="json-eval($.)"></property>
</log>
<payloadFactory media-type="json">
<format>{"jobId":"$1", "table":"$2"}</format>
<args>
<arg evaluator="json" expression="$.result.jobId"></arg>
<arg value="test"></arg>
</args>
</payloadFactory>
<send></send>
</outSequence>
</resource>
</api>
response look as follows
{
"jobId": "3a47f931-f040-4e4a-a688-331f1918ae82",
"table": "test"
}

Related

Callout is calling a diferent endpoint

Hi i'm new in wso2 and I have 2 api's, I want to call the second one using the first, but the url that the callout mediator is using is diferente from the one I set up, resulting in error HTTPSender Unable to sendViaGet to url[http://192.168.20.1:8280/loginAPI/login/Nurse]
The code is below
Any help will be welcome
<api context="/Staff" name="StaffAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" url-mapping="/Nurse">
<inSequence>
<log level="full"/>
<callout description="" initAxis2ClientOptions="false" serviceURL="http://192.168.20.1:8280/loginAPI/login">
<source type="envelope"/>
<target key="response"/>
</callout>
<log level="custom">
<property expression="get-property('response')" name="response"/>
</log>
<send>
<endpoint key="NurseEP"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
<api context="/loginAPI" name="LoginAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/login">
<inSequence>
<payloadFactory media-type="json">
<format>{
"userName": "xxx",
"password": "xxx",
"rememberMe": true,
"fireBaseToken": "string"
}</format>
<args/>
</payloadFactory>
<cache collector="false" hashGenerator="org.wso2.carbon.mediator.cache.digest.DOMHASHGenerator" id="Token" maxMessageSize="2000" scope="per-host" timeout="5000">
<onCacheHit/>
<implementation maxSize="1000" type="memory"/>
</cache>
<send>
<endpoint key="LoginEP"/>
</send>
</inSequence>
<outSequence>
<cache collector="true" scope="per-host"/>
<send/>
</outSequence>
<faultSequence/>
</resource>
The http://192.168.20.1:8280/loginAPI/login endpoint when called on postman is valid
It seams that your serviceURL is suffixed by your api url-mapping, try to add that before callout (it has to be used in case of send mediator, not sure for callout but it looks like the same behavior) :
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

WSO2 Ei 6.1 email received as attachment

I have a service which send the email from WSo2 server. But i am getting the message content as attachment and not in body of the email.
You can define the message content for the email body using payload factory mediator as below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="mailtest"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<payloadFactory media-type="xml">
<format>
<test xmlns="">$1</test>
</format>
<args>
<arg xmlns:ax21="http://services.samples/xsd"
xmlns:ns="http://services.samples"
evaluator="xml"
expression="//ns:getQuoteResponse/ns:return/ax21:name"/>
</args>
</payloadFactory>
<property name="Subject" scope="transport" value="Sample Mail"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="text/plain"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="mailto:yourmail#gmail.com"/>
</endpoint>
</send>
</outSequence>
</target>
<description/>
</proxy>
If you want to define a message body with the email attachment, use "transport.mail.bodyWhenAttached" property.

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>

Set Custom Payload in wso2 ESB or AM?

I have a rest API in ESB server.I need to set payload as follows
<fields>Name</fields>
<query>
<term>
<NUM>100</NUM>
</term>
</query>
any suggestion ?
you could use the payloadfactory mediator in ESB 4.8.1, take this xml as an example. you need to do some changes :-) but it´s an start:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JsonToXMLProxy"
transports="https http local"
startOnLoad="true"
trace="disable">
<description/>
<target>
<endpoint>
<address uri="http://www.w3schools.com/webservices/tempconvert.asmx" format="soap11"/>
</endpoint>
<inSequence>
<log>
<property name="TEMPERATURA_ENTRADA" expression="json-eval($.celsius)"/>
</log>
<payloadFactory media-type="xml">
<format>
<web:CelsiusToFahrenheit xmlns:web="http://www.w3schools.com/webservices/">
<web:Celsius>$1</web:Celsius>
</web:CelsiusToFahrenheit>
</format>
<args>
<arg evaluator="json" expression="$.celsius"/>
</args>
</payloadFactory>
<header name="Action"
value="http://www.w3schools.com/webservices/CelsiusToFahrenheit"/>
</inSequence>
<outSequence>
<log>
<property xmlns:p="http://www.w3schools.com/webservices/"
name="TEMPERATURA_SALIDA"
expression="//p:CelsiusToFahrenheitResponse/p:CelsiusToFahrenheitResult"/>
</log>
<payloadFactory media-type="json">
<format>
"Temperatura" : {
"EnFahrenheit" : $1
}
</format>
<args>
<arg xmlns:p="http://www.w3schools.com/webservices/"
evaluator="xml"
expression="//p:CelsiusToFahrenheitResponse/p:CelsiusToFahrenheitResult"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</target>
</proxy>
Try payload/enrich mediators ..

How to Know the URL of Client In wso2 esb for Filter

i am doing filter based on the URL so i wish to know the FROM which service i am getting request .Means i wish to know the URL of Client
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Emp" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<payloadFactory>
<format>
<send xmlns="">
<username>$1</username>
<password>$2</password>
</send>
</format>
<args>
<arg expression="get-property('username')"/>
<arg expression="get-property('password')"/>
</args>
</payloadFactory>
<send receive="Emp_Seq">
<endpoint>
<address uri="http://192.168.1.65:8282/services/Login"/>
</endpoint>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
URL of above Proxy is http://192.168.1.65:8282/services/Emp
my second proxy is which will do some logic based on first proxy
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Login" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="client_ip_address" expression="get-property('axis2','REMOTE_ADDR')" scope="default" type="STRING"/>
<property name="username" expression="//username/text()" scope="default" type="STRING"/>
<property name="password" expression="//password/text()" scope="default" type="STRING"/>
<property name="From" expression="get-property('From')"/>
<property name="Address" expression="get-property('To')"/>
<filter xmlns:ns="http://org.apache.synapse/xsd" xpath="get-property('From')='/services/Emp'">
<then>
<payloadFactory>
<format>
<ResponseJSON xmlns="">
<Status>404</Status>
<Exception>Not Found</Exception>
<Total>0</Total>
</ResponseJSON>
</format>
</payloadFactory>
<send/>
</then>
<else>
<payloadFactory>
<format>
<p:login xmlns:p="http://authentication.services.core.carbon.wso2.org">
<p:username>$1</p:username>
<p:password>$2</p:password>
<p:remoteAddress>$3</p:remoteAddress>
</p:login>
</format>
<args>
<arg expression="//username/text()"/>
<arg expression="//password/text()"/>
<arg expression="get-property('client_ip_address')"/>
</args>
</payloadFactory>
<header name="Action" value="urn:login"/>
<log level="full"/>
<send receive="Login_Seq">
<endpoint>
<address uri="https://192.168.1.65:9443/services/AuthenticationAdmin" format="soap11"/>
</endpoint>
</send>
</filter>
</inSequence>
<outSequence>
<log level="full"/>
</outSequence>
</target>
<description></description>
</proxy>
The issue is get-property('To') is giving Address=/services/Login where as get-property('From') is giving senderAddress=null
How can i manage this i trie d with lot of propertys even though its not working
like
<property name="senderAddress" expression="get-property('transport', 'From')"/>
<property name="Sender Address" expression="$url:From"/>
<header name="From" expression="get-property( 'From')"/>
<property name="PRESERVE_WS_ADDRESSING" value="true"/>
<property xmlns:wsa="http://www.w3.org/2005/08/addressing" name="$header" expression="$header/wsa:From"/>
This propertys also not working we don't have any option in wso2 esb If you know this please edit my proxy roughly ..its simple depanding logic but it is not working in WSO2
thanks in advance
You should be able to get the client's address with the REMOTE_HOST or REMOTE_ADDR properties. Please refer http://wso2.org/project/esb/java/4.0.3/docs/properties_guide.html#http