WSO2 EI 6.1.1 post request body not send - wso2

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);

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

Add query params dynamically at endpoint API WSO2 ESB

I'm trying to edit an api resource in WSO2 ESB to put query params dinamically in the end of endpoint URL.
At this moment, the resource is like this:
<resource methods="GET" uri-template="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs/searchEngine/sortAndFilterBeneficiaries?criterioOrdenacion={query.param.criterioOrdenacion}&registrosPorPagina={query.param.registrosPorPagina}&numPagina={query.param.numPagina}&userId={query.param.userId}&serviciosSeleccionados={query.param.serviciosSeleccionados}&fechaRequerida={query.param.fechaRequerida}&limiteInfDias={query.param.limiteInfDias}&limiteSupDias={query.param.limiteSupDias}&ubicacion={query.param.ubicacion}&limiteDistancia={query.param.limiteDistancia}&valoraciones={query.param.valoraciones}&competencias={query.param.competencias}"/>
</endpoint>
</send>
</inSequence>
But, I'm doing this:
<resource methods="GET" url-mapping="/searchEngine/sortAndFilterBeneficiaries*">
<inSequence>
<filter source="$ctx:query.param.criterioOrdenacion" regex="PRODUCTION">
<then>
<property name="REST_URL_POSTFIX" expression="fn:concat(get-property('axis2','REST_URL_POSTFIX'), '&criterioOrdenacion={query.param.type}')" scope="axis2" type="STRING"/>
</then>
</filter>
<log level="custom">
<property name="Access token value" expression="$trp:Authorization"/>
</log>
<oauthService remoteServiceUrl="https://server:port/services/" username="admin#wso2.com" password="admin"/>
<header name="Authorization" scope="transport" action="remove"/>
<send>
<endpoint>
<http method="get"
uri-template="http://server:port/project-web-services/services/project-rs"/>
</endpoint>
</send>
</inSequence>
Is this correct?
This is correct. When you want to change base path only one endpoint will be affected, but in first case you must update all dynamic endpoint.

Can we Set a Send mediator with Xpath expression

i am trying to send a message to my email for that i am using send mediator as well i setup required configurations in AXIS2 file
is it work for below proxy
if not what is the way to give xpath to send mediator
<proxy xmlns="http://ws.apache.org/ns/synapse" name="mailCheck" transports="http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
<property name="messageType" value="text/html" scope="axis2" type="STRING"/>
<property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
<property name="Mail" value="mailto:faisal.shaik#youtility.in" scope="default" type="STRING"/>
<log level="full">
<property name="Mail" value="mailto:faisal.shaik#youtility.in"/>
</log>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint key-expression="get-property('Mail')"/>
</send>
</inSequence>
<outSequence/>
</target>
<description></description>
</proxy>
if need any changes pls let me know
if you want to get the email address from a property value then use the header mediator to set value of "To" to "mailto:faisal.shaik#youtility.in".
You can do that adding the following before the send mediator
<header name="To" expression="fn:concat('mailto:', get-property('Mail'))"/>
You can use this:
<property name="To" expression="get-property('uri.var.to')" scope="transport"/>
<send>
<endpoint>
<address uri="mailto:"/>
</endpoint>
</send>
<send>
<address uri="mailto:xxx#yyy"/>
</send>
key-expression also can be used..

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

How can I retrieve HTTP status returned by REST service in WSO2 ESB?

My Proxy Service deployed on ESB is calling another standalone REST service. This service returns HTTP status 200 along with some data in the response body. My question is how I can retrieve HTTP status from response. Here is my configuration:
<proxy name="CQProxy"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<switch source="get-property('Action')">
<case regex="getTaskTicket">
<sequence key="GetTaskTicket"/>
</case>
<default/>
</switch>
</inSequence>
<outSequence>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="Status"
expression="get-property('HTTP_SC')"/>
</log>
<send/>
</outSequence>
<faultSequence/>
</target>
<publishWSDL key="gov:/services/cqproxy/CQProxy.wsdl">
<resource location="CQProxy.xsd" key="gov:/services/cqproxy/CQProxy.xsd"/>
</publishWSDL>
</proxy>
<sequence name="GetTaskTicket">
...
<property name="REST_URL_POSTFIX"
value="/16783484?oslc.select=dcterms:title,oslc_cm:status"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
<send>
<endpoint>
<address uri="http://.../simpleQuery"
format="rest"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
</sequence>
...
I tried the following code:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('HTTP_SC')"/>
</log>
And this one too:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2', 'HTTP_SC')"/>
</log>
But all of them returned null.
After reading WSO2 documentation in more details, I found the right answer:
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="$axis2:HTTP_SC"/>
It is weird that the documented get-property('axis2', 'HTTP_SC') does not work.
Posting the solution that worked for me:
<property scope="default" type="STRING" name="HTTP_STATUS_CODE" expression="get-property('axis2', 'HTTP_SC')"/>
<log level="custom">
<property expression="get-property('HTTP_STATUS_CODE')" name="HTTP status code received: "/>
</log>