1

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

Community
  • 1
  • 1
zar3bski
  • 2,773
  • 7
  • 25
  • 58

2 Answers2

0

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

Arunan Sugunakumar
  • 3,311
  • 3
  • 12
  • 20
0

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>
user666
  • 1,750
  • 3
  • 18
  • 34