WSO2 - value dynamically injected to the endpoint - endpoint

I am a newbie in WSO2 ESB and I am struggling with one issue related to the dynamically generated endpoint adress uris.
I followed by the tutorial how to integrate RabbitMQ with WSO2 and I created following endpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Test2">
<address trace="disable" uri="rabbitmq:/Test?rabbitmq.server.host.name=localhost&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json" />
</endpoint>
However, I wanted to inject dynamically value of rabbitmq.server.host.name, so I created a local entry, like below:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="queue.hostname" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[localhost]]></localEntry>
and injected that value to the endpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Test2">
<property expression="get-property('queue.hostname')" name="queue.hostname" scope="default" type="STRING" />
<address trace="disable" uri="rabbitmq:/Test?rabbitmq.server.host.name={queue.hostname}&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json" />
</endpoint>
During tests, I discovered that property queue.hostname value in not correctly injected to the URI and URI is:
rabbitmq:/Test?rabbitmq.server.host.name={queue.hostname}&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json
instead of:
rabbitmq:/Test?rabbitmq.server.host.name=localhost&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json
Do you know what I am doing wrong?
I will apreciate any example codes.
Thank you in advance!

As you take values from property mediator, it can't assign in the middle of URI as it does not take parameter values. So you have to use endpoint templates for that.
Sample scenario:
<template xmlns="http://ws.apache.org/ns/synapse" name="TM_out_endpoint_template">
<axis2ns158:parameter xmlns:axis2ns158="http://ws.apache.org/ns/synapse" name="host"> </axis2ns158:parameter>
<endpoint name="$name">
<address uri="jms:/MyQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://$host:61616&transport.jms.DestinationType=queue">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
</template>
Use that according to your scenario. Reference: https://docs.wso2.com/display/ESB490/Endpoint+Template

Related

WSO2: Can't find endpoint, error code 305100, error message: "Couldn't find the endpoint with the key"

I'm trying to call an endpoint from a sequence using WSO2 Integration Studios. Whenever I define the endpoint in-line, my code works fine and I get a response from the endpoint. Whenever I define the endpoint as a separate entity, it stops working and I get the following error-message: "MESSAGE = An unexpected error occurred., REST_API = null, ERROR_CODE = 305100, ERROR_MESSAGE = Couldn't find the endpoint with the key..."
My code looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XMLSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log category="TRACE" description="Log Request Payload"/>
<call description="Send request to the endpoint">
<endpoint key="TestEndpoint" />
</call>
</sequence>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="TestEndpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="https://[api]">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
For reference, my code does work when it looks like this:
`<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XMLSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log category="TRACE" description="Log Request Payload"/>
<call description="Send request to the endpoint">
<endpoint name="TestEndpoint" xmlns="http://ws.apache.org/ns/synapse">
` <http method="get" uri-template="https://[api]">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</sequence>
This "Couldn't find the endpoint with the key.." error occurred when EI/ESB cannot find the endpoint configuration in the synapse configuration space.
Check whether you have added it to the composite application project when bundling all the synapse xml artefacts to the .car file.

WSO2 Micro Integrator throws an error when content type is application/ld+json

I want to call an API that I created with Integration Studio. There are headers that this API uses. API returns ld+json data.When I make a request to the API I created via Postman,gives the following error.
Unexpected character in preface '{' (code 123); expected '<' in [row,col
I added TRANSPORT_HEADERS as remove using Property Mediator. But this time, the API does not work because the Headers information is deleted. I added the following lines to the deployment.toml and axis2.xml files. But it still didn't work.
[[custom_message_builders]]
content_type = "application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"
Below is the xml file I used.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/x" name="x" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="https://json-ld.org/contexts/person.jsonld">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<script language="js"><![CDATA[var x = mc.getPayloadJSON();
if (x.id == "urn:ngsi-ld:AirQualitySensor:012")
mc.setPayloadJSON('{"s":"success"}');
else
mc.setPayloadJSON('{"s":"fail"}');]]></script>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Thank you in advance for your answers
You need to map the correct custom content type to the appropriate message builder. For example if your response content type is application/ld+json you need to add the message builder like the below.
[[custom_message_builders]]
content_type = "application/ld+json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"

ESB WSO2: I want to insert data into a database through a data service I created but I get this error

This is the error I get in the console:
[2022-02-17 08:55:40,121] ERROR {org.apache.axis2.description.ClientUtils} - The system cannot infer the transport information from the nio-local://services/my_first_project_data-services URL.
[2022-02-17 08:55:40,122] WARN {org.apache.synapse.endpoints.EndpointContext} - Endpoint : ep.insertUserAddress with address nio-local://services/my_first_project_data-services will be marked SUSPENDED as it failed
[2022-02-17 08:55:40,123] WARN {org.apache.synapse.endpoints.EndpointContext} - Suspending endpoint : ep.insertUserAddress with address nio-local://services/my_first_project_data-services - current suspend duration is : 30000ms - Next retry after : Thu Feb 17 08:56:10 EET 2022
[2022-02-17 08:55:40,125] WARN {org.apache.synapse.transport.passthru.util.PassThroughTransportUtils} - Unable to set the HTTP status code from the property HTTP_SC with value:
This is my API source code:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api/dbtask/insert" name="api.dbtask.insert" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<call blocking="true">
<endpoint key="ep.insertUserAddress"/>
</call>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
This is my endpoint source code:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="ep.insertUserAddress" xmlns="http://ws.apache.org/ns/synapse">
<address uri="nio-local://services/my_first_project_data-services">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</address>
</endpoint>
This is my dataservice source code:
<data name="my_first_project_data-services" serviceNamespace="" serviceGroup="" transports="http https">
<description/>
<config id="default">
<property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/utilizatori</property>
<property name="org.wso2.ws.dataservice.user">root</property>
<property name="org.wso2.ws.dataservice.password">1234</property>
</config>
<operation name="insertUser" returnRequestStatus="true">
<call-query href="insertUser"/>
</operation>
<query id="insertUser" useConfig="default">
<sql>INSERT INTO utilizatori.users (id, nume, varsta) VALUES (14, "Alexandru", 50)</sql>
</query>
</data>
The thing is when I'm trying the service here, it works:
I'm using Postman to send requests
What am I doing wrong?
There is an issue with the data service URL you have configured "nio-local://services/my_first_project_data-services". The format of the data service endpoint should look like follows [1].
http://localhost:8280/services/RDBMSDataService/employee
But if your intention is to use the local transport, you first need to enable the local transport. You can find more information on this in the blog post [2].
[1]-https://docs.wso2.com/display/EI660/Exposing+a+Datasource+as+a+Data+Service
[2]-https://mcvidanagama.medium.com/install-dss-features-to-esb-and-enable-local-transport-for-data-service-endpoints-f4866495a8d7

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.

WSO2 ESB reliable messaging

I have tried this sample "https://docs.wso2.com/display/ESB470/Sample+102%3A+Reliable+Message+Exchange+with+Back-End+Server+Using+WS-ReliableMessaging+1.1", and unfortunaly I couldn't understand the config explained in this sample. the config is:
<definitions xmlns="http://ws.apache.org/ns/synapse">
<in>
<RMSequence single="true" version="1.1"/>
<send>
<endpoint name="reliable">
<address uri="http://localhost:9000/services/ReliableStockQuoteService">
<enableRM/>
<enableAddressing/>
</address>
</endpoint>
</send>
</in>
<out>
<header name="wsrm:SequenceAcknowledgement" action="remove"
xmlns:wsrm="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
<header name="wsrm:Sequence" action="remove"
xmlns:wsrm="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
<header name="wsrm:AckRequested" action="remove"
xmlns:wsrm="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
<send/>
</out>
There is no place that explain where to use this config. What is the definitions tag? What are in and out tags?
I have tried this proxy service to invoke a reliabl-messaging enabled backend.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="reliableClient"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<RMSequence single="true" version="1.0"/>
<send>
<endpoint>
<wsdl service="reliableBackEnd"
port="reliableBackEndHttpSoap11Endpoint"
uri="http://localhost:9763/services/reliableBackEnd?wsdl">
<enableAddressing/>
<enableRM/>
</wsdl>
</endpoint>
</send>
</inSequence>
<outSequence>
<header xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"
name="wsrm:SequenceAcknowledgement"
action="remove"/>
<header xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"
name="wsrm:Sequence"
action="remove"/>
<header xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"
name="wsrm:AckRequested"
action="remove"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
but it is getting time out. the backed is hosting in the same ESB 4.8.1, with default RM-Policy enabled.
#Reza,
definitions tag is the root tag of the ESB synapse config. Under the definitions tag, all the synapse artifact related configs such as proxy services, sequences, and etc are included.
Also regarding the sample you are referring,you are referring to an older version of 4.7.0 and make sure you have enabled nhttp transport. Instead of using the older version, I would like to suggest you use a newer version. Please refer [1], a nice article written by Buddhima.
[a] https://buddhimawijeweera.wordpress.com/2015/09/05/reliable-messaging-with-wso2-esb/