AnonymousEndpoint with address {uri.var.apiurl} in WSO2 EI 6.6 - wso2

I tired to send the request to an endpoint I get the AnonymousEndpoint error and when I hit the endpoint URL with request in the postman it's working fine what should I do to fix this issue.
And I even tired the markForSuspension and suspendOnFailure configuration nothing worked as excepted.
<property name="singleQuote" scope="default" type="STRING" value="'"/>
<property description="AppConfig" expression="evaluate(fn:concat('get-property(',get-property('singleQuote'),'QRSag_iAppraisal_Config_',get-property('clientOrg'),get-property('singleQuote'),')' ))" name="AppConfig" scope="default" type="OM"/>
<property expression="$ctx:AppConfig//*[local-name()='laravel_url']/text()" name="uri.var.apiurl" scope="default" type="STRING"/>
<property expression="$ctx:AppConfig//*[local-name()='authorization']/text()" name="Authorization" scope="transport" type="STRING"/>
<!--
<log level="custom">
<property name="uri.var.apiurl ::::::::::::::::::: " expression="$ctx:uri.var.apiurl"/>
<property name="Authorization ::::::::::::::::::: " expression="$trp:Authorization"/>
</log> -->
<call description="VB iAppraisal Endpoint">
<endpoint>
<http method="post" uri-template="{uri.var.apiurl}"/>
</endpoint>
</call>
<!-- <log level="custom">
<property name="Laravel API Response ::::::::::::::::::: " expression="json-eval($.)"/>
</log> -->

Related

WSO2 File download over HTTP and save it to folder

How to create Proxy Service which is capable to download XML file from specific address and save it to the Folder?
I tried below answer : But it is not working VFS throws error :
<call>
<endpoint>
<address format="soap11"
uri="https://scsanctions.un.org/resources/xml/en/consolidated.xml"/>
</endpoint>
</call>
<property expression="fn:concat('consolidated-', get-property('SYSTEM_DATE', 'yyyy-MM-dd'),'.xml')"
name="transport.vfs.ReplyFileName"
scope="transport"/>
<log level="custom">
<property name="Step 1" value="---------Writing response to file ---------"/>
</log>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint>
<address uri="vfs:file://C:/output"/>
</endpoint>
</call>
<log level="custom">
<property name="Step 2" value="---------Service is called ---------"/>
</log>
<property expression="fn:concat('treasury-',get-property('SYSTEM_DATE', 'yyyy-MM-dd'), '.xml' )"
name="transport.vfs.ReplyFileName"
scope="transport"/>
<log level="custom">
<property name="Step 2"
value="---------sending request to treasure site ---------"/>
</log>
<call>
<endpoint>
<address format="soap11" uri="https://www.treasury.gov/ofac/downloads/sdn.xml"/>
</endpoint>
</call>
<log level="custom">
<property name="Step 2" value="---------Writing response to file ---------"/>
</log>
<property name="FORCE_SC_ACCEPTED"
scope="axis2"
type="STRING"
value="true"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<call>
<endpoint>
<address uri="vfs:file://C:/output"/>
</endpoint>
</call>
enter code here
WSO2 ESB: How to download a file over HTTP?
Im trying to calling multiple endpoint to receive response which is supposed to be saved in this folder file://C:/output
Regards

WSO2 EI 6.1.1 post request body not send

I have a problem with wso2 EI 6.1.1. I tried using call mediator to post data to an endpoint, where the data is created via class I've created.
The issue is that the body seems to be always empty. The resulted object from the class is not sent as the body.
<resource methods="POST" url-mapping="/itineraries">
<inSequence>
<property description="baseUrl" expression="get-property('boBaseUrl')" name="uri.var.boBaseUrl" scope="default" type="STRING"/>
<property description="InsiteoClientId" expression="get-property('InsiteoClientID')" name="clientID" scope="default" type="STRING"/>
<property description="appVersion" expression="$trp:X-app-version" name="appVersion" scope="default" type="STRING"/>
<property description="buildingId" expression="$trp:X-current-building-id" name="uri.var.buildingId" scope="default" type="STRING"/>
<property description="wayPoints" expression="json-eval($.)" name="wayPoints" scope="default" type="STRING"/>
<call>
<endpoint>
<http method="get" uri-template="{uri.var.boBaseUrl}/api/v1/buildings/{uri.var.buildingId}"/>
</endpoint>
</call>
<property description="floors" expression="json-eval($.floors)" name="floors" scope="default" type="STRING"/>
<property description="InsiteoSiteId" expression="json-eval($.information.insiteoIDSite)" name="uri.var.insiteoSiteId" scope="default" type="STRING"/>
<class description="ItineraryClass" name="com.capgemini.smartWorkPlace.Itinerary"/>
<log level="full"/>
<header expression="get-property('InsiteoApiKey')" name="Authorization" scope="transport"/>
<call>
<endpoint>
<http method="post" uri-template="http://services.test.insiteo.com/APIV3/{uri.var.insiteoSiteId}/iti/process"/>
</endpoint>
</call>
<log level="full"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
The request status code returns 500 as if no body was ever sent.
I would really appreciate some help.
In your class mediator check if you're setting the created payload to the context body. If its json,
JsonUtil.getNewJsonPayload(axis2MessageContext, jsonPayload.toString(), true, true);

Sending to dynamic address endpoint

How can one send an email to a dynamic address?
Address endpoint's URI seem to be static.
Is there a way to inject a property in a address endpoint ?
Here is what I have so far :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="email" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mail'))" name="mail"/>
</log>
<property name="messageType" value="text/html" scope="axis2"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="Subject" value="File Received" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint name="mail2user">
<address uri="mailto:username#gmail.com"/>
</endpoint>
</send>
</sequence>
Thanks.
Define header "To" and use send without endpoint :
<header name="To"expression="fn:concat('mailto:', get-property('senderAddress'))"/>
<property name="OUT_ONLY" value="true"/>
<send/>
Don't forget to define transportSender "mailto" with class "org.apache.axis2.transport.mail.MailTransportSender" in axis2.xml
Here is the final code after jean-michel suggestion :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sendMail" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="//email" name="mailto" scope="default" type="STRING"/>
<log level="custom">
<property expression="fn:concat('Sending mail to - ',get-property('mailto'))" name="mail"/>
</log>
<property name="messageType" scope="axis2" type="STRING" value="text/html"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/html"/>
<property name="Subject" scope="transport" type="STRING" value="File Received"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<header expression="fn:concat('mailto:', get-property('mailto'))" name="To" scope="default"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<send/>
</sequence>

Unable to use call mediator in APIM 2.0.0

I've tried this on 1.10.0 and 2.0.0
On 1.10.0, you can disable the JMS sender in repository/conf/axis2/axis2_blocking_client.xml and use the call mediator in blocking mode. This is described in this blog post: http://shenavid.blogspot.nl/2016/08/invoking-external-endpoints-using-call.html and works ok. However this method does not work in 2.0.0 even though the related issue is marked as resolved.
Has anyone else tested this on 2.0.0 already? Or found an other workaround?
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="opal_auth_and_send"
onError="gov:apimgt/customsequences/fault/json_fault.xml"
trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property description="ORG_PAYLOAD" expression="$body/child::node()"
name="ORG_PAYLOAD" scope="default" type="STRING"/>
<property description="URL_POSTFIX"
expression="get-property('axis2', 'REST_URL_POSTFIX')"
name="URL_POSTFIX" scope="default" type="STRING"/>
<property action="remove" description="Remove REST_URL_POSTFIX"
name="REST_URL_POSTFIX" scope="axis2"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<header name="Authorization" scope="transport" value="Basic xxxxxxxx"/>
<property description="set messageType" name="messageType"
scope="transport" type="STRING" value="application/json"/>
<call blocking="true" description="Get Auth token (blocking)">
<endpoint>
<http method="get" trace="enable" uri-template="https://opal-demo34.ortec-finance.com/auth/api/token"/>
</endpoint>
</call>
<property description="Get Token from Response"
expression="json-eval($.token)" name="TOKEN" scope="default" type="STRING"/>
<property action="remove" description="Remove transport headers"
name="TRANSPORT_HEADERS" scope="axis2"/>
<log description="Log auth result" level="full"/>
<property description="Restore REST_URL_POSTFIX"
expression="get-property('URL_POSTFIX')" name="REST_URL_POSTFIX"
scope="axis2" type="STRING"/>
<payloadFactory description="Restore Payload" media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('ORG_PAYLOAD')"/>
</args>
</payloadFactory>
<header expression="get-property('TOKEN')" name="Authorization" scope="transport"/>
</sequence>
Thanks,
Danny

WSO2 ESB overwrites a ContentType property

I am working on the WSO2 ESB Proxy service, which involves exposing the internal RESTful service via SOAP endpoint on the ESB.
My RESTful service requires Content-type = "application/rdf+xml". I tried setting it using all 3 properties mentioned in the documentation: messageType, ContentType and CONTENT_TYPE. However, the request Content-type still remains "application/xml".
Here is an excerpt from my sequence that calls REST service:
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="pox">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
I tested it with TCPMon and no matter what Content-type property I use, request still contains "application/xml".
Please advice.
Can you try WSO2 ESB 4.7.0 with following configuration? Note that, I have changed the address format from "pox" to "rest"
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="rest">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
These are the http headers sent now (captured from tcpmon)
PUT /record/12345 HTTP/1.1
Cookie: region1_configure_menu=none; region3_registry_menu=none; region4_monitor_menu=none; region5_tools_menu=none; JSESSIONID=54D2911FCD5559C6B2F723E7C6FA9B44; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23
Authorization: null
OSLC-Core-Version: 2.0
Content-Type: application/rdf+xml
Accept: application/rdf+xml
Transfer-Encoding: chunked
Host: www.foo.com:8080
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO
In the configuration you have attached, you have specified the format of the address uri as "pox" .
<address uri="http://my_url" format="pox">
This will be the reason that you are getting content-type as application/xml always. Please remove this attribute and try. It should be
<address uri="http://my_url">
If you still see the issue, then try to switch to the NHTTP transport as suggested by RaviU. For that, you can first backup the axis2.xml (ESB_HOME/repository/conf/axis2/axis2.xml) as axis2_back.xml and then rename the axis2_nhttp.xml file (same location) as axis2.xml.
Can you set the content type property like this;
<property name="Content-Type” value="application/rdf+xml" scope="transport"/>
Please remove other content-type properties..
If you define like this;
[1]<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[2]<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[1] for, to select messageformatter
[2]for, to select message builders
Edit;
try like this
<inSequence>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="Content-Type"
value="application/json"
scope="transport"
type="STRING"/>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:5555/com"/>
</endpoint>
</send>
Sometimes, you have to enable those message formatters in axis2.xml before using them.
Check this article out. It may help if you haven't done so yet.
http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf