WSO2 ESB - how to dynamically set value to WSDL Endpoint URI using Property Meditor - variables

I have an endpoint (WSDL) with following settings:
<endpoint>
<wsdl port="portName"
service="serviceName"
uri="http://example.com/services/service1.wsdl"/>
</endpoint>
And I have a separate xml file containing my settings for those 3 attributes: uri, service, and port. I can get their value from the xml.
<property expression="get-property('registry','gov:trunk/services/Config.xml')"
name="gc" scope="default" type="OM"/>
<log level="custom">
<property expression="$ctx:gc//wsdl//uri" name="uri"/>
<property expression="$ctx:gc//wsdl//service" name="service"/>
<property expression="$ctx:gc//wsdl//port" name="port"/>
</log>
Now, my question is: how do I set those 3 values dynamically to my endpoint?
I only need this endpoint once, and there is no need to create template for this purpose, but I can't find any resource to help me do that.
Can anyone share some knowledge and experience?
Thanks

Related

Method not allowed in wso2 esb

I need to add api service using wso2 api management or wso2 ei. i have a web api with ip:port format that have response via postman but when i add web api in api manager or wso2 ei in api menu and call published api via postman i get this error
method not allowed and in log i have this error : main sequence executed for call to non-existent = /CardTransfer/
my API Source :
<api xmlns="http://ws.apache.org/ns/synapse" name="NoorService" context="/CardTransfer" version="v1" version-type="url">
<resource methods="POST">
<inSequence>
<log level="full">
<property name="befor" value="befor"/>
</log>
<send>
<endpoint>
<http uri-template="http://x.x.x.x:9110/"/>
</endpoint>
</send>
<log level="full">
<property name="after" value="after"/>
</log>
</inSequence>
<outSequence>
<send/>
</outSequence>
</resource>
</api>
The request URL for the API resource you have created is:
https://<ip>:<port>/CardTransfer
the forward slash end of the API context should be omitted.
If the API resource contains a url-mapping="/", the request URL would be:
https://<ip>:<port>/CardTransfer/

Load dynamic sequence from Registry - WSO2 ESB

I wanted to load a sequence dynmically in the API. If I create sequence is the same ESB Solution project and load, it was successfuly referred the sequence:
<property description="supplierSeq" expression="json-eval($.sequence)" name="supplierSeq" scope="default" type="STRING"/>
<sequence description="" key="{get-property('supplierSeq')}"/>
But if I tried to create the sequence in the registry resource project as mentioned here, I could not load it.
<property description="supplierSeq" expression="json-eval($.sequence)" name="supplierSeq" scope="default" type="STRING"/>
<sequence description="" key="{concat('gov:sequence/', get-property('supplierSeq'))}"/>
Please advise.
I have make the registry path within script mediator and added as a property:
payload.sequence = "gov:sequence/" + supplier + "_availability.xml";
and then referred for the sequence:
<sequence description="" key="{get-property('supplierSeq')}"/>
This worked

Unable to read HTTP headers in an API resource

I am trying to read HTTP header from inside an API that I defined in the ESB. I have tried various methods (see below) all of them print out "null" in the logs.
<log level="custom">
<property name="LOG-POSITION___________________________" value="...4"/>
<property name="AXIS2___________________________" expression="$axis2:accept"/>
<property name="AXIS2___________________________" expression="$axis2:Accept"/>
<property name="AXIS2___________________________" expression="$axis2:ACCEPT"/>
<property name="CTX___________________________" expression="$ctx:accept"/>
<property name="CTX___________________________" expression="$ctx:Accept"/>
<property name="CTX___________________________" expression="$ctx:ACCEPT"/>
<property name="TRP___________________________" expression="$trp:accept"/>
<property name="TRP___________________________" expression="$trp:Accept"/>
<property name="TRP___________________________" expression="$trp:ACCEPT"/>
</log>
I can't see why it is not working.
Here is the synapse code to read and log the content-type http header. Here $trp stands for the transport header.
<log level="custom">
<property name="Content_Type" expression="$trp:Content-Type"/>
</log>
Ref: https://docs.wso2.com/display/ESB500/Synapse+XPath+Variables
If it doesn't work, enable wire logs and post the logs in the question.
I have found an answer to this by looking through existing code, and doing a bit of trial and error.
The expression "$trp:Accept" works, but it must be used before using either a call or send mediator.
For any others experiencing this issue, move the property mediator for grabbing this to the beginning of your proxy or api and the values should come through.

WSO2 API Manager 1.10 issue

We are running into an issue where a call to a WSO2 API REST endpoint fails with a "412 Precondition Failed" when the Content-Length exceeds 1068. Just adding a space to the request (increasing size to 1069) causes this failure. This issue can also happen when content length is less than 1069, if the API is called fast enough (using SOAPUI for testing). We have a theory that the header and body are split between packets and confuses the request. We tried turning off chunking and that didn't affect things. When the back end REST service is called directly it works fine.
You can turn off the chunking as below by using the property mediator if you are calling the SOAP endpoint. But you have to make sure that the SOAP endpoint is also expecting a non-chunked request.
<property name=”DISABLE_CHUNKING” value=”true” scope=”axis2″/>
But if you are using REST endpoint above property may not work sometimes. In that kind of situation, we need to make sure the Content-Length header is appended to the request. We can use below two properties to append the Content-Length header.
<property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"></property>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"></property>
Sample proxy inSequence
<inSequence>
<log level="custom">
<property name="msg" value="Executing IN sequence"></property>
</log>
<property name="FORCE_HTTP_CONTENT_LENGTH" value="true" scope="axis2"></property>
<property name="COPY_CONTENT_LENGTH_FROM_INCOMING" value="true" scope="axis2"></property>
<send>
<endpoint>
<address uri="https://www.google.com" format="rest"></address>
</endpoint>
</send>
</inSequence>

About messageType and JIRA connector

I have two proxy services for testing purpose that connects with JIRA using JIRA Connector. First one, accepting "application/json" payload:
<proxy name="PruebaJIRA_01" startOnLoad="true" trace="disable" transports="https http">
<description/>
<target>
<inSequence>
<log level="full"/>
<jira.init>
<username>xxxxxx</username>
<password>xxxxxx</password>
<uri>http://gea-jira.its.ute.com/jiragea</uri>
</jira.init>
<property expression="json-eval($.consulta)" name="query"/>
<jira.searchJira>
<query>{$ctx:query}</query>
</jira.searchJira>
<log level="full"/>
<respond/>
</inSequence>
</target>
</proxy>
The second one, accepting "text/xml" payload:
<proxy name="PruebaJIRA_02" startOnLoad="true" trace="disable" transports="https http">
<description/>
<target>
<inSequence>
<property name="messageType" scope="axis2" value="application/json"/>
<log level="full"/>
<jira.init>
<username>xxxxxx</username>
<password>xxxxxx</password>
<uri>http://gea-jira.its.ute.com/jiragea</uri>
</jira.init>
<property expression="//root/consulta" name="query"/>
<jira.searchJira>
<query>{$ctx:query}</query>
</jira.searchJira>
<log level="full"/>
<respond/>
</inSequence>
</target>
</proxy>
It seems that JIRA connector only accept JSON incoming data, so in the second one I have a "messageType" conversion at the top of the sequence.
Both services run OK, but the question is: Why is the second proxy working if I am using an xpath expression?
I am using wso2 ESB 4.9.0.
Thanks in advance.
ESB receives disparate message formats from different clients and systems, because of this ESB required a canonical message format inside the ESB to do all the message mediation tasks. Because of this the message builder used to convert the incoming messages into a canonical format. The canonical format using inside the ESB is SOAP. So surely your XPATH expression works with the soap message.
MessageType property used to select correct message formatter and the message formatter is used to build the outgoing stream from the proxy.
More Info - demystifying-wso2-esb-pass-through-transport /
Working with Message Builders and Formatters