How to validate input and output messages in proxy service against wsdl - wso2

Is there any way to validate input and output messages in proxy service against specific wsdl?
Have a situation, when proxy generates invalid output message, so i want to catch this inside my proxy just before responding to client.
Also i want to check if input message is valid.

You can use a tool like SoapUI to validate scenario like this. You can generate a test using particular wsdl. And you can use tool like tcpmon to validate the message going between proxy and the particular endpoint.
As a example use one tcpmon listening to out port to the proxy and redirect it to the actual port.
You can find soapui from [1] and if your using wso2 ESB the tcpmon is available at /bin directory and you can start it using
sh wso2esb-4.5.0/bin/tcpmon.sh
By looking at the message passing through tcpmon you can validate the message going out from your proxy.
[1]. http://sourceforge.net/projects/loadui/files/latest/download?source=files

You can validate the payload of the wso2 esb proxy using the Validate mediator.
Example,
<validate source="//xpath_of_element_to_validate">
<schema key="local_entry_name_of_your_schema_file"/>
<on-fail>
*This part contains the code to handle validation failure*
</on-fail>
</validate>
This Validate mediator can be used anywhere in the proxy. To validate the request, use it as the first line and to validate the response, use it before the respond mediator
You can refer the below link for more details,
https://docs.wso2.com/display/ESB490/Validate+Mediator
Hope this helps!!
Thanks!!

Related

Getting Soap Fault on hitting a WebService using JMETER

I'm trying to contact a webservice via Jmeter (3.0), and I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
<s:Subcode>
<s:Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</s:Value>
</s:Subcode>
</s:Code>
<s:Reason>
<s:Text xml:lang="es-AR">The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</s:Text>
</s:Reason>
</s:Fault>
</s:Body>
</s:Envelope>
I haven't encountered any issues contacting the web service from SoapUI, so I'm wondering what could cause this problem.
You can see the screen shots here:
The HTTP Request within the tree, first part of the HTTP Request data, the HTTP Header Manager settings: https://i.stack.imgur.com/6HxIK.jpg
Here are the results on SoapUI (works just fine):
Results and log
Is it possible that the way that SoapUI sends the requests differs from the way Jmeter does and that's why it works?
Please help. Thanks!
You need to put this action bit to be a part of the Content-Type header like:
I would also recommend adding HTTP Cookie Manager to your Test Plan
Out of interest, why don't you just record the request originated from SoapUI using JMeter HTTP(S) Test Script Recorder like:
Configure JMeter for recording. The easiest way of doing this is using JMeter Templates feature
From JMeter main menu: File - Templates - Recording - Create
Workbench - HTTP(S) Test Script Recorder - Start
Configure SoapUI for recording
From SoapUI main menu: Preferences - Proxy Settings
Proxy Settting: manual, host: IP address or hostname of machine where JMeter is running, port: 8888
Execute request in SoapUI
Inspect the recorded request in JMeter under Workbench -> Recording Controller.
I think you have some trivial error in the value of http header SOAPAction.
Happened to notice(in the image you attached) that there are double quotes in its value.
Just remove the double quotes " from the SOAPAction value.
UPDATE:
It is noticed, while editing the question, that soapui has sent an additional http header action with a value (you masked the value).
So, please add action header in the jmeter request as well the right value in the jmeter plan.

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

Custom Uri or endpoint on WSO2

We have just installed our WSO2 ESB, and we are trying to create some proxies services with customs endpoints.
The default endoint format is:
http://{host}:{port}/services/{Proxy Service Name}
I'd like to have something like:
http://{host}:{port}/services/utilities/{Proxy Service Name}
http://{host}:{port}/services/public/{Proxy Service Name}
I followed this tutorial:
http://wso2.org/library/knowledge-base/2011/01/custom-urls-wso2-esb-proxy-services
but we have a problem, when I send a request to my custom endpoint, I have no answer.
suggestions?
I assume that you were able to properly create a custom endpoint and "I have no answer" means you didn't get any response. If it is the case following are the possible reasons for that,
Proxy service endpoint didn't receive the request
Proxy service didn't configured properly to response back
So test whether the 1 is the reason you can simply put a log mediator with following configuration in inSequence,
<log level="full"/>
then if the proxy service received a message it will log it in console. If that works could you please post your proxy service configuration to check whether it is properly defined.
Well, it seems that we've found a solution, I'm going to resume the full solution.
As the tutorial indicates, to costumize your proxy service endpoint, you have to add the following handler on the axis2.xml configuration:
<handler name="CustomURIBasedDispatcher" class="org.apache.synapse.core.axis2.CustomURIBasedDispatcher"/>
Then, you can customize your endpoint on the design view or on the source view, I've choosen the source view, adding this parameter:
<parameter name="ServiceURI">/services/intern</parameter>
The custom endpoint is autogenerated as:
http://{host}:{port}/services/intern.myWebservice
But I has not worked for me. If I send a request to the custom endpoint, I have no response.
I've solved the problem, adding to the "ServiceURI" parameter the name of the service:
<parameter name="ServiceURI">/services/intern/myWebService</parameter>
then you have to send the request to the following endpoint:
http://{host}:{port}/services/intern/myWebService
So now you have a custom endpoint for every proxy service.
Thanks Malith for your help.

WSO2-ESB: SOAP Mediator from wsdl

I have seen some of the SOAP- Example- Mediators. I have not found a transformation based on the endpoint-WSDL.
I want to send some nested named array in json or POX and that data should go into a complete namespaced headered (username, password) SOAP-Request based on the names.
All the examples I have found had either a very simple wsdl or the namespaces were static in the XSL-Transformation.
It should be possible to do that, as I see in for example php-NuSOAP. You feed it with a wsdl-endpoint, the operation you want to execute and the parameter-array, and it calls the Webservice.
I am looking for a solution which is not too much hardcoded for every single service, so the proxy still works when the wsdl changes and Server Clients get changed.
As far as I understand the payload factory mediator in (https://stackoverflow.com/a/12969814/2277620) you would have to hardcode the soap-format in the mediator.
If WSO2 is the wrong tool for that I'd like to have a hint which tool could help.
Thanks in advance!
Marco.
For my understanding, you want to have a proxy, but it's backend service/wsdl may vary..
What , you can do is, you can save the wsdl (dynamic wsdl)in registry and point that in your proxy. whenever you edit the wsdl, proxy will automatically adopt to that..But the request, which you send to your backend should follow the wsdl definitions..It is totally client side responsibility..

Tool to intercept RESTful webservices

May be this has been asked before but i coud'nt find a proper tool to do this.
What is the best tool to place in the middle of a RESTful webservice and monitor it without port redirection.
Something like TCPMON which will show the full request from the client and the response from the server. For example if the response contain a JSON i should be able to view that??
Charles Proxy is great for logging the full request/response for HTTP connections.