How to inject http endpoint adresses as a environment in WSO2? - wso2

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

Related

How to call many Endpoint successively in WSO2 Integration Studio?

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>

Use variables for URI in WSDL mediators WSO2

I am re-factorizing a wso2 project and I wondered how/whether I could do the following. This project is designed to send data to a SOAP Api. In every environment, this API exposes a .wsdl file and the URL and credentials are the only things changing from one environment to another. The most natural thing to do is thus to
create those in the Registry and
load it in the beginning of the job like so
<propertyGroup>
<property expression="get-property('registry', 'gov:/endpoints/sap_constructionSiteUser')" name="sap_constructionSiteUser" scope="default" type="STRING"/>
<property expression="get-property('registry', 'gov:/endpoints/sap_constructionSitePassword')" name="sap_constructionSitePassword" scope="default" type="STRING"/>
<property expression="get-property('registry', 'gov:/endpoints/sap_constructionSiteUrl')" name="uri.var.sap_constructionSiteUrl" scope="default" type="STRING"/>
</propertyGroup>
But I could not find a straightforward way to use this uri.var.sap_constructionSiteUrl in the endpoint definition. The following does not work
<call>
<endpoint>
<wsdl optimize="mtom" uri="{uri.var.sap_constructionSiteUrl}" port="OUVERTURE_CHANTIER" service="OUVERTURE_CHANTIER" statistics="enable">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</wsdl>
</endpoint>
</call>
Looks like uri= only accept plain value. Is there a way I could made this dynamic without writing the entire endpoint in the Registry (the point is to keep things simple for the clients)
[Environment]
wso2ei 6.5.0
====================EDIT========================
I just created a template:
<template name="crm4sap-constructionSiteTemplate" xmlns="http://ws.apache.org/ns/synapse">
<axis2ns488:parameter name="port" xmlns:axis2ns488="http://ws.apache.org/ns/synapse"/>
<axis2ns489:parameter name="service" xmlns:axis2ns489="http://ws.apache.org/ns/synapse"/>
<axis2ns490:parameter name="uri" xmlns:axis2ns490="http://ws.apache.org/ns/synapse"/>
<endpoint name="$name">
<wsdl port="$port" service="$service" uri="$uri">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</wsdl>
</endpoint>
</template>
And I call it with
<call>
<endpoint name="constructionSiteEndpoint" template="crm4sap-constructionSiteTemplate">
<axis2ns468:parameter name="port" value="OUVERTURE_CHANTIER" xmlns:axis2ns468="http://ws.apache.org/ns/synapse"/>
<axis2ns469:parameter name="service" value="OUVERTURE_CHANTIER" xmlns:axis2ns469="http://ws.apache.org/ns/synapse"/>
<axis2ns469:parameter name="uri" value="{$ctx:sap_constructionSiteUrl}" xmlns:axis2ns469="http://ws.apache.org/ns/synapse"/>
</endpoint>
</call>
Variable substitution does not seem to occur:
[2020-04-15 12:30:54,032] [] WARN - TemplateEndpointFactory Could not read the WSDL endpoint {$ctx:sap_constructionSiteUrl}
java.net.MalformedURLException: no protocol: {$ctx:sap_constructionSiteUrl}
at java.net.URL.<init>(URL.java:600)
at java.net.URL.<init>(URL.java:497)
at java.net.URL.<init>(URL.java:446)
Looks like a common problem
You can try to template this endpoint and then call the template with the parameters. You can pass dynamic values to the template in the runtime.
https://docs.wso2.com/display/EI650/Endpoint+Template
I was able to do it using the following code in the sequence:
<call-template target="template-for-calling-soap">
<with-param name="url" value="{get-property('soap-uri')}"/>
</call-template>
Where soap-uri is a local entry or a simple property, and the sequence template named template-for-calling-soap takes as parameter the url value and has the following code:
<template name="template-for-calling-soap"
xmlns="http://ws.apache.org/ns/synapse">
<parameter name="url"/>
<sequence>
<property expression="$func:url" name="uri.var" scope="default"
type="STRING"/>
<send>
<endpoint>
<address format="soap11" uri="${uri.var}"/>
</endpoint>
</send>
</sequence>
</template>

wso2 micro integrator clustering for a service - creating another question, since first one was closed for no eason

Let's say we have a micro integrator communicating with several services.
We want to be able to cluster one of the services, for example if we send two requests to a service we want each of these requests to be processed by a different node of a service, is that possible?
Services are third party REST API, we want to send requests to two different URL.
There is Load-BalanceEndPoint element in the Integration studio element, but it's not clear how it works, or even if it permit us to solve the issue above.
Could anyone help us resolve this problem/explain how we should use mentioned endpoint?
Yes, you can use Load-Balance Endpoint for your usecase. Have a look at the following sample configurations.
API configuration :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/loadbalance" name="checkLoadBalance" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<call>
<endpoint key="testLoadBalance"/>
</call>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Endpoint Configuration :
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="testLoadBalance" xmlns="http://ws.apache.org/ns/synapse">
<loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
<endpoint name="endpoint_urn_uuid_6179155B57847314A657084710149040-304004407">
<http method="GET" uri-template="http://www.mocky.io/v2/5e574b1c3000006000fd38cd">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
<endpoint name="endpoint_urn_uuid_6179155B57847314A657084710149040-304004407">
<http method="GET" uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</loadbalance>
<description/>
</endpoint>
Here I have used two different mocky endpoints. They will return {"Hello": "World"} and {"hello": "world"}.
After deploying, if I invoke checkLoadBalance API for first time, I will get response from the first endpoint. If I invoke for the second time, I will get response from the second endpoint. Here I have given the algorithm as Roundrobin. Hence it will scheduled in a RoundRobin manner.

How to create a Default Endpoint in wso2 ESB

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.

Load Balancing endpoint in wso2esb 4.7.0

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>