I have been reading this documentation more than two weeks and it is still hard to understand some concepts.
Lets consider simple case. User makes request to our API then EI must call specific endpoint depending on requests body and show response.
Now there is the main problem on getting data of HTTP request.
I know that it could be accessed via Property Mediator, but this documentation does not help to understand anything.
if user makes GET request like this:
https://my-ei-domain.com:8280/myapi/mymethod?query1=1&query2=2
How it is possible to get values of query1 and query2
If user makes POST request with urlencoded form data how to get them?
If user makes POST request with JSON body like this:
{
"var1": "one",
"var2": 2,
"var3": {
"var3_var1": "two"
}
}
How to get values of these variables?
User makes POST request with XML body:
<body>
<var1>1</var1>
<var2>2</var2>
<var3>
<var1>3</var1>
</var3>
<body>
How to get these values?
Next problem. Sometimes users will send some variables inside Headers of requests. How to get them?
These cases are not described well in documentation. Even if they are, they just scattered across multiple pages.
if user makes GET request like this... . Using as described in
documentation URL Template or URI mapping
https://docs.wso2.com/display/EI611/Working+with+APIs
If user makes POST request with urlencoded form data how to get them... There is no another way to get data as described above. Actually Content-Type is used to identify how data transfered and I think (since ESB server use apache http core lib, widely used) will able to handle param values. Anyway that is easy to reproduce. Create rest service, send urlencode request and see how it works.
If user makes POST request with JSON body like this... Rules are described in documentation how to work with json in synapse engine https://docs.wso2.com/display/ESB480/JSON+Support (paragraph Accessing content from JSON payloads)
User makes POST request with XML body: to rest service ? to webservice? Anyway, xpath is commonly used to access certain parts of xml documents. But, synapse engine has to identify that xml document is received and parse it. Engine relies on Content-Type, details in here https://docs.wso2.com/display/ESB480/Working+with+Message+Builders+and+Formatters
Next problem. Sometimes users will send some variables inside Headers of requests. How to get them? In here how to read http headers in esb
Most of answers in documentation or easy to find by in web.
Your question is quite long and I can see you are requesting tutorials on how to achieve these. I hope the following Wso2 related tutorials will help you:
Enterprise Service Integration
Service Orchestration
Restful Integration
As an example let me explain the answers to a few of your questions:
To get information from a query like the following:
http://127.0.0.1:8280/pizzashop/api/menu/pizza?val=thin&type=crust
you may use property mediators like this:
<property name="Type" expression="$ctx:query.param.type"></property>
<property name="Val" expression="$ctx:query.param.val"></property>
WSO2 uses mediators to achieve most of the tasks. For example the payloadFactory mediator can be used to process the json and xml body and transform them. To process the following json
{ "payment":
{
"amount_lkr": "175.00",
"card_no": "1234-5678-9876-5432"
}
}
we can use payloadFactory mediator as follows:
<payloadFactory media-type="json">
<format>{"purchaseInformation": {"amount": "$1","cc": "$2"}}</format>
<args>
<arg evaluator="json" expression="$.payment.amount_lkr"></arg>
<arg evaluator="json" expression="$.payment.card_no"></arg>
</args>
</payloadFactory>
Similarly this mediator and others can be used to process xml as well in a POST request.
Please learn from the tutorials. The details are too broad to be explained in a single answer
Related
Hi everyone I am new using WSO2 ESB, here is the issue I made a integration project to learn but I have not been able to read the body of my request when I try I see this warning "Json Payload is empty"
enter image description here
Here is how I am trying to read the body <filter regex="[1-9]" source="json-eval($.test)">
enter image description here
And finally here is my request, I already set the header application/json
enter image description here
If anyone could help me, I would be very grateful. Thanks in advance
The request needs to be a POST to see the payload hit the ESB.
With GET it will just do a GET request without it.
Technically you can do GET with body but it's not a very common scenario.[1]
[1]https://docs.wso2.com/display/EI611/Unusual+Scenarios+for+HTTP+Methods+in+REST#UnusualScenariosforHTTPMethodsinREST-UsingGETwithaBody
That is because the GET method in wso2 does not allow the body payload. You can read in wso2 documentation:
Typically, a GET request does not contain a body, and the ESB profile does not support these types of requests. When it receives a GET request that contains a body, it drops the message body (...)
From doc: Using GET with a Body
Additional it is not good practice to do that, refer to this question: HTTP GET with request body
So you should use POST request.
I’m stuck with trying to connect to my SOAP API. The goal is to retrieve a quote via the “Getquote” function which is available in our webservice and use that quote in an application in Bubble.is. Therefore, I want to make it work through form-data so I can reuse the keys and values in Bubble. I get a succesfull quote through the raw method. See picture
Raw method:
You can see that all my fields are in the body so with the form-data method I put all the individual fields in key and value but I get the error message you see below.
Form data method:
Can someone see what I'm doing wrong? Excuses me for I am just starting. There might be some beginner mistakes in there. Thanks for the help!
SOAP encodes messages by using XML. Form data uses a completely different encoding, which the SOAP server doesn't understand, hence the error.
Although I've never used it, there is a Chrome extension called Boomerang that supports SOAP requests, and which may suit you better.
I'm having issue with what I feel is a simple url pattern match, but seeing unexpected behavior for an API I created.
I set up the API, and when I place the "URL Pattern", I do something simple like "/player/{playerId}"
When I go to the next screen to input the endpoint information, I reference my path variable as it appears in the documentation, like http://mycoolendpoint.com/playerInfo/{uri.var.playerId}
What I end up seeing is that the entire URL pattern is being appended to my endpoint. So, in the above, instead of seeing the expected http://mycoolendpoint.com/playerInfo/111, I see coming across the wire http://mycoolendpoint.com/playerInfo/111/player/111
Am I setting up something wrong when I do this syntax that it's appending the entire URL pattern to the Sandbox and Production endpoints instead of just the value of the path variable?
API's resource is normally appended to its endpoint URL by API Manager by default So to avoid this you can follow below instructions,
Create a custom sequence with the following content and save it as a .xml file.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="TestSequence">
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
</sequence>
Now edit your API in publisher. In design view go to "Message Mediation Policies" section and Enable Message mediation. Now add a In Flow and upload the previously saved sequence.
There are 2 ways you can do this by defining your API like below.
1) Define resource like this.
playerInfo/{playerId}
and define endpoint like this.
http://mycoolendpoint.com/
Or
2) Define resource like this.
/{playerId}
and define endpoint like this.
http://mycoolendpoint.com/playerInfo/
Or you can also do this as #ycr has mentioned. If you want to do that change for all APIs without creating a custom sequence file, you can add below line inside InSequence section of <APIM_HOME>/repository/resources/api_templates/velocity_template.xml file.
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
This template is used when APIM creates synapse files of new APIs.
I am bit confused with WSO2 ESB aggregator mediator.
I need to send three messages to different systems via WebServices, but the three systems have different message formats, so i need to transform each response to canonical model before validate onComplete expression, how can i achieve this?
Thanks for your quick response!
I know that XSLT transformation is what i need to transform the response message, but the problem is i don't know where to put it. What i understand is the onComplete section needs a xpath expression from response message, but the three message have different xpath values.
for example:
Response 1:
<ns:getCustomerInfoResponse>
<ns:Status>
<ns1:Code>0</ns1:Code>
<ns1:Desc>SUCCESS</ns1:Desc>
</ns:Status>
</ns:getCustomerInfoResponse>
Response 2:
<v1:findByIdResponse>
<output>
<StatusCode>0</StatusCode>
<StatusDesc>OK</StatusDesc>
</output>
</v1:findByIdResponse>
What i need is transform two (or three) responses to unique canonical response before validate onComplete expression to something like:
<ns:response>
<status>
<code>0</code>
<desc>SUCCESS</desc>
</status>
</ns:response>
Thanks.
Thanks Ratha for your response.
Consider the following scenario:
In a bank there are three different systems: Credit System, CoreBanking System and CRM system.
I need to do something like "get all balances from all products", so, the request is the customer id, then the customer id is sent to CRM for obtaining all customer products. Depending of the product (Credit Card or Savings Account) it needs to send the customer id to Credit System or CoreBanking. Finally, each system will response and the ESB needs to response with both balances.
Hope you can help me with this use case!
Regards.
I don't think it is right to use aggregate mediator here, since you are receiving different responses from the service endpoints, which can not be correlated using xpath.
Aggregate mediator, which can be used along with clone/iterate mediators. Clone and iterate mediator is used to send same requests to multiple endpoint/such like scenarios.
My questions;
Are you sending same request to different endpoints and which are responding different type of responses? If so, it looks bit wrong, how you defined your services.
If you are sending different requests and getting different response, and want to aggregate( or create a new reponse) based on the responses which you received from your backend services, it will fall into service chaining pattern, which you can find in the ESB documentation.
Hope this is clear to you.
You can use XSLT mediator to get messages in to a unified format. please refer [1] for the XSLT mediator sample.
[1]. http://wso2.org/project/esb/java/3.0.1/docs/mediators/xslt.html
Thank You,
Dharshana.
This blog also explains your scenario with a sample...
If I understand you correctly, you want a combination of service chaining, transformation and iteration/aggregation.
So you start by sending the request to the CRM System, it will then respond with the different products, subdivided into Credit Card or Saving Account.
Then you could use two iterate mediators to split the response into the different requests for the two endpoints and collect the responses by using the aggregate or property mediator in the response sequences.
Now that you have the responses of the Credit System and CoreBanking service, you can start to transform (XSLT) and aggregate them to your response (balances).
Here you can find an example for service chaining and a bit of XSLT transformation.
Regards.
I'm trying to use REST Client for Firefox as a mock form to post multipart file data to a Spring 3-driven controller and subsequent handlers. I have our Web Services project configured such that we are able to send XML/JSON requests, which are marshaled/unmarshaled and consumed in the usual way. When I try to use the enctype="multipart/form-data" (by sending the Content-Type="multipart/form-data"), I immediately get :
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
I've been sure to include this in my rest-servlet configuration :
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000"/>
</bean>
Thinking that this was a limitation of the commons FileUpload jar version, I tried to older releases, but to no avail. Same with my REST Client, trying both this and this
My ultimate goal would be to have JAXB marshal a specified file into an object that contains a byte[] automatically. For a great reference as to what I'd like to see, this post hits exactly that, but it uses RESTEasy as the implementation, whereas I use Spring 3 (and this cannot be changed).
Ideally, POSTing this XML :
<fileUpload>
<username>user123</username>
<localFileToBeUploaded>path/to/file</localFileToBeUploaded>
</fileUpload>
Would result in an FileUpload object containing the username as a String and the file as either a byte array, InputStream, or actual File object, which gets mapped to some specific controller for handling. I'm comfortable with the XML marshaling, but I'm lost as to how to deal with the file aspect.
Is this possible or am I mixing two different paradigms? I haven't been able to come across anything like this, which leads me to believe I'm a little out in left field. Any ideas or comments would be hugely helpful. Thank you!
This will be available in REST Client 3.1 it looks like: http://code.google.com/p/rest-client/issues/detail?id=100