Property mediator is disappearing in WSO2 EI 6.6 - wso2

I'm trying to send the token before the endpoint but it's disappearing when it's deployed in the server and I even try to the pass the token within the endpoint properties but it's not accepting and thrown error like Invalid token, please help me to sort this out.
<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">
<property name="Authorization" scope="transport" value="Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjllMDA1MGQ4ZDFlNmZlMTYzMjllMGViYTY1MmE4NDBhMTZhMDUzZjQ3MWU0OTA4MmE0Y2ZkOGI2NTZhYjU3N2NkMmEwNTUxNjhkYzVhMjRiIn0.eyJhdWQiOiI3MjUiLCJqdGkiOiI5ZTAwNTBkOGQxZTZmZTE2MzI5ZTBlYmE2NTJhODQwYTE2YTA1M2Y0NzFlNDkwODJhNGNmZDhiNjU2YWI1NzdjZDJhMDU1MTY4ZGM1YTI0YiIsImlhdCI6MTY1MDk2ODgzMiwibmJmIjoxNjUwOTY4ODMyLCJleHAiOjE2ODI1MDQ4MzIsInN1YiI6IjU3NCIsInNjb3BlcyI6W119.BUyx65owuErEmx57_N-FC4kT_QvPQ01pvof_308hjWHPbfrajajs2oGJx0hTuztQUT5xTKqMEV9pFHfdUKM93VWTBBCMFrbP9Qg03dq1Se9fbXGJ5EkmRiAy9qJ2WCiMs2sj6sN3H7_aWxn0D6u9kbfymzRUdw3pP9KT0L0hl03RRAliW0JpVv6qJgog2bvCJni_BsM5kt84dXFohbEtRqas40bYCd-VHqy-pxlVbq6-y27OF5XC-qcWRxT78iXG2P9joULCZKTHINUPigpT2h8-QA8nPakmDflEgLScG1yAKlcgDY1aVLEZYOblkMryoITQ1bfGck_jdq_hiCu5qtz1JEhTyYXpv3RxJ_8Bnp4Do_PKfMUbqxNaDbZr75sr83HTWlcsBcPYIVG3xXRAXcB4rRKB25NitdGBkg4zqcc9SiVqBgxT2FNWEjugs-tanNjcNODX_sradOQ-7RLlcTy7NRLqa3lUyNSBpow__X5DjJpGRQoym-9j3PRQGQGOQgNImuplYQ066n4W-TzradcaxLm0oCaSqlfZ9Ozn-9as5NHMdUlNYHpOb1aAi5Qxg0JtVvdSKAYiWpwmEzBAkTm3PWMRwQpXHMqGNgkpibwI3QcqY5IrPB1ZZ0xnZ-_bOHbpFLxgAMGGBRkIBVIqPmxCxqZz06TsQWGAF9cZ12c "/>
<endpoint key="iAppraisal"/>
</call>

Don't wrap <property name="" ... /> inside <call > mediator. It should be before call endpoint like below:
<property name="Authorization" scope="transport" value="Bearer eyJ0eXAiOiJK /.../ Z12c"/>
<call description="VB iAppraisal Endpoint">
<endpoint key="iAppraisal"/>
</call>
Or optionally you can put that inside Endpoint definition.

Related

Cannot send request in mediation synapse in wso2 apim

We have two ways to send requests in wso2 APIM:
1- send mediator
2- call mediator
Unfortunately, I cannot use any of these mediators!
for example this request: http://jsonplaceholder.typicode.com/posts/
I need this approach for get token from a server and then use it in payload of main request for authentication.
could anyone help me please?! :)
I didn't get any error or special log!
<log level="custom">
<property name="text" value="###############################33"/>
</log>
<call blocking="false">
<endpoint>
<http method="GET" uri-template="http://jsonplaceholder.typicode.com/posts/"/>
</endpoint>
</call>
<log level="custom">
<property name="text" value="###############################"/>
</log>
You could find related blogs "WSO2 API Manager & OAuth2 Protected Endpoint" and answer to this question
The idea is to
call the token endpoint with the appropriate grant type(usually client secret grant is used for system to system calls).
Then extract the token using the script mediator
Then use the that token to call the API attaching the token to "Authorisation Bearer:" header.
Please give this a try.
Let's use the below properties before the call mediator. If your response is not a json payload, you need to set the expected payload content type to the ContentType and messageType properties.
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<property name="ContentType" scope="axis2" value="application/json"/>
<property name="messageType" scope="axis2" value="application/json"/>
After adding the above properties into the sequence, it should look like the below.
<sequence>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<property name="ContentType" scope="axis2" value="application/json"/>
<property name="messageType" scope="axis2" value="application/json"/>
<call blocking="true">
<endpoint>
<http method="GET"
uri-template="http://www.mocky.io/v2/5c9ddf51330000b12c3f253a"/>
</endpoint>
</call>
</sequence>

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

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

WSO2 Integrator: REST API GET Request missing response body

I am using WSO2 Integrator 6.6.0 to make a blocking HTTP GET to a REST API that returns a JSON response (HTTP 200 OK).
But I never see the response body inside my sequences. I am not sure what I am doing wrong, having exhausted all available documentation and other threads.
Sequence doing the call (simplified to anonymize), which logs the response afterwards:
<!-- Remove XML body as not needed for GET request -->
<payloadFactory media-type="json">
<format></format>
<args></args>
</payloadFactory>
<header name="Accept" value="application/json" scope="transport"/>
<property name="NO_ENTITY_BODY" value="true" scope="axis2" type="BOOLEAN" />
<call blocking="true">
<endpoint>
<http method="GET" uri-template="http://my-api/order-status">
</endpoint>
</call>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<log level="full">
<property name="response-log" value="Received response"/>
<property expression="$body" name="response-body"/>
<property expression="json-eval($)" name="json-eval-body"/>
</log>
This results simply into a log line - with no response body at all!
INFO {org.apache.synapse.mediators.builtin.LogMediator} - To:
http://my-api/order-status, WSAction: urn:mediate, SOAPAction:
urn:mediate, MessageID:
ID:414d51204343494153303131202020209ca4175f28ac422e, Direction:
response, response-log = Received response, response-body =
<soapenv:Body
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"></soapenv:Body>,
json-eval-body = {}, Payload: {}
I can see the request in my API application and I can also see what it correctly returns a response body in its logs. Also, using Postman to do the same request I receive the following JSON response with 200 OK and Content-Type appication/json:
{
"order_status": "NOT_FOUND"
}
Inside WSO2 I do not see anything! I want to be able to convert the response into XML format.
What could be wrong?
Before making a REST call, it is necessary to remove the headers from the main call.
Put this snippet before the call mediator:
<property name = "FORCE_HTTP_CONTENT_LENGTH" scope = "axis2" type = "STRING" value = "true" />
<property action = "remove" name = "REST_URL_POSTFIX" scope = "axis2" />
<property action = "remove" name = "TRANSPORT_HEADERS" scope = "axis2" />
As I understand it should solve.
Can you modify the NO_ENTITY_BODY property as follows and try this mediation again.
<property name="NO_ENTITY_BODY" action="remove" scope="axis2"/>
Having simplified this configuration for this question, I had missed that having the following property set in my proxy service:
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
Means that WSO2 is ignoring the response from the API. Removing this property resolved the issue for the following config:
<header name="Accept" value="application/json" scope="transport" />
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<call blocking="true">
<endpoint key="conf:/endpoints/FX_TRADING_API_ORDERSTATUS.xml"/>
</call>

Get content of local-entry into Basic Authorization property

I am using the esb as a mediator, to translate rest to soap basically. The soap I am invoking is secure, so I need a Authorization property. I have no problem using this service:
<resource methods="GET" uri-template="/getAllZones">
<inSequence>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('user:password'))" scope="transport"></property>
<property name="DISABLE_CHUNKING" value="true" scope="axis2"></property>
<payloadFactory media-type="xml">
<format>
<zon:GetAllZones xmlns:zon="http://someUrl.xsd">
<Filter></Filter>
</zon:GetAllZones>
</format>
<args></args>
</payloadFactory>
<send>
<endpoint key="myEndpoint"></endpoint>
</send>
<log level="full"></log>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
<send></send>
</outSequence>
</resource>
But I want to store the user and password as a local entry inside ESB. I have tried this:
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode(get-property('user'):get-property('password')))" scope="transport"></property>
But it is not working. Any Ideas?
Thanks in advance
You can store your values inside the registry. Then access them using get-property with scope registry.
For example, if you have some registry resource stored in conf:/creds/user and this has properties username and password, you can access those using:
get-property('registry', 'conf:/creds/user#username') and get-property('registry', 'conf:/creds/user#password')
As an example, in order to access properties setup as follows:
You would use something like:
<inSequence>
<log level="custom">
<property name="Username" expression="get-property('registry', 'conf:/user#username')"/>
<property name="Password" expression="get-property('registry', 'conf:/user#password')"/>
<property name="Encoded" expression="fn:concat('Basic ', base64Encode(fn:concat(get-property('registry', 'conf:/user#username'), ':', get-property('registry', 'conf:/user#username'))))"/>
</log>
<respond/>
</inSequence>
But you might want to consider encrypting the password. In which case you should use the secure vault inside the ESB. You can access something in a secure vault using alias {wso2:vault-lookup('user')}.
More details in https://docs.wso2.com/display/ESB490/Working+with+Passwords.

WSO2 ESB - transform a HTTP 202 accepted response

The Endpoint_BPS_CreateCaseService/UpdateCaseService endpoints below both point to one-way BPEL services running on WSO2 BPS. WSO2 BPS returns a HTTP 202 accepted message instantly when they are invoked.
The client application that I am using will throw a fault if it does not get a valid SOAP envelope as a response so I'm going to use a proxy service in ESB to wrap around the BPEL process.
How do I use a WSO2 ESB proxy service to forward a SOAP envelope to Endpoint_BPS_* below and then return a SOAP envelope response to my client app?
I also want to execute the faultSequence "ProcessFault" if either endpoint is unavailable or times out. I previously used the OUT_ONLY to get around the response issue above but it means I can't detect endpoint problems. Unless it is possible to do both somehow?
Another thing I've tried is cloning the message but this was a bit messy.
Any help greatly appreciated
<proxy xmlns="http://ws.apache.org/ns/synapse" name="BPSProxyService" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
<target faultSequence="ProcessFault">
<inSequence>
<log level="full">
<property name="MESSAGE" value="BEGIN BPSProxyService" />
</log>
<switch source="//*[local-name()='Operation']">
<case regex="create">
<send>
<endpoint key="Endpoint_BPS_CreateCaseService" />
</send>
</case>
<case regex="update">
<send>
<endpoint key="Endpoint_BPS_UpdateCaseService" />
</send>
</case>
</switch>
</inSequence>
<outSequence>
<property name="HTTP_SC" value="200" scope="axis2" />
<class name="esb.mediators.InjectSOAPEnvelope" />
<log level="full">
<property name="MESSAGE" value="END BPSProxyService" />
</log>
<send />
<drop />
</outSequence>
</target>
<publishWSDL key="common/bpsproxyservice/bpsproxyservice.wsdl">
<resource location="schema.xsd" key="common/schema_v2.xsd" />
</publishWSDL>
</proxy>
When you receive a 'HTTP/1.1 202 Accepted' response from your backend like BPS in the outSequence of your Proxy Service, then you need the <property name="SC_ACCEPTED" value="false" scope="axis2"/> statement to modify the '202'-response into something else.
Example:
<property name="SC_ACCEPTED" value="false" scope="axis2"/>
<property name="HTTP_SC" value="200" scope="axis2"/>
<payloadFactory media-type="xml">
<format>
<response>
<result>OK</result>
</response>
</format>
<args/>
</payloadFactory>
<send/>
The response is transformed into 'HTTP/1.1 200 OK' with a response message.
Add the "FORCE_SC_ACCEPTED" parameter with the "OUT_ONLY" in the inSequence of the proxy service as follows.
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
For more information use the following article:
http://mohanadarshan.wordpress.com/2013/05/05/out_only-scenario-in-proxy-service-wso2-esb/