I was about implement a workflow of a Job using many calls mediators , each one it works perfect until i put them together so it didn't work and it give me this WARN in my console
[2022-12-19 16:55:03,026] INFO {SourceHandler} - Writer null when calling informWriterError
[2022-12-19 16:55:03,027] WARN {SourceHandler} - STATE_DESCRIPTION = Socket Timeout occurred after accepting the request headers and the request body, INTERNAL_STATE = REQUEST_DONE, DIRECTION = REQUEST, CAUSE_OF_ERROR = Connection between the client and the EI timeouts, HTTP_URL = /NumSequence, HTTP_METHOD = GET, SOCKET_TIMEOUT = 180000, CLIENT_ADDRESS = /127.0.0.1:57800, CONNECTION http-incoming-3 Correlation ID : dd34a03b-a3e6-4f6a-a254-230076b41246
this is my code :
The first API execute an SQL Statement of drop
The second API execute an SQL Statement of create
The third API execute an SQL Statement select
The forth API execute an SQL Statement of update
<api context="/NumSequence" name="NumSequence" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="http://ebs-dev:8290/services/RADMINDataService/numseqdrop">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<call>
<endpoint>
<http method="get" uri-template="http://ebs-dev:8290/services/RADMINDataService/numseqcreate">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<call>
<endpoint>
<http method="get" uri-template="http://ebs-dev:8290/services/CRMDataService/ReadUsername">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<iterate expression="//accounts/account">
<target>
<sequence>
<payloadFactory media-type="json" template-type="freemarker">
<format><![CDATA[{
"_postaddusername": {
"NumSequence":${payload.account.NumSequence},
"Prefixe":"${payload.account.Prefixe}"
}
}]]></format>
<args/>
</payloadFactory>
<call>
<endpoint>
<http method="post" uri-template="http://ebs-dev:8290/services/RADMINDataService/AddUsername">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</sequence>
</target>
</iterate>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Related
I am calling an http endpoint in WsO2 Integration Studio. How can I give the address of this endpoint externally as envrionment? .Because the addresses of my endpoints are different in dev environment and live environment. I looked at the document about it. But I couldn't do it.
I want to changeable localhost:XXX address as a environment
Below is my WSO2 code:
<call>
<endpoint>
<http method="get" uri-template="http://localhost:XXX/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
You can use $SYSTEM:EP_ADDR as the uri-template and set the environment variable EP_ADDR on your environment,
<call>
<endpoint>
<http method="get" uri-template="$SYSTEM:EP_ADDR">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
The above config works in fine MI 4.1.0. If this doesn't help please specify the version you are using.
For more info: https://ei.docs.wso2.com/en/latest/micro-integrator/develop/injecting-parameters/#endpoint-parameters
To see how we can inject variables in embed runtime of Integration Studio check https://medium.com/think-integration/how-to-inject-environment-variables-to-wso2-integration-studio-runtime-83b8f0cb882e
What Sanoj mentioned is one option. Another option is to use the Property Mediator. This will allow you are dynamically constructing the URL using the Environment variable or file parameters.
<property expression="concat('https://', get-property('env', 'host'), ':', get-property('env', 'port'))" name="uri.var.ep" scope="default" type="STRING"/>
Then use it in your Endpoint configuration
<call>
<endpoint>
<http method="get" uri-template="{uri.var.ep}">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
Update
In order to add them to your runtime you need to export them as environment variables in the server runtime. If you are on a linux environment you can add them into the integrator.sh (Depending on the Product you are using this may change.) For example for the given example above you can add the following two lines.
export host=abcd.efg.com
export port=8987
We have a use case, where we have to iterate through array of json-object and call an external endpoint based on certain key value. So we have used a iterator mediator, switch mediator(to match condition) and an aggregate mediator.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/propertycheck" name="propertyCheck" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<iterate attachPath="json-eval($)" expression="json-eval($.main)" id="testingid" preservePayload="true" sequential="true">
<target>
<sequence>
<switch source="json-eval($.sub1)">
<case regex="a">
<log level="full" separator=","/>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:3000/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</case>
<case regex="b">
<log level="full" separator=","/>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:3000/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</case>
<case regex="c">
<log level="full" separator=","/>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:3000/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</case>
<default>
<log>
<property name="default" value="defaultCase"/>
</log>
<payloadFactory media-type="json">
<format>{
"sub1":"My own Response"
}</format>
<args/>
</payloadFactory>
</default>
</switch>
</sequence>
</target>
</iterate>
<log/>
<aggregate id="testingid">
<correlateOn expression="json-eval($)"/>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" expression="json-eval($)">
<log>
<property expression="json-eval($)" name="outout"/>
</log>
</onComplete>
</aggregate>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
The Above use case works fine, when an external endpoint is called and response is returned to the aggregate mediator, but we have to build the response in the default case with out calling an endpoint, How can be this achieved? As the aggregate mediator will be triggered only after it receives response from a back end service.
We have also followed the answer that was provided in the post : WSO2 ESB, Using Aggregate mediator without send/call in iterate mediator
This also does not seems to work, below is the implementation as per the post answer
<?xml version="1.0" encoding="UTF-8"?>
<api context="/propertycheck" name="propertyCheck" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<iterate attachPath="json-eval($)" expression="json-eval($.main)" id="testingid" preservePayload="true" sequential="true">
<target>
<sequence>
<switch source="json-eval($.sub1)">
<case regex="a">
<log level="full" separator=","/>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:3000/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</case>
<case regex="b">
<log level="full" separator=","/>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:3000/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</case>
<case regex="c">
<log level="full" separator=","/>
<call>
<endpoint>
<http method="post" uri-template="http://localhost:3000/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</case>
<default>
<log>
<property name="default" value="defaultCase"/>
</log>
<payloadFactory media-type="json">
<format>{
"sub1":"My own Response"
}</format>
<args/>
</payloadFactory>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<sequence key="AggregateSequence"/>
</default>
</switch>
</sequence>
</target>
</iterate>
<log/>
<aggregate id="testingid">
<correlateOn expression="json-eval($)"/>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" expression="json-eval($)">
<log>
<property expression="json-eval($)" name="outout"/>
</log>
</onComplete>
</aggregate>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
AggregateSequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="AggregateSequence" statistics="enable" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<log>
<property expression="json-eval($)" name="request to mediator"/>
</log>
<aggregate id="testingid">
<correlateOn expression="json-eval($)"/>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" expression="json-eval($)">
<log>
<property expression="json-eval($)" name="inside Aggregator"/>
</log>
</onComplete>
</aggregate>
</sequence>
Request
{
"main":[
{
"sub1":"a"
},
{
"sub1":"b"
},
{
"sub1":"c"
},
{
"sub1":"d"
}
]
}
Any help is appreciated. Thanks
Think I had exactly the same problem, when no backend is called. Not sure anymore if it was stated in the documentation, anyhow I solved it calling the local "echo" EI/ESB service" when no backend call should be done.
Here's a snippet of how I solved it.
<iterate xmlns:m0="http://ws.wso2.org/dataservice" expression="$body//m0:Entry" id="iteratorID" sequential="true">
<target>
<sequence>
<filter xpath="contains(get-property('schedulerHour'), get-property('currentHour')) and (contains($ctx:schedulerMinutes, $ctx:currentMinute))">
<then>
.... real backend should be called...
<call>
<endpoint>
<http uri-template="https://someURL"/>
</endpoint>
</call>
....
</then>
<else>
.... fake backend call...
<payloadFactory media-type="xml">
<format>
<p:echoInt xmlns:p="http://echo.services.core.carbon.wso2.org">
<in>123</in>
</p:echoInt>
</format>
<args/>
</payloadFactory>
<call>
<endpoint>
<http method="POST" uri-template="http://localhost:8280/services/echo"/>
</endpoint>
</call>
.....
</else>
</filter>
</sequence>
</target>
</iterate>
I have different services and there respective endpoints in my WSO2 DSS like
http://localhost:9764/services/Get_details/
http://localhost:9764/services/muser_DataService/
etc
so,when am creating a proxy service in WSO2 ESB i want to give a default endpoint in my proxy rather then the particular endpoint in DSS
For this approach i used Recipient List Group as shown below
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Endpoint">
<endpoint name="null_value">
<address uri="http://localhost:9764/services/null_value/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Get_details">
<address uri="http://localhost:9764/services/Get_details/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Get_geodetails">
<address uri="http://localhost:9764/services/Get_geodetails/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="muser_DataService">
<address uri="http://localhost:9764/services/muser_DataService/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
But when am using this endpoint in my proxy, process is failing to find the required endpoint in the created Recipient List Group and throwing an error as shown below
"Fault":{"faultcode":"axis2ns2:Client","faultstring":"The endpoint reference (EPR) for the Operation not found is \/services\/Get_details\/ and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.","detail":""}
What can be done for a successful execution......
Recipient endpoint is used for different purpose. You should have different endpoint definition, if your backend service URL is different. Then use proper endpoint in your proxy.
I'm using wso2esb 4.7.0 and wso2dss 3.0.0. Their are multiple services on server i wish to use load balancing endpoint.For that i went through documents.I have cleared my concept but in littlebit confusion that how to implement that in actual proxy service.I have created a load balance endpoint as :
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="TestAddressEndpoint">
<session type="http">
<sessionTimeout>0</sessionTimeout>
</session>
<loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
<endpoint name="Addressdetail_endp">
<address uri="http://localhost:9764/services/maddress_Dataservice/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Addressdetail_endp2.0">
<address uri="http://localhost:9764/services/maddress_Dataservice2.0/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Addressdetail_endp3.0">
<address uri="http://localhost:9764/services/maddress_Dataservice3.0/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
</loadbalance>
</endpoint>
Now i wanted to ask that how can i used this endpoint in actual proxy service? Should i make changes in axis2.xml file?
Have a look at this sample. Or else if you can refer to a saved endpoint as below;
<target endpoint="TestAddressEndpoint"/>
Using this is a proxy service;
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MyProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target endpoint="TestAddressEndpoint"/>
<description/>
...
</proxy>
I have a wso2 esb 4.7.0 proxy with an inline endpoint and inline configurations like suspendOnFailure ormarkForSuspension.
The <markForSuspension><errorCodes>-1 (never suspend) is very important for all my endpoints. So far I need to copy/paste the whole configuration tags for each endpoint.
How can I change the default value for markForSuspension?
Then I would not have to give the whole configuration for each endpoint anymore.
<?xml version="1.0" encoding="UTF-8"?>
<proxy>
<!-- .... -->
<send>
<endpoint>
<address uri="##To##">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
</target>
</proxy>
AFAIK, you cannot change the default values unless you modify the code (and recompile).
I would recommend you to create a template for you endpoint. See Sample 752
For example, you can try following configuration.
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="http"
statistics="enable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint name="ep_name"
template="ep_template"
uri="##To##"/>
</send>
</inSequence>
...
</target>
</proxy>
Following is the template for endpoint
<template xmlns="http://ws.apache.org/ns/synapse" name="ep_template">
<endpoint name="$name">
<address uri="$uri">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</template>
I hope this helps