Eclipse removes drop mediator after send - wso2

I tried to implement a validation with FAULT in it something like this
<on-fail>
<makefault version="soap11">
<code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
<reason value="Invalid Request!!!"/>
<role/>
</makefault>
<log level="full"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<send/>
<drop/>
</on-fail>
therefore I added DROP after SEND what function just as I wanted (without DROP I just recived FAULT message but the process did not stop what resulted into invoking some End points with incorrect inputs)
Then I needed to check on something and I open the same sequence in Eclipse and discovered that DROP got removed.
I tried to drag and drop DROP but got an error message that the SEND mediator cannot be followed by another mediator.
why?
do you happen to know a better way how to implement SEND + DROP so there is not a risk that I lose this when I open it in Eclipse?
thx a lot!

You do not need to add a Drop Mediator after a Send. It is invalid to add any mediators after the Send mediator, since the message context will be dropped after the send. May be instead of a SEND mediator you can try adding a Respond Mediator. Your use case is not so clear.

In Eclipse Developer Studio, we cannot specify any mediator after SEND mediator/ RESPOND mediator/ DROP mediator. This is because, ideally mediation flow should not continue after those mediators.
For your case, can you try CALL mediator[1] instead of SEND mediator followed by DROP mediator as follows
<on-fail>
<makefault version="soap11">
<code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
<reason value="Invalid Request!!!"/>
<role/>
</makefault>
<log level="full"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<call/>
<drop/>
</on-fail>
https://docs.wso2.com/display/ESB490/Call+Mediator

Related

how to force text/plain in WSO2 call to an endpoint

I have an enrich mediator in a sequence which has a value in a plain text. I have verified the value with log and ensured it is a text. But when I do the call after the enrich (see below) the API received the payload as a JSON with key always as "test": and then the plaintext value.
The API below expects any values, it just saves the body to a file. When I try to set a property before the call to state message type=text/plain it just hangs, does not do the call?
QUESTION: Does WSO2 mediator (wso2 framework) by nature expects the body to be either be JSON or XML? NOT Text/Plain allowed. If this is true, then I have to change my API to handle this issue I Think.
If someone can answer that question, I think I will know what to do. Because when I call the same API using a java class mediator with same options it works fine.
<call>
<endpoint>
<http method="POST" uri-template="http://xxxxxxx.38:8280/writefile"/>
</endpoint>
</call>
Thanks for the update. I had tried that before, when I had that the process was hanging and would not call the api. Here is what we did for it to work:
<payloadFactory media-type="xml">
<format>
<text xmlns="http://ws.apache.org/commons/ns/payload">$1</text>
</format>
<args>
<arg evaluator="xml" expression="get-property('fileContent')"/>
</args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/plain"/>
Thanks for the update folks. First time asking a questions and good to see getting response ASAP. Will try to contribute my learning and try to help .
Add this before the call mediator.
<property name="messageType" value="text/plain" scope="axis2"/>

How to retrieve HTTP REST METHOD of current service at Run time in WSO2 AM Sequence?

How to retrieve HTTP REST METHOD(GET,PUT,POST,DELETE,OPTIONS) in WSO2 Api Manager's Sequence at runtime? I tried to $ctx:REST_METHOD which returns 'null' value.
<sequence name="ec_rest_dynamic_ep" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="$ctx:REST_METHOD" name="restmethod"
scope="default" type="STRING"/>
<log>
<property expression="get-property('restmethod')" name="*******************REST_METHOD***********"/>
</log>
</sequence>
Basically, HTTP REST METHOD value of current service & URL context of that service needed to identify the service in order redirect the service to its endpoint dynamically at runtime.
Try the following property.
<property name="Http_Method" expression="get-property('axis2', 'HTTP_METHOD')"/>
You can find more useful properties in [1].
#Pubci's answer is correct. Here is another way.
<property name="Method" scope="transport" expression="$ctx:api.ut.HTTP_METHOD"/>
Some other properties can be found here.

Passing along application information from WSO2 APIM to specific API's

I'm looking for a way to communicate the user and the subscribed application name from the WSO2 API Manager to specific API's. I already found documentation on using JWT for this, but that would imply that all connected API's get this information, something that is not desirable in our scenario.
Can the same be accomplished using some sort of mediation sequence? I can't find any proper documentation on what parameters and fields are available there.
Thanks in advance.
Yes you can write a custom mediation sequence like this.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--Temp:v1.0.0--In">
<property name="UserName" scope="transport" expression="$ctx:api.ut.userName"/>
<property name="AppName" scope="transport" expression="$ctx:api.ut.application.name"/>
<log level="custom">
<property name="User" expression="$trp:UserName"/>
<property name="App" expression="$trp:AppName"/>
</log>
</sequence>
Here I'm creating 2 transport headers with user name and app name.

WSO2 API manager prototype API HTTP response status

I am using the inline javascript prototype feature in the WSO2 API manager and I'm trying to set different HTTP response statuses. Is this possible? If so how is it done?
So far I have tried setting the HTTP_SC property but this doesn't seem to have any effect.
mc.setProperty('HTTP_SC', "404");
I had the same requirement and after much exploring under the hood was able to find a workable solution.
The reason why setting the property:
mc.setProperty('HTTP_SC', "404");
didn't work is that the property needs to be set in the axis2 scope (as Abimaran said). mc.setProperty doesn't set it on that scope. Moreover, the MessageContext object doesn't provide a way to set the scope.
The 'Deploy as Prototype' action actually creates the API definition file by merging the specified in-line script into the a velocity template and storing the resulting API definition into a file.
Template: ./repository/resources/api_templates/prototype_template.xml
Output location: repository/deployment/server/synapse-configs/default/api/
The output file will have a name in the format:
provider--API Name-vVERSION.xml
where provider appears to be the username of the API creator.
What I did was add a filter to the template:
<filter source="boolean(get-property('HTTP_SC'))" regex="false">
<then>
<property name="HTTP_SC" value="200" scope="axis2"/>
</then>
<else>
<property name="HTTP_SC" expression="get-property('HTTP_SC')" scope="axis2"/>
</else>
</filter>
I added it immediately after a similar block (for handling CONTENT_TYPE) at the start of the inSequence element.
You need to add following properties before <send/> mediator
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="HTTP_SC" value="403" scope="axis2"/>

Sending custom response from ESB

I have a string in a custom mediator in the inSequence . I want this string to be the final response from the esb . I want to sent this string back to the client as response.How can i do this?
After adding what ever the string you have inside the custom mediator you can send the current payload back to the client using the following config.
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<send/>