Saturday, August 29, 2015

How to expose SOAP services as SOAP services via WSO2 API Manager?

Exposing SOAP services is well supported by WSO2 ESB. However, if you would like to have features such as design & prototype APIs, publish & govern API use, control access & enforce security, create a store where anyone can come, play around & subscribe to APIs, manage developer community and monitor API usage etc, then WSO2 API Manager is the ideal product. See here for a complete set of features offered by WSO2 API Manager.

In this post, we will see how you can expose a SOAP service as a SOAP service via WSO2 API Manager 1.9.0.

1. If you don't have any SOAP service, find a public SOAP service in http://www.service-repository.com

2. In this post, we will use StockQuote SOAP service from the above public service repository. Below are the details we should have in order to publish a SOAP service via WSO2 API Manager.

StockQuote SOAP WSDL - http://www.webservicex.com/stockquote.asmx?WSDL
StockQuote SOAP Endpoint - http://www.webservicex.com/stockquote.asmx

3. Download WSO2 API Manager 1.9.0 or latest version from here and start it. If you are new to WSO2 API Manager, visit the quick start guide

4. Login to API Publisher (https://localhost:9443/publisher)



5. Click on "Add" under "APIs" from the left menu



6. Click on "I have a SOAP Endpoint" option, provide your WSDL URL and click on "Start Creating"



7. In the "Design API" page, fill in the general details and click on "Next: Implement"



8. Click on "Managed API".



9. Fill in "Production Endpoint" and "Sandbox Endpoint" and click on "Next: Manage". If your endpoint is secured, have a look at this to learn how to configure a secured backend endpoint in WSO2 API Manager.



10. Select "Tier Availability" and "Transports" under "Configurations" and click "Save & Publish". You have now successfully published a SOAP service as a SOAP service via WSO2 API Manager.



11. Login to API Store (https://localhost:9443/store)


12. Click on your API and you will see a WSDL is published under "Overview" space of the API. Click "Download WSDL" and save it in your machine. Later we will use SoapUI to load this WSDL and invoke the API.



13.  Subscribe to the API using one of your Application and go to "My Subscriptions" page.



14. Click on "Generate keys" to generate consumer key & secret and access token. You will need this access token to invoke the API unless you have disable security to your API when publishing the API. See here to learn how to do that.



15. Create a new SOAP project in SoapUI using the WSDL you have downloaded in step 12.

16. Send a request and you will get following error. Reason is you haven't sent the access token as a bearer token when invoking the API.



17. Add a header "Authorization" and set the value as "Bearer #access-token". Replace #access-token with the access token you generated step 14.




18. Send the request and you will get the response.



As you can see, it is very straightforward to expose a SOAP service as a SOAP service via API Manager.

Saturday, August 15, 2015

WSO2 ESB - How to check whether a string is encoded or not?

The following sample demonstrate how to encode a string in WSO2 ESB and how to check whether a string is encoded or not.

<property name="string" value="abcd"/>
<property name="encodedString" expression="base64Encode('abcd')"/>
<log level="custom">
  <property name="encodedString" expression="get-property('encodedString')"/>
</log>
<filter source="get-property('encodedString')"
     regex="^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$">
  <then>
     <log level="custom">
        <property name="encoded?" value="yes"/>
     </log>
  </then>
  <else>
     <log level="custom">
        <property name="encoded?" value="no"/>
     </log>
  </else>
</filter>

This is based on the regular expression given here to check whether a string is encoded or not.