wso2 using clone and aggregate with datamapper - wso2

So I am using Clone Mediator and Aggregate Mediator to get the two(2) response from the API in a single request. But the problem is that the first request returns an error from DataMapper Mediator (http://pastebin.com/7P43ZbAa) and the second request returned my expected response (http://pastebin.com/2WbCvi9z) without any errors.
Here's my api config
http://pastebin.com/2ytGEkFk

Related

Custom error messages and HTTP return codes in WSO2DSS

I am using Wso2 DSS and building RESTful webservices from an oracle DB and trying to return custom error messages in case no records found or invoked using invalid parameters.
And I also want to control the HTTP return code for these error responses.
For example. Lets say there is a webservice: /getemployee/{empno} that returns employee details in JSON/XML format.
If I call getemployee with an empno that doesn't exists in the DB then
I want the response to be like something similar to below
<Error>
<Error_code>No employee found </Error_code>
</Error>
It should not have the normal employee details message structure that would go as response when an employee is found.
At the moment if record is not found by the underlying query DSS just returns empty message with just root element.
The HTTP return code for this response should be 404 as opposed to the success code 200.
By default all responses get HTTP return code 200 in DSS.
Is this possible at all just by using DSS?
Appreciate your help
You would need WSO2 ESB to do that. You can make a proxy service in ESB that will call DSS and then transform the response for you based on its contents and your needs. You can do so using XSLT.
You can set manually the desired HTTP return code, using the property HTTP_SC:
<property name="HTTP_SC" scope="axis2" type="STRING" value="404"/>
You can also use switch and payload factory, if you know what you will receive and the output will be a static one.

WSO2ESB 4.9.0 - OUT_ONLY not working for JMS endpoint

As per the documentation ESB as a JMS Producer setting OUT_ONLY should make the send mediator async. But instead I get timeout error as its waiting on response. What I found from various blogs is adding FORCE_SC_ACCEPTED would make it async. But in this case the proxy will respond at the send mediator. I do not want that, I want it to go to out sequence where I can generate a proper response message. Any help appreciated.
Use clone mediator :
in the 1st target, define OUT_ONLY property and use send mediator to send your message to a JMS queue
in the 2nd target, create a response message and use respond mediator

WSO2 API Message Mediation based on accept headers

I am using WSO2 Api Manager as a proxy between a client and the server. The server sends XML responses that I successfully converted to a JSON response with a custom PayloadFactory message mediation. Problem that I now am facing is the following: How do I mediate based on the accept headers of a request?
When I have in the header of a request:
Accept application/json
I want to use my mediator to convert the response from the server to JSON, but when I have
Accept text/xml or application/xml
I don't want to use my mediator and just forward the response as is.
Edit:
Basicly the only thing a really need is to save my "Accept ... " header. I can forward it to the server, but the server doesn't do anything with it. Are there global variables or something that I can use per proxy request?
Any advice will be appreciated.
You can use Filter mediator or Switch mediator to do a if-then-else kind of operations inside the insequence and implement your first requirement. You can get the header using synapse xpath variables.
You can define a custom sequence and add it to the api
for the second question, you can use property mediator to define values and use them later. set the 'Scope' parameter according to your need

BPEL:Unable to invoke endpoint uri : 415 unsupported media type

I'm trying to invoke a HTTP Binding with POST where the endpoint is a RESTFUL webservice that takes in an XML message and sends an email.
I'm using JDeveloper 11g to create the composite where it'll have an exposed HTTP Binding POST and an external reference which is also a HTTP Binding POST that calls a RESTFUL Webservice endpoint . In the BPEL process, i'm just doing a simple receive from the exposed HTTP Binding and then using the input to invoke the External References HTTP Binding. However, I'm always getting an error at the invoke phase :
oracle.fabric.common.FabricInvocationException: Unable to invoke
endpoint URI successfully due to: javax.xml.soap.SOAPException:
javax.xml.soap.SOAPException: Bad response: 415 Unsupported Media Type
from url
Unable to invoke endpoint URI successfully due to:
javax.xml.soap.SOAPException: javax.xml.soap.SOAPException: Bad
response: 415 Unsupported Media Type from url
I'm guessing that it's because my payload is lacking the MIME header content-type : application/xml. The webservice endpoint itself is working fine as I'm able to test it through other means such as POSTMan and soapUI.
Is there a way to set the HTTP header content-type of the payload? Is there anyway to check or verify? Any help would be greatly appreciated.
Regards,
Mark

How to populate SOAP headers like From, ReplyTo in ESB 4.0.3

We are using WSO2 ESB 4.0.3 with Data services feature on MAC OSX 10.7.4.
I have proxy service which forwards the message to Data Service. When there is any fault in Data service the fault is returned to calling proxy service in OUTSEQUENCE. Now if there is any error I forward this to common error handler from proxy service which happens in OUTSEQUENCE. This common error handler is another proxy service only.
Now when the Error handling is completed the control returns back to original proxy service which called the error handling proxy service. But what happens is when the control returns to original proxy service from error handler it AGAIN starts executing the OUTSEQUENCE of proxy service.
So for me it is executing the OUTSEQUENCE of proxy service twice in case of fault from Data Service.
Is it standard behavior? I used to Java kind of executing where when the call from method returns it starts executing the next line. But here looks like it again starts executing the OUTSEQUENCE from beginning.
To avert executing the OUTSEQUENCE from beginning again I populate the value at "transport" scope in Error hanlder proxy which will used in filter mediator to avoid executing the logic in OUTSEQUENCE twice.
I am trying to find if there are any SOAP headers I can use instead of setting the property. I see no SOAP headers being set like "From" or "ReplyTo" and I believe message co-ordination happens with MessageId. How can we use these SOAP headers instead of property to divert the flow logic.
Please help.
thanks
Abhijit
In this case instead of using send mediator to invoke the web service you can use the call out mediator. Which makes a blocking call to error handling service and returns to the same place.
And also with esb 4.0.3 you can specify the receive sequence at the send mediator level. By default the response is received at the outsequence level.
eg. <send receive="fundTransferSequence">
<endpoint>
<address encoding="UTF-8" statistics="disable"
uri="http://10.1.23.11:8888/EgateValidWS/EgateValidWSSoapHttpPort" >
</address>
</endpoint>
</send>