I need to validate request and response in WSO2 APIM. Can someone please provide the example how to do that. I am using WSO2 with version 2.6.1
In the below JSON I need to validate the email field should have proper email address and it should not be empty.
{
"User":{
"name":"abc",
"age":"30",
"email":"abc#xyz.com"
}
}
It should give error or fault message if email is empty or not in proper.
Please provide example I went through many WSO2 documentation but could not able to find it. Thanks
You can use mediation sequences to achieve this requirement. To validate the request, upload the request for In Flow and for validating the response, upload the sequence for Out Flow.
For official documentation for writing the mediation sequences, follow [1]
For more information on how to use mediation sequences with api manager follow[2]
[1] https://docs.wso2.com/display/ESB500/Mediating+Messages
[2] https://docs.wso2.com/display/AM260/Adding+Mediation+Extensions
Related
I am new to WSO2. We are trying to implement WSO2 api manager for our project. So I have downloaded wso2 api manager 3.0 and started to explore it. In that I have seen schema validation option and then referred the documentation of it. According to that I have added schema definition in my API as per Open API specification (v3.0). But after enabling the schema definition, it doesn't seem to validate the request against the schema defined. Is there anything that I am doing wrong? Please provide any any information related to this.
JSON schema validation in WSO2 api manager 3.0 documentation:
https://apim.docs.wso2.com/en/latest/Learn/APISecurity/APIRequestResponseSchemaValidation/json-schema-validator/
If you have provided a valid request payload/parameters or if the response you get is according to the schema you have provided you won't get any special notifications to indicate that the values have passed through the schema validation. If the req/response payload does not adhere to the schema, then you will get the error message.
Did you get any error message? Also, share your OpenAPI schema definition to see whether that has some issues.
Can some one please let me know or guide me to achieve this:
I am calling one login API which returns authorization ticket. I need to capture the ticket information from the response message of first API and use it to invoke another API.
First and Second API are separate ones. First API is for login and second API is for creation of entity.
I have read through many posts and blogs but not able to proceed further and I am fairly new in WSO2. Can some one please guide me.
Thanks
You can simply achieve this by using a proxy service, mediation sequences and mediators. You will need 2 sequences which perform,
Log in, read the response and extract the token which then set to a property mediator. So that the second sequence can retrieve it.
Read the token which was set from the sequence1 and invoke the next API.
Then you can create a single proxy service in ESB, which invokes sequence 1 and 2.
Please go through the documentation[1] on Message Mediation for more detailed information on how to use different mediators.
[1] https://docs.wso2.com/display/ESB490/Mediating+Messages
Please suggest the possible techniques to validate(NULL, NOT NULL, TAG presence, length, etc.) incoming request JSON schema elements in API Manager before backend service is invoked.
Is it recommended to perform schema level validation in WSO2 API Manager?
As per my knowledge, schema validations(XML/JSON) should be done at client side before API deployed on API Manager in invoked.
Any comments would be appreciated.
Regards,
Abhishek
In order to validate the request json you can use OpenAPI validation specifications. apim facilitates you to edit the OpernAPI spec from the UI it self.
As per my knowledge you can do the validation in both places, but if you do the validation in the client it self you can prevent the API invocation to api manager.
I have been asked to test my Rest API in JMeter and configured my service details in HTTP Request tab in JMeter and unfortunately i am seeing Authentication failed error even though it displays correct information in Request tab.
Here is my Header Manager section as below...
This is my request and using POST method for this.
Can you pls help in getting this fixed...
you have to implement correct correlation.
Authentication must be executed every time.
The authorization token is a random value that you get from previous authentication.
You have to extract it (maybe with a regular expression) and use it in the HTTP operation.
The recommended way of testing resources protected by Basic HTTP Authentication is using HTTP Authorization Manager.
Add HTTP Authorization Manager to your test plan
Provide Base URL and credentials (plain text)
That's it, you don't need to add Authorization header manually, JMeter will automatically generate it, check out How to Use HTTP Basic Authentication in JMeter article for more details if required.
I am facing an alarming situation with the services published in WSO2 ESB. In an absolutely random way, some services fail the response message validation, in spite of the fact that de response is totally correct. The error deals with missed tagges in the payload. This takes place with no pattern at all. A services is working until it starts to respond a validation fault. When this occurs, I check the following:
A soapUI client can be generated by the WSDL published by the ESB, so it is not a reference issue.
Response is validated successfully by the XSD used by the validate mediator. (validated by an alternative tool).
I can even see the payload that previously is logged and it is correct. This have occured several times in different services.
The only way to fix this is undeploy the services and deploy it again. I have try the redeploy option in the service dashboard, and reset the whole system with no success.
I have a feeling that somehow the payload used by the validate mediator is a kind of locked, blank, unreachable or dirty.
How can I set the validate mediator process in debug mode? I think this might help.
Any help? I am thinking of denying using this system in a production environment.
I use wso2 esb 4.5.1.
King regards.
Put the log mediator with the log level ="full" before the validate mediator and see, what is passed to the validate mediator. This will help you to find the erroneous response..