tag:blogger.com,1999:blog-184810692024-03-05T20:35:54.859+10:30Chandana Napagoda's BlogChandana Napagoda's Web BlogChandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.comBlogger104125tag:blogger.com,1999:blog-18481069.post-47357738335095626332022-09-10T06:43:00.000+09:302022-09-10T06:43:01.232+09:30Adding XML Declaration - WSO2 <div><div>The XML declaration is a processing instruction that identifies the document is in XML format. While working on one of the integration scenarios, I noticed that WSO2 is not sending the XML declaration in the response or backend request message as expected. However, I was able to see it in the log messages. </div><div><br /></div><div>To overcome this issue, you can set below the AXIS2 property before sending a message out.</div></div><div><br /></div><div>To Add XML declaration:</div><div><br /></div><div><span style="font-family: courier;"><property name="WRITE_XML_DECLARATION" scope="axis2" value="true"/></span></div><div><br /></div><div>Also you can use below additional properties to set custom encoding type and set values for standalone.</div><div><br /></div><div><span style="font-family: courier;"><property name=XML_DECLARATION_ENCODING" scope="axis2" value="UTF-16"/></span></div><div><span style="font-family: courier;"><br /></span></div><div><span style="font-family: courier;"><property name="XML_DECLARATION_STANDALONE" scope="axis2" value="no"/></span></div><div><br /></div><div><br /></div>Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-44034562250413876362020-12-01T08:00:00.016+10:302020-12-01T12:30:49.675+10:30Integrate With Mutual Certificate Authentication based Service<div><div></div></div><br />There are many ways to secure a Service/API using different Authentication mechanisms. Mutual Certificate authentication(AKA: Client Certificate Authentication) is one of the ways to secure Service or API. <br /><br />Recently I was trying to integrate with an API which is secured using Mutual Certificate Authentication. In this scenario, the backend service team gave me their certificate-based on PKCS#12. <br /><br />When integrating this backend system with WSO2 Platform, we have to use 'Multi-HTTPS transport'. With this 'Multi-HTTPS transport', it will grant great flexibility to define different SSL profiles with separate trust stores and key stores for different IPs or hosts. This custom SSL profile can be implemented for Client to Synapse Runtime(Client --> ESB) or Synapse Runtime to Backend(ESB --> Backend). If it is Client to ESB, then you have to define custom SSL Profiles in the transportReceiver section.<br /><br />In my use-case, it was for ESB to Backend. So I had to add custom SSL profiles into the transportSender section of the axis2.xml file. Since I have a PKCS#12 based certificate file, I don't need to convert it to JKS or anything.<br /><br />Let's assume Mutual Certificate Authentication based backend API URL is <a href="https://backendhost.com/api/users">https://backendhost.com/api/users</a>. The Custom SSL profiles configuration in the axis2.xml(or senderprofiles.xml in WSO2 EI 7<span style="background-color: rgba(236, 236, 236, 0.5); color: #37474f; font-family: "Roboto Mono", "Courier New", Courier, monospace; font-size: 10.88px;">)</span> is like below. <div><span class="im" style="background-color: white; color: #500050; font-family: Arial, Helvetica, sans-serif; font-size: small;"><br /></span></div><div><span class="im" style="background-color: white; color: #500050; font-family: Arial, Helvetica, sans-serif; font-size: small;"><br /></span></div><div><!--HTML generated using hilite.me--><div style="background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"><pre style="line-height: 125%; margin: 0px;"><span style="color: #007700;"><transportSender</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"https"</span> <span style="color: #0000cc;">class=</span><span style="background-color: #fff0f0;">"org.apache.synapse.transport.passthru.PassThroughHttpSSLSender"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><parameter</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"non-blocking"</span> <span style="color: #0000cc;">locked=</span><span style="background-color: #fff0f0;">"false"</span><span style="color: #007700;">></span>true<span style="color: #007700;"></parameter></span>
<span style="color: #007700;"><parameter</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"keystore"</span> <span style="color: #0000cc;">locked=</span><span style="background-color: #fff0f0;">"false"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><KeyStore></span>
<span style="color: #007700;"><Location></span>repository/resources/security/wso2carbon.jks<span style="color: #007700;"></Location></span>
<span style="color: #007700;"><Type></span>JKS<span style="color: #007700;"></Type></span>
<span style="color: #007700;"><Password></span>wso2carbon<span style="color: #007700;"></Password></span>
<span style="color: #007700;"><KeyPassword></span>wso2carbon<span style="color: #007700;"></KeyPassword></span>
<span style="color: #007700;"></KeyStore></span>
<span style="color: #007700;"></parameter></span>
<span style="color: #007700;"><parameter</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"truststore"</span> <span style="color: #0000cc;">locked=</span><span style="background-color: #fff0f0;">"false"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><TrustStore></span>
<span style="color: #007700;"><Location></span>repository/resources/security/client-truststore.jks<span style="color: #007700;"></Location></span>
<span style="color: #007700;"><Type></span>JKS<span style="color: #007700;"></Type></span>
<span style="color: #007700;"><Password></span>wso2carbon<span style="color: #007700;"></Password></span>
<span style="color: #007700;"></TrustStore></span>
<span style="color: #007700;"></parameter></span>
<span style="color: #007700;"><parameter</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"customSSLProfiles"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><profile></span>
<span style="color: #007700;"><servers></span>backendhost.com:443<span style="color: #007700;"></servers></span>
<span style="color: #007700;"><KeyStore></span>
<span style="color: #007700;"><Location></span>repository/resources/security/backendcertificate.p12<span style="color: #007700;"></Location></span>
<span style="color: #007700;"><Type></span>PKCS12<span style="color: #007700;"></Type></span>
<span style="color: #007700;"><Password></span>certificatePassword<span style="color: #007700;"></Password></span>
<span style="color: #007700;"><KeyPassword></span>certificatePassword<span style="color: #007700;"></KeyPassword></span>
<span style="color: #007700;"></KeyStore></span>
<span style="color: #007700;"></profile></span>
<span style="color: #007700;"></parameter></span>
<span style="color: #888888;"><!--<parameter name="HostnameVerifier">DefaultAndLocalhost</parameter>--></span>
<span style="color: #888888;"><!--supports Strict|AllowAll|DefaultAndLocalhost or the default if none specified --></span>
<span style="color: #007700;"></transportSender></span>
</pre></div>
<div><br /></div></div><div>Docs:</div><div><br /></div><a href="https://docs.wso2.com/display/EI611/Multi-HTTPS+Transport" rel="nofollow" target="_blank">Multi-HTTPS Transport - WSO2 ESB/EI</a><div><a href="https://ei.docs.wso2.com/en/7.2.0/micro-integrator/setup/transport_configurations/multi-https-transport/" rel="nofollow" target="_blank">Multi-HTTPS Transport - WSO2 EI 7</a></div>Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-59686663316201401982020-02-20T22:32:00.004+10:302020-02-20T22:32:56.385+10:30CSV to SOAP Message conversion with Smooks MediatorSmook Mediator available in WSO2 EI/ESB can be used to do various message transformations. For an example read <a href="https://blog.lakmali.com/2013/08/csv-to-xml-transformation-with-wso2-esb.html" target="_blank">CSV file and transform to XML</a>. I had a requirement where I wanted to load a CSV file content into the database. So, my initial idea was to convert CSV content into XML, then use the XSLT mediator to generate a data service request. But it will be a costly operation with lots of resource consumption.<br />
<div>
<br /></div>
<div>
Therefore, instead of generating a data service request via XSLT, I tried to use the options available in Smooks. Smooks provides FreeMaker based templating support that can be used to convert CSV to SOAP.</div>
<div>
<br /></div>
<div>
Here, first I have created a sample input CSV file and expected Data Service sample request message. With this, it will be very easy to generate data mapping. Below are the examples of CSV and Data Service models</div>
<div>
<br /></div>
<div>
<div>
<b>Sample.csv:</b></div>
<div>
UserId,NameFirst,NameLast</div>
<div>
1,Chandana,Napagoda</div>
<div>
2,John,Tester</div>
</div>
<div>
<br /></div>
<div>
<b>SampleOut.xml : </b></div>
<div>
<div>
<au:addUsers_batch_req xmlns:au="https://blog.napagoda.com"></div>
<div>
<span style="white-space: pre;"> </span><au:addUsers></div>
<div>
<span style="white-space: pre;"> </span><au:UserId>1</au:UserId></div>
<div>
<span style="white-space: pre;"> </span><au:NameFirst>Chandana</au:NameFirst></div>
<div>
<span style="white-space: pre;"> </span><au:NameLast>Napagoda</au:NameLast></div>
<div>
<span style="white-space: pre;"> </span><au:System>-1234</au:System></div>
<div>
<span style="white-space: pre;"> </span></au:addUsers></div>
<div>
<span style="white-space: pre;"> </span><au:addUsers></div>
<div>
<span style="white-space: pre;"> </span><au:UserId>2</au:UserId></div>
<div>
<span style="white-space: pre;"> </span><au:NameFirst>John</au:NameFirst></div>
<div>
<span style="white-space: pre;"> </span><au:NameLast>Tester</au:NameLast></div>
<div>
<span style="white-space: pre;"> </span><au:System>-1234</au:System></div>
<div>
<span style="white-space: pre;"> </span></au:addUsers></div>
<div>
</au:addUsers_batch_req></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
When I created the Smook configuration using WSO2 IDE, the view will be like this</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij_xBrZ3O8jeGEWze_rq7ZlEF6FqedxHObGtxacCtd7feUl44uXo1z9CF7yQg4Fpx6SML9IzgappiOhLd78ZSeE0Fs2mKV6Stpbv59B63-YLpGWSV9rD_pLCsPOn35t1Nxf8mUlg/s1600/smooks-1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="814" height="305" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij_xBrZ3O8jeGEWze_rq7ZlEF6FqedxHObGtxacCtd7feUl44uXo1z9CF7yQg4Fpx6SML9IzgappiOhLd78ZSeE0Fs2mKV6Stpbv59B63-YLpGWSV9rD_pLCsPOn35t1Nxf8mUlg/s640/smooks-1.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Next, click on the input task, then select input CSV file as input data. After that, define fields in the CSV file, using the Input configuration section. In Addition to above, I have skipped the first line, and each record was marked as User, and parent Element defined as Users.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcEXOwf3xEHhRfLZPsW3OmfFZNe0mJZ6xvd8LzWPZz2aoM8QdgUi10gwj2ii4NE3SXtyII3UkDwTtDqqiPs-GuPMzpigcT_tLdFsut6K27hUv-xuU7PqO7d-NO7h70O5Gwa7KIaQ/s1600/smooks-2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="700" data-original-width="1132" height="393" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcEXOwf3xEHhRfLZPsW3OmfFZNe0mJZ6xvd8LzWPZz2aoM8QdgUi10gwj2ii4NE3SXtyII3UkDwTtDqqiPs-GuPMzpigcT_tLdFsut6K27hUv-xuU7PqO7d-NO7h70O5Gwa7KIaQ/s640/smooks-2.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
Next, right-click on the 'Input Task', and mouse hover on the 'Add Task' option and click on the 'Apply Template' option.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNpxIdcNmfqOU49ipH7Zse8u3fikAe1CTrxlBMXPgCT0Ztuxay5R0nzM5DsFc_4a5_N40ZJLolxolE3TPLGWvkMFvCt9BIeR7Cl0gAiCz_ziAxXVZmw1rmoKBkk8_3nzQXf_7foA/s1600/smooks-3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="282" data-original-width="829" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNpxIdcNmfqOU49ipH7Zse8u3fikAe1CTrxlBMXPgCT0Ztuxay5R0nzM5DsFc_4a5_N40ZJLolxolE3TPLGWvkMFvCt9BIeR7Cl0gAiCz_ziAxXVZmw1rmoKBkk8_3nzQXf_7foA/s640/smooks-3.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
You will get a dialogue like below to select the output message type. For me, it is XML. </div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2B6pTOiMqcvN35Q2vDoVCW2Rjlj6MDX5AX4CWzCF2YxKMe3Hmso_GYN9W9xUX3chflZNnEk3au_AkM0XN-aogg-5a1fXWP6u8V8dfhFwlrKxAf0nFOjepj3_FAC5vOubOLEmNUw/s1600/smooks-4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="412" data-original-width="685" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2B6pTOiMqcvN35Q2vDoVCW2Rjlj6MDX5AX4CWzCF2YxKMe3Hmso_GYN9W9xUX3chflZNnEk3au_AkM0XN-aogg-5a1fXWP6u8V8dfhFwlrKxAf0nFOjepj3_FAC5vOubOLEmNUw/s400/smooks-4.PNG" width="400" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
In the next dialogue, I can select my Output file format(Data Service Request).</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl8Qk0SfkSeCrcd2Rc_J6mTMnvfmZMz-KsDWL1YJ54xk2RKMA3mBm9Bnri00JCnCNbeek1GvSOuxdVVlsz6ibhBJffKnScr_kSWpBFmotz_Mf6uj7E5aXLmFi2jRD0t7mwABlF2Q/s1600/smooks-5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: left;"><img border="0" data-original-height="592" data-original-width="688" height="343" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl8Qk0SfkSeCrcd2Rc_J6mTMnvfmZMz-KsDWL1YJ54xk2RKMA3mBm9Bnri00JCnCNbeek1GvSOuxdVVlsz6ibhBJffKnScr_kSWpBFmotz_Mf6uj7E5aXLmFi2jRD0t7mwABlF2Q/s400/smooks-5.PNG" width="400" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Once we select the Smooks Output model and click on the 'Finish' button, Initial data mapping screen will look like below. </div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU9tzWUxTbHojuAmnU-ktAgzCWEd4yGFugaJ_wAofzEF1M5cH1eP0OkJ9UZ8uFKlrLiUPFvpGNNQwOL4RujxpOBbf7INDoWKNmUwya9T9YWsHs7JOZptFfgQW_1C5oLSBIpazm2w/s1600/smooks-6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="432" data-original-width="779" height="353" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiU9tzWUxTbHojuAmnU-ktAgzCWEd4yGFugaJ_wAofzEF1M5cH1eP0OkJ9UZ8uFKlrLiUPFvpGNNQwOL4RujxpOBbf7INDoWKNmUwya9T9YWsHs7JOZptFfgQW_1C5oLSBIpazm2w/s640/smooks-6.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Next, select 'User' element from the input model and drop it into 'addUsers' output model. This will generate necessary Freemaker template elements to iterate input rows.</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjt6Kfc9jXp04yxjNg7Y_KTUB_ZeXAKr6PoyNG45puYfOD6kiy8atJaeQX8BwrLcnguewaOMWKaSZq4bJ6QbJmEE51jTJrAjnt_5UKjsTVrCeQc47elxBuTdbes9nBe4Zm_z5Iiw/s1600/smooks-7.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="538" data-original-width="841" height="408" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjt6Kfc9jXp04yxjNg7Y_KTUB_ZeXAKr6PoyNG45puYfOD6kiy8atJaeQX8BwrLcnguewaOMWKaSZq4bJ6QbJmEE51jTJrAjnt_5UKjsTVrCeQc47elxBuTdbes9nBe4Zm_z5Iiw/s640/smooks-7.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
Next map each input element into expected output elements. When ding that, you have to select each leaf element from the input model and drop into the output leaf element. </div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-Esllzl8mJI8n2ByBexQyz2-m0oXbHvkhhHdiwAwW5aOwt1cu14aUacXHiBId20eleXQZINw6omJB4wrSdWQKWHiJBrK9t6D3vUEQ0cdFAEq1FWXCJyfryL5WZtm0BGJOilMFw/s1600/smooks-8.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="560" data-original-width="806" height="443" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-Esllzl8mJI8n2ByBexQyz2-m0oXbHvkhhHdiwAwW5aOwt1cu14aUacXHiBId20eleXQZINw6omJB4wrSdWQKWHiJBrK9t6D3vUEQ0cdFAEq1FWXCJyfryL5WZtm0BGJOilMFw/s640/smooks-8.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
When navigating to source view of Smooks configuration, below configuration has been auto-generated. </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
<?xml version="1.0" encoding="UTF-8"?><smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd" xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd"></div>
<div>
<params></div>
<div>
<param name="stream.filter.type">SAX</param></div>
<div>
<param name="inputType">input.csv</param></div>
<div>
<param name="input.csv" type="input.type.actived">File:/E:\test\done\Sample.csv</param></div>
<div>
</params></div>
<div>
<csv:reader fields="UserId,NameFirst,NameLast" recordElementName="User" rootElementName="Users" skipLines="1"/></div>
<div>
<ftl:freemarker applyOnElement="#document"></div>
<div>
<ftl:template><![CDATA[<?xml version="1.0" encoding="UTF-8"?></div>
<div>
<au:addUsers_batch_req xmlns:au="https://blog.napagoda.com"></div>
<div>
<#list .vars["Users"]["User"] as User></div>
<div>
<au:addUsers></div>
<div>
<au:UserId>${.vars["User"]["UserId"]}</au:UserId> </div>
<div>
<au:NameFirst>${.vars["User"]["NameFirst"]}</au:NameFirst> </div>
<div>
<au:NameLast>${.vars["User"]["NameLast"]}</au:NameLast> </div>
<div>
</au:addUsers></div>
<div>
</#list> </div>
<div>
</au:addUsers_batch_req>]]></ftl:template></div>
<div>
<param name="modelSrc">File:/E:\test\done\SampleOut.xml</param></div>
<div>
<param name="modelSrcType">XML</param></div>
<div>
<param name="messageType">XML</param></div>
<div>
<param name="templateDataProvider">input</param></div>
<div>
</ftl:freemarker></div>
<div>
<resource-config selector="#document"></div>
<div>
<resource>org.milyn.delivery.DomModelCreator</resource></div>
<div>
</resource-config></div>
<div>
</smooks-resource-list></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-31119631779011255682019-12-03T20:53:00.000+10:302019-12-03T20:53:28.751+10:30Configure Kerberos based Authentication into WSO2 Datasources <br />
As you know, Kerberos can be used to authenticate System or users reside on a none secured network. In my use case, I have Windows AD and MSSQL server and I have a couple of WSO2 Servers running on Linux systems.<br />
<br />
In my initial setup I have configured, WSO2 servers has to use SQL users. But instead of using SQL users, I prefer to use AD users. So I have started configuring Kerberos and faced a lot of troubles.<br />
<div>
<br /></div>
<div>
If you are starting from scratch, I would recommend writing a Java class to connect MSSQL server using Kerberos. Then You can identify all small mistakes such as character case issues, typos, JDBC driver compatibility issues, etc. </div>
<div>
<br /></div>
<div>
Below are a few issues I have faced:</div>
<div>
<br /></div>
1) CASE is significant in krb5.conf file<br />
<div>
<br /></div>
<div>
2) I found that we need to use MSSQL JDBC 6.4 version in order to get new tickets. But if you are just planning use pre-generated tickets, you can use the older version as well.</div>
<div>
<br /></div>
<div>
Here are the steps you need follow when configuring Kerberos with WSO2 Enterprise Integrator. </div>
<div>
<br /></div>
<div>
<b>1) Define your krb5.conf </b><b>File</b><b>. </b></div>
<div>
<br /></div>
In my config file, I have defined two KDC and admin server(KDC) which will handle the database administration requests and all KDC(master and worker) will generate credentials. KDCs are your Active directory server hostnames<br />
<div>
<br /></div>
<div>
<div>
<i>[libdefaults]</i></div>
<div>
<i><span style="white-space: pre;"> </span>default_realm = NAPAGODA.COM</i></div>
<div>
<i>[realms]</i></div>
<div>
<i><span style="white-space: pre;"> </span>NAPAGODA.COM = {</i></div>
<div>
<i><span style="white-space: pre;"> </span>kdc = dc1.napagoda.com</i></div>
<div>
<i><span style="white-space: pre;"> </span>kdc = dc2.napagoda.com</i></div>
<div>
<i><span style="white-space: pre;"> </span>admin_server = dc1.napagoda.com</i></div>
<div>
<i><span style="white-space: pre;"> </span>default_domain = NAPAGODA.COM</i></div>
<div>
<i><span style="white-space: pre;"> </span>}</i></div>
<div>
<i><br /></i></div>
<div>
<i>[domain_realm]</i></div>
<div>
<i> .napagoda.com = NAPAGODA.COM</i></div>
<div>
<i> napagoda.com = NAPAGODA.COM</i></div>
</div>
<div>
<br /></div>
<div>
<b>2) . Configure jaas.conf </b><b>File</b></div>
<div>
<br /></div>
<div>
This file needs to be created under '<b><span style="color: red;">repository/conf/identity</span></b>/' directory. With WSO2 Enterprise Integrator product they have moved conf directory into product home. However, still, this file needs to be created based on the old folder structure. So make sure to use '<b><span style="color: red;">repository/conf/identity</span></b>/'. Luckily, if not, it will display an error message in the log file(or console). </div>
<div>
<br /></div>
<div>
<div>
<i>SQLJDBCDriver {</i></div>
<div>
<i> com.sun.security.auth.module.Krb5LoginModule required useTicketCache=true;</i></div>
<div>
<i>};</i></div>
</div>
<div>
<br /></div>
<b>3). Locating the krb5.conf File</b><br />
<div>
<br /></div>
<div>
If you have created your krb5.conf file inside lib/security directory of the JRE, you don't need to set the environment variable. Otherwise, you have to pass 'krb5.conf' file location as a 'java.security.krb5.conf' environment variable. <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/jgss/tutorials/KerberosReq.html" target="_blank">Oracle Docs</a></div>
<div>
<br /></div>
<div>
ex: <b>-Djava.security.krb5.conf=/file/location/krb5.conf </b></div>
<div>
<br /></div>
<div>
4) Configure WSO2 Datasources</div>
<div>
<br /></div>
<div>
You can use Kerberos based Authentication in your datasources XML files or datasources defined via the 'admin console'. But make sure to pass correct parameters into SQL connection URL to use Kerberos Authentication. Please note, in the connection user and password fields, you can AD user's credentials. </div>
<div>
<br /></div>
<div>
ex:<b> jdbc:sqlserver://your.sql.server.com;database=database_name;<span style="color: red;">integratedSecurity=true;authenticationScheme=JavaKerberos</span></b></div>
<div>
<br /></div>
<div>
<br /></div>
<br />
- <a href="http://janbernhardt.blogspot.com/2017/02/kerberos-debugging-in-java.html" target="_blank">Kerberos Debugging in Java</a><br />
- <a href="https://www.microsoft.com/en-us/download/details.aspx?id=56615" target="_blank">Microsoft JDBC Driver 6.4 for SQL Server</a><br />
<div>
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-14042522991187842782019-12-01T08:30:00.000+10:302019-12-01T08:30:05.634+10:30Compare Two XML Elements and Filter using WSO2 EI<br />
Think about an integration scenario, where you are getting a list of data from a service endpoint(Data 1) and you want to exclude or match this response against the data returned by another service endpoint(Data 2).<br />
<br />
In such a situation, first, you need to have a unique attribute in both data set to exclude or match elements. So in my use case, list of data and matching content is as below<br />
<div>
<div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><CodeLists></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>O<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Open<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>C<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Cancelled<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>X<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Denied<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>P<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Pending<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>D<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Duplicate<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"></CodeLists></span>
</pre>
</div>
<div>
<div style="text-align: center;">
Data 1</div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><CodeLists></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>O<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Open<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Id></span>P<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Pending<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"></CodeLists></span>
</pre>
</div>
<div style="text-align: center;">
<b>Data 2</b></div>
</div>
<br /></div>
<div>
<br /></div>
So here I am going to use WSO2 Enterprise Integrator and its XSLT mediator to filter the results. First I am joining all the elements that need to be hidden into a single Synapse property. <br />
<div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"elementsToBeHide"</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"string-join(//CodeLists/CodeList/Id, ',')"</span> <span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"default"</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"STRING"</span><span style="color: #007700;">/></span></pre>
<br /></div>
<div>
<br /></div>
<div>
<div>
Then I am calling my XSLT with elementsToBeHide as a parameter.</div>
</div>
<div>
<br /></div>
<div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><xslt</span> <span style="color: #0000cc;">key=</span><span style="background-color: #fff0f0;">"conf:/xslts/xslt_FilterResults.xslt"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"elementsToBeHide"</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$ctx:elementsToBeHide"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></xslt></span>
</pre>
</div>
</div>
<div>
<br /></div>
<div>
My XSLT file is stored in the registry. However, if you are using a Micro Integrator profile, you can add this XSLT as a local entry. Inside my XSLT document, I am looping all code list elements and check whether each ID exists in 'elementsToBeHide' parameter. You can use the same XSLT Choose Condition to filter data based on matching or not matching scenarios. In my example, if ID is not matching to the current ID, it will be added to Code element.</div>
<div>
<br /></div>
<div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #008800; font-weight: bold;"><xsl:stylesheet</span> <span style="color: #0000cc;">version=</span><span style="background-color: #fff0f0;">"2.0"</span> <span style="color: #0000cc;">xmlns:xsl=</span><span style="background-color: #fff0f0;">"http://www.w3.org/1999/XSL/Transform"</span> <span style="color: #0000cc;">xmlns:xsi=</span><span style="background-color: #fff0f0;">"http://www.w3.org/2001/XMLSchema-instance"</span>
<span style="color: #0000cc;">xmlns:xs=</span><span style="background-color: #fff0f0;">"http://www.w3.org/2001/XMLSchema"</span> <span style="color: #0000cc;">xmlns:sy=</span><span style="background-color: #fff0f0;">"http://ws.apache.org/ns/synapse"</span> <span style="color: #0000cc;">xmlns:fn=</span><span style="background-color: #fff0f0;">"http://www.w3.org/2005/xpath-functions"</span>
<span style="color: #0000cc;">xmlns:i=</span><span style="background-color: #fff0f0;">"http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: #007700;">></span>
<span style="color: #008800; font-weight: bold;"><xsl:strip-space</span> <span style="color: #0000cc;">elements=</span><span style="background-color: #fff0f0;">"*"</span> <span style="color: #007700;">/></span>
<span style="color: #008800; font-weight: bold;"><xsl:param</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"elementsToBeHide"</span> <span style="color: #007700;">/></span>
<span style="color: #008800; font-weight: bold;"><xsl:template</span> <span style="color: #0000cc;">match=</span><span style="background-color: #fff0f0;">"/CodeLists"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><CodeLists></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #008800; font-weight: bold;"><xsl:for-each</span> <span style="color: #0000cc;">select=</span><span style="background-color: #fff0f0;">"CodeList"</span><span style="color: #007700;">></span>
<span style="color: #008800; font-weight: bold;"><xsl:choose</span><span style="color: #007700;">></span>
<span style="color: #008800; font-weight: bold;"><xsl:when</span> <span style="color: #0000cc;">test=</span><span style="background-color: #fff0f0;">"matches($elementsToBeHide,Id)"</span><span style="color: #007700;">></span>
<span style="color: #888888;"><!-- match senarios --></span>
<span style="color: #008800; font-weight: bold;"></xsl:when></span>
<span style="color: #008800; font-weight: bold;"><xsl:otherwise</span><span style="color: #007700;">></span>
<span style="color: #888888;"><!-- not matching --></span>
<span style="color: #007700;"><Code></span>
<span style="color: #007700;"><Name></span><span style="color: #008800; font-weight: bold;"><xsl:value-of</span> <span style="color: #0000cc;">select=</span><span style="background-color: #fff0f0;">"Name"</span><span style="color: #007700;">/></Name></span>
<span style="color: #007700;"><Id></span><span style="color: #008800; font-weight: bold;"><xsl:value-of</span> <span style="color: #0000cc;">select=</span><span style="background-color: #fff0f0;">"Id"</span><span style="color: #007700;">/></Id></span>
<span style="color: #007700;"></Code></span>
<span style="color: #008800; font-weight: bold;"></xsl:otherwise></span>
<span style="color: #008800; font-weight: bold;"></xsl:choose></span>
<span style="color: #008800; font-weight: bold;"></xsl:for-each></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"></CodeLists></span>
<span style="color: #008800; font-weight: bold;"></xsl:template></span>
<span style="color: #008800; font-weight: bold;"></xsl:stylesheet></span>
</pre>
</div>
</div>
<div>
<br />
<br />
The output of the XSLT transformation is as below and it only includes elements which are not matching to the filtering data set.</div>
<div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><CodeLists></span>
<span style="color: #007700;"><CodeList></span>
<span style="color: #007700;"><Code></span>
<span style="color: #007700;"><Id></span>C<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Cancelled<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></Code></span>
<span style="color: #007700;"><Code></span>
<span style="color: #007700;"><Id></span>X<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Denied<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></Code></span>
<span style="color: #007700;"><Code></span>
<span style="color: #007700;"><Id></span>D<span style="color: #007700;"></Id></span>
<span style="color: #007700;"><Name></span>Duplicate<span style="color: #007700;"></Name></span>
<span style="color: #007700;"></Code></span>
<span style="color: #007700;"></CodeList></span>
<span style="color: #007700;"></CodeLists></span>
</pre>
</div>
</div>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-5326915613803219322019-01-04T22:35:00.001+10:302019-01-04T22:35:31.229+10:30XSLT - Modify Date and DateTime valueIf you want to perform date and time related opertions with XSLT 'date' or 'dateTime' values, you can use 'xs:yearMonthDuration' or 'xs:dayTimeDuration' function to achieve this. You can add or reduce years, months, date, hours or even minutes through those functions.<br />
<br />
<br />
<b> xs:yearMonthDuration</b><br />
<br />
For this function input value is year month duration and it should be passed in <a href="https://en.wikipedia.org/wiki/ISO_8601#Durations">ISO_8601 format</a><br />
<div>
<br /></div>
n- the [n] is replaced by the value for each of the date and time elements<br />
P - The duration designator(for period).<br />
<div>
<div>
nY- the number of years.</div>
<div>
nM- the number of months.</div>
<div>
<br /></div>
ex: <i>xs:yearMonthDuration('P1Y2M')</i> - 1 Year and 2 Months</div>
<div>
ex: <i>xs:yearMonthDuration('-P1Y2M')</i> - Negative 1 Year and 2 Months<br />
<br />
<b>xs:dayTimeDuration</b><br />
<br />
For this function input value is day time duration and it also needs to be passed in <a href="https://en.wikipedia.org/wiki/ISO_8601#Durations">ISO_8601 format</a><br />
<br />
n- the [n] is replaced by the value for each of the date and time elements<br />
P - The duration designator(for period).</div>
<div>
nD- the number of days.</div>
<div>
T- The date and time separator.</div>
<div>
nH- the number of hours.</div>
<div>
nM- the number of minutes.</div>
<div>
nS - the number of seconds.</div>
<div>
<br /></div>
ex: xs:dayTimeDuration('P3D') - 3 Days<br />
<div>
ex: xs:dayTimeDuration('-P3D') - Negative 3 days</div>
ex: xs:dayTimeDuration('P6DT50H80S') - 6 days, 50 hours, and 80 seconds<br />
<div>
<br />
<div>
<br />
Example XSLT :<br />
<br />
<?xml version="1.0"?><br />
<xsl:stylesheet version="2.0"<br />
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />
xmlns:xs="http://www.w3.org/2001/XMLSchema" ><br />
<br />
<xsl:output method="text"/><br />
<br />
<xsl:variable name="dT" as="xs:dateTime" select="xs:dateTime('2016-02-29T00:00:01')"/><br />
<xsl:variable name="d" as="xs:date" select="xs:date('2016-02-29')"/><br />
<br />
<xsl:template match="/"><br />
<xsl:text>Add 1 Year and 2 Months : </xsl:text> <xsl:value-of select="($d+ xs:yearMonthDuration('P1Y2M'))"/><br />
<xsl:text>&#xA;Negative 1 Year and 2 Month : </xsl:text> <xsl:value-of select="($d+ xs:yearMonthDuration('-P1Y2M'))"/><br />
<br />
<xsl:text>&#xA;Add 3 Days : </xsl:text> <xsl:value-of select="($dT+ xs:dayTimeDuration('P3D'))"/><br />
<xsl:text>&#xA;Negative 3 days : </xsl:text> <xsl:value-of select="($dT+xs:dayTimeDuration('-P3D'))"/><br />
<xsl:text>&#xA;Add 6 days, 50 hours, and 80 seconds : </xsl:text> <xsl:value-of select="($dT+ xs:dayTimeDuration('P6DT50H80S'))"/><br />
</xsl:template><br />
</xsl:stylesheet><br />
<br />
<br /></div>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-82510017973625828782018-07-26T19:24:00.005+09:302018-07-26T19:25:09.773+09:30WSO2 EI/ESB Change Backend Response Status Code<div>
With WSO2 Enterprise Integrator or Enterprise Service Bus servers, if you want to change the backend server response code, you can set custom status status code as below:</div>
<div>
<br /></div>
<div>
<property name="HTTP_SC" scope="axis2" type="STRING" value="403"/></div>
<div>
<br /></div>
<div>
If you are getting 'HTTP/1.1 202 Accepted' response from your backend, you need to set "SC_ACCEPTED" as false by setting a custom SC_ACCEPTED</div>
<div>
<br /></div>
<div>
Ex: Receiving 202 from backend and change it to 200</div>
<div>
<br /></div>
<div>
<div>
<filter regex="202" source="$axis2:HTTP_SC"></div>
<div>
<then></div>
<div>
<property action="remove" name="HTTP_SC" scope="axis2"/></div>
<div>
<property name="SC_ACCEPTED" scope="axis2" value="false"/></div>
<div>
<property name="HTTP_SC" scope="axis2" type="STRING" value="200"/></div>
<div>
</then></div>
<div>
<else/></div>
<div>
</filter></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-2691435480666377862018-06-06T17:38:00.000+09:302018-06-06T17:38:53.563+09:30Read XML content of the LocalEntry in WSO2 ESB<div>
Local Entry is one of the data storage points in the WSO2 Enterprise Service Bus, where you can store text strings, XML content, and File URLs. I have been asked a question that, how can we read the content of the local entry if it as an XML file.</div>
<div>
<br /></div>
<div>
Below is an example to read the content of the local entry(Name: NameOfLocalEntry) and assign the value of XML elements as properties. </div>
<div>
<br /></div>
<div>
<b>Content of Local Entry:</b></div>
<div>
<br /></div>
<div>
<div>
<?xml version="1.0"?></div>
<div>
<Server></div>
<div>
<span style="white-space: pre;"> </span><userName>chandana</userName></div>
<div>
<span style="white-space: pre;"> </span><URL>blog.napagoda.com</URL></div>
<div>
</Server></div>
</div>
<div>
<br /></div>
<div>
<b>Synapse Configuration: </b></div>
<div>
<br /></div>
<div>
<div>
<property name="localEntry" expression="get-property('NameOfLocalEntry')" scope="default" type="OM"/></div>
</div>
<div>
<br /></div>
<div>
<property name="userName" expression="$ctx:localEntry//*[local-name()='userName']"/></div>
<div>
<property name="URL" expression="$ctx:localEntry//*[local-name()='URL']"/></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-45857859982456537042018-04-30T21:05:00.000+09:302018-04-30T21:05:17.046+09:30Payload Factory Mediators for JSON MessageWSO2 ESB/EI PayloadFactory mediator can be used to replace the contents of a message. As an example, if the backend is accepting a different message structure than what you are receiving, you can use PayloadFactory mediator to change the message structure. Other than that, if you want to transform XML payload into JSON or JSON to XML with different message structure you can use this mediator.<br />
<br />
Recently, I faced an issue while transforming a message into JSON which is originally read from a CSV file(using <a href="https://blog.lakmali.com/2013/08/csv-to-xml-transformation-with-wso2-esb.html" target="_blank">Smooks Mediator</a>). This message can have empty values in the content sometimes and such messages look like below:<br />
<br />
<i><Users></i><br />
<i><User></i><br />
<i><FirstName>Chandana</FirstName></i><br />
<i><MiddleName/></i><br />
<i></Users></i><br />
<i></User></i><br />
<br />
I initially wrote a payload factory mediator like below:<br />
<br />
<i><payloadFactory media-type="json"></i><br />
<i> <format></i><br />
<i><span style="white-space: pre;"> </span> {</i><br />
<i><span style="white-space: pre;"> </span> "UserInfo": {</i><br />
<i><span style="white-space: pre;"> </span> "fName": "$1",</i><br />
<i><span style="white-space: pre;"> </span> "mName": "$2"</i><br />
<span style="white-space: pre;"><i> </i></span><br />
<i><span style="white-space: pre;"> </span>}</i><br />
<i><span style="white-space: pre;"> </span>}<span style="white-space: pre;"> </span></i><br />
<i><span style="white-space: pre;"> </span></format></i><br />
<i><span style="white-space: pre;"> </span><args></i><br />
<i><span style="white-space: pre;"> </span><arg evaluator="xml" expression="//User/FirstName"/></i><br />
<i> <arg evaluator="xml" expression="//User/MiddleName"/></i><br />
<i><span style="white-space: pre;"> </span></args></i><br />
<i></payloadFactory></i><br />
<br />
JSON Output from the Payloadfactory mediator :<br />
<br />
<i>{</i><br />
<i><span style="white-space: pre;"> </span> "UserInfo": {</i><br />
<i><span style="white-space: pre;"> </span> "fName": "Chandana",</i><br />
<i><span style="white-space: pre;"> </span> "mName": "{"MiddleName":null}",</i><br />
<span style="white-space: pre;"><i> </i></span><br />
<i><span style="white-space: pre;"> </span>}</i><br />
<i><span style="white-space: pre;"> </span>}</i><br />
<br />
So you can see that JSON output is malformed, but this will work perfectly when you have a value for MiddleName field.<br />
<br />
To avoid this issue, what we have to do is, when we are passing arguments to the PayloadFactory mediator, we should pass text values(ex: FirstName/text()) instead of the XML object.<br />
<br />
<i><payloadFactory media-type="json"></i><br />
<i> <format></i><br />
<i><span style="white-space: pre;"> </span> {</i><br />
<i><span style="white-space: pre;"> </span> "UserInfo": {</i><br />
<i><span style="white-space: pre;"> </span> "fName": "$1",</i><br />
<i><span style="white-space: pre;"> </span> "mName": "$2"</i><br />
<span style="white-space: pre;"><i> </i></span><br />
<i><span style="white-space: pre;"> </span>}</i><br />
<i><span style="white-space: pre;"> </span>}<span style="white-space: pre;"> </span></i><br />
<i><span style="white-space: pre;"> </span></format></i><br />
<i><span style="white-space: pre;"> </span><args></i><br />
<i><span style="white-space: pre;"> </span><arg evaluator="xml" expression="//User/FirstName/text()"/></i><br />
<i> <arg evaluator="xml" expression="//User/MiddleName/text()"/></i><br />
<i><span style="white-space: pre;"> </span></args></i><br />
<i></payloadFactory></i><br />
<br />Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com1tag:blogger.com,1999:blog-18481069.post-87780672556449735292018-02-22T06:58:00.000+10:302018-02-22T08:51:38.113+10:30 WSO2 ESB - How to use filter inside iterate mediator<br />
WSO2 ESB's Iterate mediator plays a very powerful role in the Splitter Enterprise Integration Pattern. Splitter Enterprise Integration Pattern is used when messages contain multiple elements that might have to be processed in different ways. The Splitter breaks out the composite message into a series of individual messages, each containing data related to one item.<br />
<br />
WSO2 ESB Iterate mediator split the message based on a given expression and process them separately. So think about a use case like you are getting multiple order items and you want to enrich each order item, by calling another endpoint and finally we need to aggregate all the enriched items.<br />
<br />
There you can use the Iterate mediator and after that aggregate mediator to aggregate all the enriched items.<br />
<div>
<br /></div>
<div>
Example:<br />
<br />
<span style="background-color: white;"><br /></span> ESB Proxy Service:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #007700;"><proxy</span> <span style="color: #0000cc;">xmlns=</span><span style="background-color: #fff0f0;">"http://ws.apache.org/ns/synapse"</span>
<span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"IteService"</span>
<span style="color: #0000cc;">transports=</span><span style="background-color: #fff0f0;">"http,https"</span>
<span style="color: #0000cc;">statistics=</span><span style="background-color: #fff0f0;">"disable"</span>
<span style="color: #0000cc;">trace=</span><span style="background-color: #fff0f0;">"disable"</span>
<span style="color: #0000cc;">startOnLoad=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><target></span>
<span style="color: #007700;"><inSequence></span>
<span style="color: #007700;"><iterate</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"aggregateid"</span>
<span style="color: #0000cc;">preservePayload=</span><span style="background-color: #fff0f0;">"true"</span>
<span style="color: #0000cc;">attachPath=</span><span style="background-color: #fff0f0;">"//Collection"</span>
<span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"//Collection/Job"</span>
<span style="color: #0000cc;">sequential=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><target></span>
<span style="color: #007700;"><sequence></span>
<span style="color: #007700;"><enrich></span>
<span style="color: #007700;"><source</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"body"</span> <span style="color: #0000cc;">clone=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><target</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"property"</span> <span style="color: #0000cc;">property=</span><span style="background-color: #fff0f0;">"originalRequest"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></enrich></span>
<span style="color: #007700;"><payloadFactory</span> <span style="color: #0000cc;">media-type=</span><span style="background-color: #fff0f0;">"xml"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><format></span>
<span style="color: #007700;"><p:echoInt</span> <span style="color: #0000cc;">xmlns:p=</span><span style="background-color: #fff0f0;">"http://echo.services.core.carbon.wso2.org"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><in></span>$1<span style="color: #007700;"></in></span>
<span style="color: #007700;"></p:echoInt></span>
<span style="color: #007700;"></format></span>
<span style="color: #007700;"><args></span>
<span style="color: #007700;"><arg</span> <span style="color: #0000cc;">evaluator=</span><span style="background-color: #fff0f0;">"xml"</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$body/Collection/Job/Id"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></args></span>
<span style="color: #007700;"></payloadFactory></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"SOAPAction"</span>
<span style="color: #0000cc;">value=</span><span style="background-color: #fff0f0;">"&#34;echoInt&#34;"</span>
<span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"transport"</span>
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"STRING"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><call></span>
<span style="color: #007700;"><endpoint></span>
<span style="color: #007700;"><address</span> <span style="color: #0000cc;">uri=</span><span style="background-color: #fff0f0;">"https://localhost:8243/services/echo"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></endpoint></span>
<span style="color: #007700;"></call></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">xmlns:ns=</span><span style="background-color: #fff0f0;">"http://echo.services.core.carbon.wso2.org"</span>
<span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"echoResponse"</span>
<span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$body/ns:echoIntResponse"</span>
<span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"default"</span>
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"OM"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><enrich></span>
<span style="color: #007700;"><source</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"property"</span> <span style="color: #0000cc;">clone=</span><span style="background-color: #fff0f0;">"true"</span> <span style="color: #0000cc;">property=</span><span style="background-color: #fff0f0;">"originalRequest"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><target</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"body"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></enrich></span>
<span style="color: #007700;"><enrich></span>
<span style="color: #007700;"><source</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"property"</span> <span style="color: #0000cc;">clone=</span><span style="background-color: #fff0f0;">"true"</span> <span style="color: #0000cc;">property=</span><span style="background-color: #fff0f0;">"echoResponse"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><target</span> <span style="color: #0000cc;">action=</span><span style="background-color: #fff0f0;">"child"</span> <span style="color: #0000cc;">xpath=</span><span style="background-color: #fff0f0;">"$body/Collection"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></enrich></span>
<span style="color: #007700;"></sequence></span>
<span style="color: #007700;"></target></span>
<span style="color: #007700;"></iterate></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"Collections"</span> <span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"default"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><Collections</span> <span style="color: #0000cc;">xmlns=</span><span style="background-color: #fff0f0;">""</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></property></span>
<span style="color: #007700;"><aggregate</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"aggregateid"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><completeCondition></span>
<span style="color: #007700;"><messageCount</span> <span style="color: #0000cc;">min=</span><span style="background-color: #fff0f0;">"-1"</span> <span style="color: #0000cc;">max=</span><span style="background-color: #fff0f0;">"-1"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></completeCondition></span>
<span style="color: #007700;"><onComplete</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$body/Collection"</span> <span style="color: #0000cc;">enclosingElementProperty=</span><span style="background-color: #fff0f0;">"Collections"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><respond/></span>
<span style="color: #007700;"></onComplete></span>
<span style="color: #007700;"></aggregate></span>
<span style="color: #007700;"></inSequence></span>
<span style="color: #007700;"></target></span>
<span style="color: #007700;"><description/></span>
<span style="color: #007700;"></proxy></span>
</pre>
</div>
<br />
<br />
Request:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><soapenv:Envelope</span> <span style="color: #0000cc;">xmlns:soapenv=</span><span style="background-color: #fff0f0;">"http://schemas.xmlsoap.org/soap/envelope/"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><soapenv:Header/></span>
<span style="color: #007700;"><soapenv:Body></span>
<span style="color: #007700;"><Collection></span>
<span style="color: #007700;"><Job></span>
<span style="color: #007700;"><Id></span>12345<span style="color: #007700;"></Id></span>
<span style="color: #007700;"></Job></span>
<span style="color: #007700;"><Job></span>
<span style="color: #007700;"><Id></span>12346<span style="color: #007700;"></Id></span>
<span style="color: #007700;"></Job></span>
<span style="color: #007700;"></Collection></span>
<span style="color: #007700;"></soapenv:Body></span>
<span style="color: #007700;"></soapenv:Envelope></span>
</pre>
</div>
<br />
<span style="background-color: white;"></span> <span style="background-color: white;"><br /></span> <span style="background-color: white;">Let me expand this use case. Assume we just need to enrich some of the items only. To do that, we have to use filter mediator inside the Iterate mediator. If we update our existing code with the filter mediator logic, it will never reach to the aggregate on-complete logic. The reason is aggregate mediator waits for total messages that came into the iterate mediator, but due to the filter logic, some messages aren't supposed to be included in the aggregation. To avoid this, what we can do is, we have to define this Iterate mediator inside the In-Sequence and after all the logic inside the Iterate mediator( before the tag) you have to add a loopback mediator and need to move aggregate mediator into Out-Sequence. This will call the aggregate mediator for all the messages.</span></div>
<div>
<br />
Example:</div>
<div>
<br />
ESB Proxy Service:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #007700;"><proxy</span> <span style="color: #0000cc;">xmlns=</span><span style="background-color: #fff0f0;">"http://ws.apache.org/ns/synapse"</span>
<span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"IteFilterService"</span>
<span style="color: #0000cc;">transports=</span><span style="background-color: #fff0f0;">"http,https"</span>
<span style="color: #0000cc;">statistics=</span><span style="background-color: #fff0f0;">"disable"</span>
<span style="color: #0000cc;">trace=</span><span style="background-color: #fff0f0;">"disable"</span>
<span style="color: #0000cc;">startOnLoad=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><target></span>
<span style="color: #007700;"><inSequence></span>
<span style="color: #007700;"><iterate</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"aggregateid"</span>
<span style="color: #0000cc;">preservePayload=</span><span style="background-color: #fff0f0;">"true"</span>
<span style="color: #0000cc;">attachPath=</span><span style="background-color: #fff0f0;">"//Collection"</span>
<span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"//Collection/Job"</span>
<span style="color: #0000cc;">sequential=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><target></span>
<span style="color: #007700;"><sequence></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"JobId"</span>
<span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"string(//Job/Id)"</span>
<span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"default"</span>
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"STRING"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><filter</span> <span style="color: #0000cc;">source=</span><span style="background-color: #fff0f0;">"$ctx:JobId"</span> <span style="color: #0000cc;">regex=</span><span style="background-color: #fff0f0;">"[0-9]+"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><log</span> <span style="color: #0000cc;">level=</span><span style="background-color: #fff0f0;">"full"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"JobId"</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"string(//Job/Id)"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></log></span>
<span style="color: #007700;"><enrich></span>
<span style="color: #007700;"><source</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"body"</span> <span style="color: #0000cc;">clone=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><target</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"property"</span> <span style="color: #0000cc;">property=</span><span style="background-color: #fff0f0;">"originalRequest"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></enrich></span>
<span style="color: #007700;"><payloadFactory</span> <span style="color: #0000cc;">media-type=</span><span style="background-color: #fff0f0;">"xml"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><format></span>
<span style="color: #007700;"><p:echoInt</span> <span style="color: #0000cc;">xmlns:p=</span><span style="background-color: #fff0f0;">"http://echo.services.core.carbon.wso2.org"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><in></span>$1<span style="color: #007700;"></in></span>
<span style="color: #007700;"></p:echoInt></span>
<span style="color: #007700;"></format></span>
<span style="color: #007700;"><args></span>
<span style="color: #007700;"><arg</span> <span style="color: #0000cc;">evaluator=</span><span style="background-color: #fff0f0;">"xml"</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$ctx:JobId"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></args></span>
<span style="color: #007700;"></payloadFactory></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"SOAPAction"</span>
<span style="color: #0000cc;">value=</span><span style="background-color: #fff0f0;">"&#34;echoInt&#34;"</span>
<span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"transport"</span>
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"STRING"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><call></span>
<span style="color: #007700;"><endpoint></span>
<span style="color: #007700;"><address</span> <span style="color: #0000cc;">uri=</span><span style="background-color: #fff0f0;">"https://localhost:8243/services/echo"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></endpoint></span>
<span style="color: #007700;"></call></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">xmlns:ns=</span><span style="background-color: #fff0f0;">"http://echo.services.core.carbon.wso2.org"</span>
<span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"echoResponse"</span>
<span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$body/ns:echoIntResponse"</span>
<span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"default"</span>
<span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"OM"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><enrich></span>
<span style="color: #007700;"><source</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"property"</span> <span style="color: #0000cc;">clone=</span><span style="background-color: #fff0f0;">"true"</span> <span style="color: #0000cc;">property=</span><span style="background-color: #fff0f0;">"originalRequest"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><target</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"body"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></enrich></span>
<span style="color: #007700;"><enrich></span>
<span style="color: #007700;"><source</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"property"</span> <span style="color: #0000cc;">clone=</span><span style="background-color: #fff0f0;">"true"</span> <span style="color: #0000cc;">property=</span><span style="background-color: #fff0f0;">"echoResponse"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"><target</span> <span style="color: #0000cc;">action=</span><span style="background-color: #fff0f0;">"child"</span> <span style="color: #0000cc;">xpath=</span><span style="background-color: #fff0f0;">"$body/Collection"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></enrich></span>
<span style="color: #007700;"></filter></span>
<span style="color: #007700;"><loopback/></span>
<span style="color: #007700;"></sequence></span>
<span style="color: #007700;"></target></span>
<span style="color: #007700;"></iterate></span>
<span style="color: #007700;"></inSequence></span>
<span style="color: #007700;"><outSequence></span>
<span style="color: #007700;"><property</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"Collections"</span> <span style="color: #0000cc;">scope=</span><span style="background-color: #fff0f0;">"default"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><Collections</span> <span style="color: #0000cc;">xmlns=</span><span style="background-color: #fff0f0;">""</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></property></span>
<span style="color: #007700;"><aggregate</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"aggregateid"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><completeCondition></span>
<span style="color: #007700;"><messageCount</span> <span style="color: #0000cc;">min=</span><span style="background-color: #fff0f0;">"-1"</span> <span style="color: #0000cc;">max=</span><span style="background-color: #fff0f0;">"-1"</span><span style="color: #007700;">/></span>
<span style="color: #007700;"></completeCondition></span>
<span style="color: #007700;"><onComplete</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$body/Collection"</span> <span style="color: #0000cc;">enclosingElementProperty=</span><span style="background-color: #fff0f0;">"Collections"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><respond/></span>
<span style="color: #007700;"></onComplete></span>
<span style="color: #007700;"></aggregate></span>
<span style="color: #007700;"></outSequence></span>
<span style="color: #007700;"></target></span>
<span style="color: #007700;"><description/></span>
<span style="color: #007700;"></proxy></span>
</pre>
</div>
<br />
Request:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><soapenv:Envelope</span> <span style="color: #0000cc;">xmlns:soapenv=</span><span style="background-color: #fff0f0;">"http://schemas.xmlsoap.org/soap/envelope/"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><soapenv:Header/></span>
<span style="color: #007700;"><soapenv:Body></span>
<span style="color: #007700;"><Collection></span>
<span style="color: #007700;"><Job></span>
<span style="color: #007700;"><Id></span>AAAA<span style="color: #007700;"></Id></span>
<span style="color: #007700;"></Job></span>
<span style="color: #007700;"><Job></span>
<span style="color: #007700;"><Id></span>12345<span style="color: #007700;"></Id></span>
<span style="color: #007700;"></Job></span>
<span style="color: #007700;"><Job></span>
<span style="color: #007700;"><Id></span>12346<span style="color: #007700;"></Id></span>
<span style="color: #007700;"></Job></span>
<span style="color: #007700;"></Collection></span>
<span style="color: #007700;"></soapenv:Body></span>
<span style="color: #007700;"></soapenv:Envelope></span>
</pre>
</div>
<br />
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com1tag:blogger.com,1999:blog-18481069.post-27106512711017447672017-12-19T08:56:00.000+10:302017-12-19T08:56:22.269+10:30WSO2 ESB/EI Callout Mediator Error Scenario<br />
When using WSO2 Enterprise Service Bus, you can use <a href="https://docs.wso2.com/display/ESB490/Call+Mediator" rel="nofollow" target="_blank">Call</a>, <a href="https://docs.wso2.com/display/ESB490/Send+Mediator" rel="nofollow" target="_blank">Send </a>and <a href="https://docs.wso2.com/display/ESB490/Callout+Mediator" rel="nofollow" target="_blank">Callout</a> mediators to invoke a service. If you are calling multiple service calls within your meditation sequence, you have to use either Call mediator or Callout mediator.<br />
<br />
As per the documentation, WSO2 Team is recommending to use Call mediator instead of the Callout mediator, due to much better performance. However, due to some legacy requirements, we might need to stay with Callout mediator for the time being.<br />
<br />
In my use case, there are some mediation scenarios with mutual SSL. So if you have noticed an "UnrecoverableKeyException: Password verification failed" exception in the WSO2Carbon log file and terminal when invoking an endpoint(backend service) using callout mediator, I would recommend you to check the Java SSL keyStore Password(values of the javax.net.ssl.keyStorePassword and javax.net.ssl.trustStorePassword environment variables) in the <esb_home>/bin/wso2server.sh file or relevant location.</esb_home><br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #997700; font-weight: bold;">TID:</span> <span style="color: #333333;">[-</span><span style="color: #0000dd; font-weight: bold;">1234</span><span style="color: #333333;">]</span> <span style="color: #333333;">[]</span> <span style="color: #333333;">[</span><span style="color: #0000dd; font-weight: bold;">2017</span><span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">12</span><span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">16</span> <span style="color: #0000dd; font-weight: bold;">13</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">04</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">28</span><span style="color: #333333;">,</span><span style="color: #0000dd; font-weight: bold;">193</span><span style="color: #333333;">]</span> INFO <span style="color: #333333;">{</span>org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">http</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HTTPSender</span><span style="color: #333333;">}</span> <span style="color: #333333;">-</span> Unable to sendViaPost to url<span style="color: #333333;">[</span><span style="color: #997700; font-weight: bold;">http:</span><span style="color: #888888;">//blog.napagoda.com] {org.apache.axis2.transport.http.HTTPSender} UUID:[d7602d4a-17ac-4b95-b459-7fec3ffa44c0]</span>
java<span style="color: #333333;">.</span><span style="color: #0000cc;">net</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SocketException</span><span style="color: #333333;">:</span> java<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">NoSuchAlgorithmException</span><span style="color: #333333;">:</span> Error constructing implementation <span style="color: #333333;">(</span><span style="color: #997700; font-weight: bold;">algorithm:</span> Default<span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">provider:</span> SunJSSE<span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">class:</span> sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLContextImpl</span>$DefaultSSLContext<span style="color: #333333;">)</span>
at javax<span style="color: #333333;">.</span><span style="color: #0000cc;">net</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">DefaultSSLSocketFactory</span><span style="color: #333333;">.</span><span style="color: #0000cc;">throwException</span><span style="color: #333333;">(</span>SSLSocketFactory<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">248</span><span style="color: #333333;">)</span>
at javax<span style="color: #333333;">.</span><span style="color: #0000cc;">net</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">DefaultSSLSocketFactory</span><span style="color: #333333;">.</span><span style="color: #0000cc;">createSocket</span><span style="color: #333333;">(</span>SSLSocketFactory<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">285</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">commons</span><span style="color: #333333;">.</span><span style="color: #0000cc;">httpclient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">protocol</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLProtocolSocketFactory</span><span style="color: #333333;">.</span><span style="color: #0000cc;">createSocket</span><span style="color: #333333;">(</span>SSLProtocolSocketFactory<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">155</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">commons</span><span style="color: #333333;">.</span><span style="color: #0000cc;">httpclient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HttpConnection</span><span style="color: #333333;">.</span><span style="color: #0000cc;">open</span><span style="color: #333333;">(</span>HttpConnection<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">707</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">commons</span><span style="color: #333333;">.</span><span style="color: #0000cc;">httpclient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">MultiThreadedHttpConnectionManager</span>$HttpConnectionAdapter<span style="color: #333333;">.</span><span style="color: #0000cc;">open</span><span style="color: #333333;">(</span>MultiThreadedHttpConnectionManager<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1361</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">commons</span><span style="color: #333333;">.</span><span style="color: #0000cc;">httpclient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HttpMethodDirector</span><span style="color: #333333;">.</span><span style="color: #0000cc;">executeWithRetry</span><span style="color: #333333;">(</span>HttpMethodDirector<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">387</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">commons</span><span style="color: #333333;">.</span><span style="color: #0000cc;">httpclient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HttpMethodDirector</span><span style="color: #333333;">.</span><span style="color: #0000cc;">executeMethod</span><span style="color: #333333;">(</span>HttpMethodDirector<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">171</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">commons</span><span style="color: #333333;">.</span><span style="color: #0000cc;">httpclient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HttpClient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">executeMethod</span><span style="color: #333333;">(</span>HttpClient<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">397</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">http</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AbstractHTTPSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">executeMethod</span><span style="color: #333333;">(</span>AbstractHTTPSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">688</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">http</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HTTPSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">sendViaPost</span><span style="color: #333333;">(</span>HTTPSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">195</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">http</span><span style="color: #333333;">.</span><span style="color: #0000cc;">HTTPSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">send</span><span style="color: #333333;">(</span>HTTPSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">77</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">http</span><span style="color: #333333;">.</span><span style="color: #0000cc;">CommonsHTTPTransportSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">writeMessageWithCommons</span><span style="color: #333333;">(</span>CommonsHTTPTransportSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">451</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">http</span><span style="color: #333333;">.</span><span style="color: #0000cc;">CommonsHTTPTransportSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">invoke</span><span style="color: #333333;">(</span>CommonsHTTPTransportSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">278</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">engine</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AxisEngine</span><span style="color: #333333;">.</span><span style="color: #0000cc;">send</span><span style="color: #333333;">(</span>AxisEngine<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">442</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">description</span><span style="color: #333333;">.</span><span style="color: #0000cc;">OutInAxisOperationClient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">send</span><span style="color: #333333;">(</span>OutInAxisOperation<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">430</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">description</span><span style="color: #333333;">.</span><span style="color: #0000cc;">OutInAxisOperationClient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">executeImpl</span><span style="color: #333333;">(</span>OutInAxisOperation<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">225</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">client</span><span style="color: #333333;">.</span><span style="color: #0000cc;">OperationClient</span><span style="color: #333333;">.</span><span style="color: #0000cc;">execute</span><span style="color: #333333;">(</span>OperationClient<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">149</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">message</span><span style="color: #333333;">.</span><span style="color: #0000cc;">senders</span><span style="color: #333333;">.</span><span style="color: #0000cc;">blocking</span><span style="color: #333333;">.</span><span style="color: #0000cc;">BlockingMsgSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">sendReceive</span><span style="color: #333333;">(</span>BlockingMsgSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">310</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">message</span><span style="color: #333333;">.</span><span style="color: #0000cc;">senders</span><span style="color: #333333;">.</span><span style="color: #0000cc;">blocking</span><span style="color: #333333;">.</span><span style="color: #0000cc;">BlockingMsgSender</span><span style="color: #333333;">.</span><span style="color: #0000cc;">send</span><span style="color: #333333;">(</span>BlockingMsgSender<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">216</span><span style="color: #333333;">)</span>
<b>at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">builtin</span><span style="color: #333333;">.</span><span style="color: #0000cc;">CalloutMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>CalloutMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd;">180</span><span style="color: #333333;">)</span></b>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AbstractListMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>AbstractListMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">89</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AbstractListMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>AbstractListMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">56</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">base</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SequenceMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>SequenceMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">149</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">base</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SequenceMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>SequenceMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">221</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AbstractListMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>AbstractListMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">89</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AbstractListMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>AbstractListMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">56</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediators</span><span style="color: #333333;">.</span><span style="color: #0000cc;">base</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SequenceMediator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">mediate</span><span style="color: #333333;">(</span>SequenceMediator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">149</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">core</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ProxyServiceMessageReceiver</span><span style="color: #333333;">.</span><span style="color: #0000cc;">receive</span><span style="color: #333333;">(</span>ProxyServiceMessageReceiver<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">197</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">engine</span><span style="color: #333333;">.</span><span style="color: #0000cc;">AxisEngine</span><span style="color: #333333;">.</span><span style="color: #0000cc;">receive</span><span style="color: #333333;">(</span>AxisEngine<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">180</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">passthru</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ServerWorker</span><span style="color: #333333;">.</span><span style="color: #0000cc;">processEntityEnclosingRequest</span><span style="color: #333333;">(</span>ServerWorker<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">395</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">synapse</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">passthru</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ServerWorker</span><span style="color: #333333;">.</span><span style="color: #0000cc;">run</span><span style="color: #333333;">(</span>ServerWorker<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">142</span><span style="color: #333333;">)</span>
at org<span style="color: #333333;">.</span><span style="color: #0000cc;">apache</span><span style="color: #333333;">.</span><span style="color: #0000cc;">axis2</span><span style="color: #333333;">.</span><span style="color: #0000cc;">transport</span><span style="color: #333333;">.</span><span style="color: #0000cc;">base</span><span style="color: #333333;">.</span><span style="color: #0000cc;">threads</span><span style="color: #333333;">.</span><span style="color: #0000cc;">NativeWorkerPool</span>$1<span style="color: #333333;">.</span><span style="color: #0000cc;">run</span><span style="color: #333333;">(</span>NativeWorkerPool<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">172</span><span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">util</span><span style="color: #333333;">.</span><span style="color: #0000cc;">concurrent</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ThreadPoolExecutor</span><span style="color: #333333;">.</span><span style="color: #0000cc;">runWorker</span><span style="color: #333333;">(</span>ThreadPoolExecutor<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1142</span><span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">util</span><span style="color: #333333;">.</span><span style="color: #0000cc;">concurrent</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ThreadPoolExecutor</span>$Worker<span style="color: #333333;">.</span><span style="color: #0000cc;">run</span><span style="color: #333333;">(</span>ThreadPoolExecutor<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">617</span><span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">lang</span><span style="color: #333333;">.</span><span style="color: #0000cc;">Thread</span><span style="color: #333333;">.</span><span style="color: #0000cc;">run</span><span style="color: #333333;">(</span>Thread<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">745</span><span style="color: #333333;">)</span>
Caused <span style="color: #997700; font-weight: bold;">by:</span> java<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">NoSuchAlgorithmException</span><span style="color: #333333;">:</span> Error constructing implementation <span style="color: #333333;">(</span><span style="color: #997700; font-weight: bold;">algorithm:</span> Default<span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">provider:</span> SunJSSE<span style="color: #333333;">,</span> <span style="color: #997700; font-weight: bold;">class:</span> sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLContextImpl</span>$DefaultSSLContext<span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">Provider</span>$Service<span style="color: #333333;">.</span><span style="color: #0000cc;">newInstance</span><span style="color: #333333;">(</span>Provider<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1617</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">jca</span><span style="color: #333333;">.</span><span style="color: #0000cc;">GetInstance</span><span style="color: #333333;">.</span><span style="color: #0000cc;">getInstance</span><span style="color: #333333;">(</span>GetInstance<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">236</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">jca</span><span style="color: #333333;">.</span><span style="color: #0000cc;">GetInstance</span><span style="color: #333333;">.</span><span style="color: #0000cc;">getInstance</span><span style="color: #333333;">(</span>GetInstance<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">164</span><span style="color: #333333;">)</span>
at javax<span style="color: #333333;">.</span><span style="color: #0000cc;">net</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLContext</span><span style="color: #333333;">.</span><span style="color: #0000cc;">getInstance</span><span style="color: #333333;">(</span>SSLContext<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">156</span><span style="color: #333333;">)</span>
at javax<span style="color: #333333;">.</span><span style="color: #0000cc;">net</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLContext</span><span style="color: #333333;">.</span><span style="color: #0000cc;">getDefault</span><span style="color: #333333;">(</span>SSLContext<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">96</span><span style="color: #333333;">)</span>
at javax<span style="color: #333333;">.</span><span style="color: #0000cc;">net</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLSocketFactory</span><span style="color: #333333;">.</span><span style="color: #0000cc;">getDefault</span><span style="color: #333333;">(</span>SSLSocketFactory<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">122</span><span style="color: #333333;">)</span>
<span style="color: #333333;">...</span> <span style="color: #0000dd; font-weight: bold;">33</span> more
Caused <span style="color: #997700; font-weight: bold;">by:</span> java<span style="color: #333333;">.</span><span style="color: #0000cc;">io</span><span style="color: #333333;">.</span><span style="color: #0000cc;">IOException</span><span style="color: #333333;">:</span> Keystore was tampered with<span style="color: #333333;">,</span> or password was incorrect
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">provider</span><span style="color: #333333;">.</span><span style="color: #0000cc;">JavaKeyStore</span><span style="color: #333333;">.</span><span style="color: #0000cc;">engineLoad</span><span style="color: #333333;">(</span>JavaKeyStore<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">780</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">provider</span><span style="color: #333333;">.</span><span style="color: #0000cc;">JavaKeyStore</span>$JKS<span style="color: #333333;">.</span><span style="color: #0000cc;">engineLoad</span><span style="color: #333333;">(</span>JavaKeyStore<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">56</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">provider</span><span style="color: #333333;">.</span><span style="color: #0000cc;">KeyStoreDelegator</span><span style="color: #333333;">.</span><span style="color: #0000cc;">engineLoad</span><span style="color: #333333;">(</span>KeyStoreDelegator<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">224</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">provider</span><span style="color: #333333;">.</span><span style="color: #0000cc;">JavaKeyStore</span>$DualFormatJKS<span style="color: #333333;">.</span><span style="color: #0000cc;">engineLoad</span><span style="color: #333333;">(</span>JavaKeyStore<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">70</span><span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">KeyStore</span><span style="color: #333333;">.</span><span style="color: #0000cc;">load</span><span style="color: #333333;">(</span>KeyStore<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1445</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLContextImpl</span>$DefaultSSLContext<span style="color: #333333;">.</span><span style="color: #0000cc;">getDefaultKeyManager</span><span style="color: #333333;">(</span>SSLContextImpl<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">852</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ssl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">SSLContextImpl</span>$DefaultSSLContext<span style="color: #333333;">.<</span>init<span style="color: #333333;">>(</span>SSLContextImpl<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">732</span><span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">reflect</span><span style="color: #333333;">.</span><span style="color: #0000cc;">GeneratedConstructorAccessor131</span><span style="color: #333333;">.</span><span style="color: #0000cc;">newInstance</span><span style="color: #333333;">(</span>Unknown Source<span style="color: #333333;">)</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">reflect</span><span style="color: #333333;">.</span><span style="color: #0000cc;">DelegatingConstructorAccessorImpl</span><span style="color: #333333;">.</span><span style="color: #0000cc;">newInstance</span><span style="color: #333333;">(</span>DelegatingConstructorAccessorImpl<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">45</span><span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">lang</span><span style="color: #333333;">.</span><span style="color: #0000cc;">reflect</span><span style="color: #333333;">.</span><span style="color: #0000cc;">Constructor</span><span style="color: #333333;">.</span><span style="color: #0000cc;">newInstance</span><span style="color: #333333;">(</span>Constructor<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">423</span><span style="color: #333333;">)</span>
at java<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">Provider</span>$Service<span style="color: #333333;">.</span><span style="color: #0000cc;">newInstance</span><span style="color: #333333;">(</span>Provider<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">1595</span><span style="color: #333333;">)</span>
<span style="color: #333333;">...</span> <span style="color: #0000dd; font-weight: bold;">38</span> more
Caused <span style="color: #997700; font-weight: bold;">by:</span> java<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">UnrecoverableKeyException</span><span style="color: #333333;">:</span> <span style="color: red;">Password verification failed</span>
at sun<span style="color: #333333;">.</span><span style="color: #0000cc;">security</span><span style="color: #333333;">.</span><span style="color: #0000cc;">provider</span><span style="color: #333333;">.</span><span style="color: #0000cc;">JavaKeyStore</span><span style="color: #333333;">.</span><span style="color: #0000cc;">engineLoad</span><span style="color: #333333;">(</span>JavaKeyStore<span style="color: #333333;">.</span><span style="color: #0000cc;">java</span><span style="color: #333333;">:</span><span style="color: #0000dd; font-weight: bold;">778</span><span style="color: #333333;">)</span>
<span style="color: #333333;">...</span> <span style="color: #0000dd; font-weight: bold;">48</span> more
</pre>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-74870911523287873202017-12-10T10:05:00.000+10:302017-12-10T10:05:23.588+10:30WSO2 ESB/EI Send XML content to backend When sending XML content inside the payload to the backend via WSO2 ESB, we have to encode it and send it. In my usecase, I have a Data Service which is accepting XML content as a parameter.<br />
<br />
To implement this requirement, we can't directly define CDATA(blocks of text that are not parsed by XML parser) inside the payload factory mediator. So we have two option to do so.<br />
<br />
The first option is that Encode XML content using Script mediator and use encoded value inside the payload factory mediator. You can read <a href="http://marxsoftware.blogspot.com.au/2013/07/escaping-xml-with-groovy-21.html" rel="nofollow" target="_blank">Hasitha's blog</a> on this topic.<br />
<br />
The second option is storing the format section of the payload factory mediator, in the registry. There you can directly define the CDATA tags inside the XML content stored in the registry. This allows you to define CDATA inside payload factory mediator.<br />
<br />
An example usecase is as below:<br />
<br />
PayloadFacroy Mediator:<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #007700;"><payloadFactory</span> <span style="color: #0000cc;">media-type=</span><span style="background-color: #fff0f0;">"xml"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><format</span> <span style="color: #0000cc;">key=</span><span style="background-color: #fff0f0;">"conf:/format/Common_Error_Message.xml"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><args></span>
<span style="color: #007700;"><arg</span> <span style="color: #0000cc;">evaluator=</span><span style="background-color: #fff0f0;">"xml"</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$ctx:ORIGINAL_MESSAGE"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><arg</span> <span style="color: #0000cc;">expression=</span><span style="background-color: #fff0f0;">"$axis2:HTTP_SC"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"></args></span>
<span style="color: #007700;"></payloadFactory></span>
</pre>
</div>
<br />
Registry Content:<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #007700;"><xs:logError</span> <span style="color: #0000cc;">xmlns:xs=</span><span style="background-color: #fff0f0;">"http://wso2.org/services/data/error"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><xs:originalPayload></span><span style="color: #557799;"><![CDATA[$1]]></span><span style="color: #007700;"></xs:originalPayload></span>
<span style="color: #007700;"><xs:statusCode></span>$2<span style="color: #007700;"></xs:statusCode></span>
<span style="color: #007700;"></xs:logError></span>
</pre>
</div>
<br />Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com1tag:blogger.com,1999:blog-18481069.post-32494076975433432542017-10-14T00:30:00.000+10:302017-10-14T00:30:37.014+10:30Secure Spring Boot REST API using Basic AuthenticationThis is the third post of my Spring Boot Blog post series. In the very first post, I talked about my experience with <a href="http://blog.napagoda.com/2017/09/building-restful-service-using-spring.html" target="_blank">creating RESTFul Services using Spring Boot.</a> Then I have expanded the sample to <a href="http://blog.napagoda.com/2017/09/integrating-swagger-with-spring-boot.html" target="_blank">integrate with Swagger </a>documentation. In this post, I am going to expand above sample with security aspect.<br />
<br />
<b>What is API Security</b><br />
<br />
API Security is a wide area with many different definitions, meanings, and solutions. The main key terms in API security are Authorization, Authentication, Encryption, Federation, and Delegation. However, I am not going to talk about each of them here.<br />
<br />
<b>What is Authentication</b><br />
<br />
Authentication is used to reliably determine the identity of an end user and give access to the resources based on the correctly identified user.<br />
<br />
<b>What is Basic Authentication</b><br />
<br />
Basic Authentication is the simplest way to enforce access controling to resources. Here, the HTTP user agent provides the username and the password when making a request. The string containing the username and password separated by a colon is Base64 encoded before sending to the backend when authentication is required.<br />
<div>
<br /></div>
<b>How to Invoke Basic Auth Protected API</b><br />
<br />
Option 1: Send Authorization header. This value is base64 encoded username:password<br />
<br />
Ex: "Authorization: Basic Y2hhbmRhbmE6Y2hhbmRhbmE="<br />
<br />
<span style="background-color: #cccccc; font-family: "courier new" , "courier" , monospace; font-size: x-small;">curl -X GET http://localhost:8080/admin/hello/chandana -H 'authorization: Basic Y2hhbmRhbmE6Y2hhbmRhbmE='</span><br />
<br />
Option 2: Using URL:<br />
<br />
<span style="background-color: #cccccc;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;">curl -X GET -u username:password http://localhost:8080/admin/hello/chandana</span></span><br />
<br />
<br />
OK, we talked about basic stuff. So let's move to see how to secure a REST API using Spring Security. You can download the initial sample code from my GitHub repo(Swagger Spring Boot Project source code)<br />
<br />
To enhance our previous sample with basic auth security, first I am going to add "spring-boot-starter-security" and "spring-boot-starter-tomcat" dependencies into the pom file.<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"> <span style="color: #888888;"><!-- --></span>
<span style="color: #007700;"><dependency></span>
<span style="color: #007700;"><groupId></span>org.springframework.boot<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>spring-boot-starter-security<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"></dependency></span>
<span style="color: #007700;"><dependency></span>
<span style="color: #007700;"><groupId></span>javax.servlet<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>javax.servlet-api<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"><version></span>3.1.0<span style="color: #007700;"></version></span>
<span style="color: #007700;"></dependency></span>
</pre>
</div>
<br />
Next step is that our configuration class is annotated with @EnableWebSecurity annotation and configuration class is extended from the WebSecurityConfigurerAdapter. The EnableWebSecurity annotation will enable Spring-Security web security support.<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #555555; font-weight: bold;">@Configuration</span>
<span style="color: #555555; font-weight: bold;">@EnableSwagger2</span>
<span style="color: #555555; font-weight: bold;">@EnableWebSecurity</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">ApplicationConfig</span> <span style="color: #008800; font-weight: bold;">extends</span> WebSecurityConfigurerAdapter <span style="color: #333333;">{</span>
</pre>
</div>
<br />
Overridden configure(HttpSecurity) method is used to define which URL paths should be secured and which should not be. In my example "/" and "/api" paths are not required any authentication and any other paths(ex: "admin") should be authenticated with basic auth.<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">protected</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">configure</span><span style="color: #333333;">(</span>HttpSecurity http<span style="color: #333333;">)</span> <span style="color: #008800; font-weight: bold;">throws</span> Exception <span style="color: #333333;">{</span>
http<span style="color: #333333;">.</span><span style="color: #0000cc;">csrf</span><span style="color: #333333;">().</span><span style="color: #0000cc;">disable</span><span style="color: #333333;">();</span>
http<span style="color: #333333;">.</span><span style="color: #0000cc;">authorizeRequests</span><span style="color: #333333;">().</span><span style="color: #0000cc;">antMatchers</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/"</span><span style="color: #333333;">,</span> <span style="background-color: #fff0f0;">"/api/**"</span><span style="color: #333333;">).</span><span style="color: #0000cc;">permitAll</span><span style="color: #333333;">()</span>
<span style="color: #333333;">.</span><span style="color: #0000cc;">anyRequest</span><span style="color: #333333;">().</span><span style="color: #0000cc;">authenticated</span><span style="color: #333333;">();</span>
http<span style="color: #333333;">.</span><span style="color: #0000cc;">httpBasic</span><span style="color: #333333;">().</span><span style="color: #0000cc;">authenticationEntryPoint</span><span style="color: #333333;">(</span>basicAuthenticationPoint<span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
In the configureGlobal(AuthenticationManagerBuilder) method, I have created an in-memory user store with a user called 'chandana'. There I have added username, password, and userole for the in-memory user.<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"> <span style="color: #555555; font-weight: bold;">@Autowired</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">configureGlobal</span><span style="color: #333333;">(</span>AuthenticationManagerBuilder auth<span style="color: #333333;">)</span> <span style="color: #008800; font-weight: bold;">throws</span> Exception <span style="color: #333333;">{</span>
auth<span style="color: #333333;">.</span><span style="color: #0000cc;">inMemoryAuthentication</span><span style="color: #333333;">().</span><span style="color: #0000cc;">withUser</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"chandana"</span><span style="color: #333333;">).</span><span style="color: #0000cc;">password</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"chandana"</span><span style="color: #333333;">).</span><span style="color: #0000cc;">roles</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"USER"</span><span style="color: #333333;">);</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
In Addition to that, you can see that I have added autowired BasicAuthenticationPoint, into my config class. Purpose of the BasicAuthenticationEntryPoint class is to set the "WWW-Authenticate" header to the response. So, web browsers will display a dialog to enter usename and password based on basic authentication mechanism(WWW-Authenticate header)<br />
<br />
Then you can run the sample using "mvn spring-boot:run". When you are accessing "localhost:8080/api/hello/chandana" basic authentication is not required to invoke the api. However, if you try to access the "localhost:8080/admin/hello/chandana" it will be required to provide basic auth credentials to access the resource.<br />
<br />
AppConfig class:<br />
<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> package com.chandana.helloworld.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableWebSecurity
public class ApplicationConfig extends WebSecurityConfigurerAdapter {
@Autowired
private BasicAuthenticationPoint basicAuthenticationPoint;
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(getApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.chandana.helloworld.controllers"))
.paths(PathSelectors.any())
.build();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/", "/api/**").permitAll()
.anyRequest().authenticated();
http.httpBasic().authenticationEntryPoint(basicAuthenticationPoint);
}
private ApiInfo getApiInfo() {
Contact contact = new Contact("Chandana Napagoda", "http://blog.napagoda.com", "cnapagoda@gmail.com");
return new ApiInfoBuilder()
.title("Example Api Title")
.description("Example Api Definition")
.version("1.0.0")
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.contact(contact)
.build();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("chandana").password("chandana").roles("USER");
}
}
</code></pre>
<br />
BasicAuthenticationEntryPoint class:<br />
<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> package com.chandana.helloworld.config;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class BasicAuthenticationPoint extends BasicAuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
throws IOException, ServletException {
response.addHeader("WWW-Authenticate", "Basic realm=" +getRealmName());
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
PrintWriter writer = response.getWriter();
writer.println("HTTP Status 401 - " + authEx.getMessage());
}
@Override
public void afterPropertiesSet() throws Exception {
setRealmName("Chandana");
super.afterPropertiesSet();
}
}
</code></pre>
<br />
You can download <a href="https://github.com/cnapagoda/spring-boot-basic-auth" target="_blank">Spring Boot Basic Auth Project</a> source code from my GitHub repo as well.<br />
<br />Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-57694897551989713842017-09-16T22:53:00.000+09:302018-05-27T17:44:43.836+09:30Introduction to WSO2 Registry Mounting This post is based on the common questions raised about registry mounting and how it works etc. Below are the main questions people ask:<br />
<br />
1). How mounting works?<br />
2). What is the difference between Config Registry and Governance Registry?<br />
3). Can I use databases other than H2 for Local Registry?<br />
4). What is meant by mount path and target path?<br />
5). Do I need to configure “remoteInstance” URL?<br />
6). What should I use as the cacheId?<br />
<br />
So let's start with how to configure a registry mount. When you are configuring the registry mount, you have to add the relevant data source to the master-datasources.xml file. In addition to that, you have to add mounting related configuration into the registry.xml file as well.<br />
<br />
In the master-datasources.xml file you have to just configure a JDBC data source by providing JDBC URL, username, password, validation queries, connection optimization parameters, etc. An example data source entry will look like below. <span style="color: red;">Note: You need to add below configuration in addition to the existing 'WSO2CarbonDB' data source. </span><br />
<br />
<!-- HTML generated using hilite.me -->
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"> <span style="color: #007700;"><datasource></span>
<span style="color: #007700;"><name></span>WSO2CarbonDB_Gov<span style="color: #007700;"></name></span>
<span style="color: #007700;"><description></span>The datasource used for registry- config/governance<span style="color: #007700;"></description></span>
<span style="color: #007700;"><jndiConfig></span>
<span style="color: #007700;"><name></span>jdbc/WSO2CarbonDB_Gov<span style="color: #007700;"></name></span>
<span style="color: #007700;"></jndiConfig></span>
<span style="color: #007700;"><definition</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"RDBMS"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><configuration></span>
<span style="color: #007700;"><url></span>jdbc:mysql://blog.napagoda.com:3306/REGISTRY_DB?autoReconnect=true<span style="color: #007700;"></url></span>
<span style="color: #007700;"><username></span>chandana<span style="color: #007700;"></username></span>
<span style="color: #007700;"><password></span>password<span style="color: #007700;"></password></span>
<span style="color: #007700;"><driverClassName></span>com.mysql.jdbc.Driver<span style="color: #007700;"></driverClassName></span>
<span style="color: #007700;"><maxActive></span>50<span style="color: #007700;"></maxActive></span>
<span style="color: #007700;"><maxWait></span>60000<span style="color: #007700;"></maxWait></span>
<span style="color: #007700;"><testOnBorrow></span>true<span style="color: #007700;"></testOnBorrow></span>
<span style="color: #007700;"><validationQuery></span>SELECT 1<span style="color: #007700;"></validationQuery></span>
<span style="color: #007700;"><validationInterval></span>30000<span style="color: #007700;"></validationInterval></span>
<span style="color: #007700;"></configuration></span>
<span style="color: #007700;"></definition></span>
<span style="color: #007700;"></datasource></span>
</pre>
</div>
In the registry.xml file, there are many vexed areas available. So let’s see an example mounting configuration first.<br />
<div>
<br /></div>
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><dbConfig</span> <span style="color: #0000cc;">name=</span><span style="background-color: #fff0f0;">"mounted_registry"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><dataSource></span>jdbc/WSO2CarbonDB_Gov<span style="color: #007700;"></dataSource></span>
<span style="color: #007700;"></dbConfig></span>
<span style="color: #007700;"><remoteInstance</span> <span style="color: #0000cc;">url=</span><span style="background-color: #fff0f0;">"https://localhost:9443/registry"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><id></span>instanceid<span style="color: #007700;"></id></span>
<span style="color: #007700;"><dbConfig></span>mounted_registry<span style="color: #007700;"></dbConfig></span>
<span style="color: #007700;"><readOnly></span>false<span style="color: #007700;"></readOnly></span>
<span style="color: #007700;"><enableCache></span>true<span style="color: #007700;"></enableCache></span>
<span style="color: #007700;"><registryRoot></span>/<span style="color: #007700;"></registryRoot></span>
<span style="color: #007700;"><cacheId></span>chandana@jdbc:mysql://blog.napagoda.com:3306/REGISTRY_DB?autoReconnect=true</cacheId>
<span style="color: #007700;"></remoteInstance></span>
<span style="color: #007700;"><mount</span> <span style="color: #0000cc;">path=</span><span style="background-color: #fff0f0;">"/_system/config"</span> <span style="color: #0000cc;">overwrite=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><instanceId></span>instanceid<span style="color: #007700;"></instanceId></span>
<span style="color: #007700;"><targetPath></span>/_system/apimconfig<span style="color: #007700;"></targetPath></span>
<span style="color: #007700;"></mount></span>
<span style="color: #007700;"><mount</span> <span style="color: #0000cc;">path=</span><span style="background-color: #fff0f0;">"/_system/governance"</span> <span style="color: #0000cc;">overwrite=</span><span style="background-color: #fff0f0;">"true"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><instanceId></span>instanceid<span style="color: #007700;"></instanceId></span>
<span style="color: #007700;"><targetPath></span>/_system/governance<span style="color: #007700;"></targetPath></span>
<span style="color: #007700;"></mount></span><span style="font-family: "times new roman";"><span style="white-space: normal;">
</span></span></pre>
</div>
<br />
You can see that when defining a mounting configuration, I have added four sections of configurations. They are ‘dbConfig’, ‘remoteInstance’ and two sections of the ‘mount’ entry.<br />
<br />
I think it's easy to explain from the mount entry first, then remoteInstance and dbConfig. In the mount entry, you can configure path, overwrite, targetPath, and instanceId.<br />
<div>
<br /></div>
<b>Mount</b><br />
<br />
<b>path </b>- Path is a location in the registry which is similar to a file system path. Resources stored inside this path will be store in relevant configured DB.<br />
<b>overwrite</b>- (Virtual, True, False)Whether an existing collection/resource at the given path would be overwritten or not. Virtual means changes are only stored in the memory and will not be written into the DB.<br />
<b>instanceId </b>- Reference to the ‘remoteInstance’.<br />
<b>targetPath </b>- The path which is stored in the database.<br />
<br />
In nutshell, any registry paths which are starting with the value in the path section will be stored in the DB against targetPath(path will be replaced with targetPath and stored in the DB). When retrieving registry path it will do the reverse replacement as well. So this target path will not be visible to you at all. If you are too curious to know about that, you can verify it by querying REG_PATH table.<br />
<div>
<br /></div>
<b>remoteInstance </b><br />
<br />
'remoteInstance' is the mapping between 'dbConfig' and Mounts. This mapping is handled via 'id' and 'dbConfig' elements. The 'id' value referred in the each mounting configurations and value of dbConfig element should be same as dbConfig name. In addition to that 'cacheId' is one of the most important configurations in this section.<br />
<br />
<b>url </b>- Registry URL of the local registry instance. This is only used in the WSO2 Governance Registry product. So you can use any value for the other products.<br />
<b>readOnly </b>- Whether the instance is read-only.<br />
<b>registryRoot </b>- The root of the registry instance.<br />
<b>enableCache </b>- Whether caching is enabled or not.<br />
<b>cacheId </b>- This is an unique identification of the remote instance used in distributed caching layer. Here we are recommending to use the cache id as registry DBUsername@DBUrl.<br />
<div>
<br /></div>
<div>
<br />
<b>dbConfig </b><br />
<br />
This dbConfig is a reference to the data source added in the master-datasources.xml file. Note that you should not remove or modify default dbConfig available in the registry.xml file. Instead of that, you need to add a new dbConfig element. Further, as the name of the newly adding dbConfig, you should use a name other than 'wso2registry', since it has been used as the default dbConfig name.<br />
<br />
<br />
So, let me answer to other questions. Any WSO2 product(released before 2018) internally consist three registry spaces. they are local, config and governance.<br />
<br />
Local Registry(repository) is used to store instance specific information such as last index time', etc.<br />
Config Registry(repository) is the place to store information that can only be shared with same products and if multinode product cluster, this section will be shared.<br />
Governance Registry(repository) is the place to store configurations and data that are shared across the whole WSO2 platform.<br />
<br />
We are recommending to store config and governance sections in an external database system. Since the Local Registry(repository) section is instance specific, we are recommending to store it with default H2 database. Information which are stored in the local registry are fail-safe and can be recovered. Please note that if you are willing to store Local section in an external RDBMS, you have to create a separate database(schema) for each instance.<br />
<br />
So let’s move on to validating my mounting configuration. In your 'remoteInstance' configuration you have to correctly refer the dbConfig name. This DB config name should not be the same one which we used for Local Registry. In addition that, you have to properly map each 'mount' section to the 'remoteInstance' using the instanceId.<br />
<br />
If you have any questions which are related to registry mounting, you can comment here. I am happy to help you.</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-13978361828887573432017-09-12T00:04:00.000+09:302017-09-12T00:45:09.308+09:30Integrating Swagger with Spring Boot REST APIIn the last post, I talked about my experience with <a href="http://blog.napagoda.com/2017/09/building-restful-service-using-spring.html" target="_blank">creating RESTFul Services using Spring Boot</a>. When creating a REST API, proper documentation is a mandatory part of it.<br />
<b><br /></b> <b>What is Swagger?</b><br />
<br />
<a href="https://swagger.io/" rel="nofollow" target="_blank">Swagger</a>(Swagger 2) is a specification for describing and documenting a REST API. It specifies the format of the REST web services including URL, Resources, methods, etc. Swagger will generate documentation from the application code and handle the rendering part as well.<br />
<br />
In this post, I am going to integrate Swagger 2 documentation into a Spring Boot based REST web service. So I am going to use <a href="http://springfox.github.io/springfox/" rel="nofollow" target="_blank">Springfox</a> implementation to generate the swagger documentation. If you want to know how to run/build Spring Boot project, please refer my previous post.<br />
<br />
Springfox provides two dependencies to generate API Doc and Swagger UI. If you are not expecting to integrate Swagger UI into your API level, no need to add Swagger UI dependency.<br />
<div>
<br /></div>
<div>
<dependency><br />
<groupId>io.springfox</groupId><br />
<artifactId>springfox-swagger2</artifactId><br />
<version>2.7.0</version><br />
</dependency><br />
<br />
<dependency><br />
<groupId>io.springfox</groupId><br />
<artifactId>springfox-swagger-ui</artifactId><br />
<version>2.7.0</version><br />
</dependency></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
@<a href="http://springfox.github.io/springfox/javadoc/2.5.0/springfox/documentation/swagger2/annotations/EnableSwagger2.html" rel="nofollow" target="_blank">EnableSwagger2</a> annotation enables Springfox Swagger support in the class. To document the service, Springfox uses a Docket. The Docket helps to configure a subset of the services to be documented and group them by a name, etc. The most hidden concept is that the Springfox works by examining an application at runtime using API semantics based on spring configurations. In other words, you have to create a Spring Java Configuration class which uses spring’s @Configuration<br />
<br />
In My example, I am generating a swagger documentation based on the RestController classes I have added.</div>
<div>
<br /></div>
<div>
<br /></div>
</div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class ApplicationConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.chandana.helloworld.controllers"))
.paths(PathSelectors.any())
.build();
}
}
</code></pre>
<br />
Since I have added two controllers, this will group(tag) each controller related APIs separately.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsQVhAzw4NL4IhkEqm_5Prlj9JaY2JFwEu4NQmTY-QFxHSHUf40YQdBQYZlG96fmtlql024IR4PLAey-qICgKGFieSJVMxg7Bqo0DkIWyupK3P2a_fYON42FGRlq6gw04D3warow/s1600/basic+swagger+ui.png" imageanchor="1"><img alt="Generated Swagger UI " border="0" data-original-height="604" data-original-width="1378" height="175" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsQVhAzw4NL4IhkEqm_5Prlj9JaY2JFwEu4NQmTY-QFxHSHUf40YQdBQYZlG96fmtlql024IR4PLAey-qICgKGFieSJVMxg7Bqo0DkIWyupK3P2a_fYON42FGRlq6gw04D3warow/s400/basic+swagger+ui.png" title="Generated Swagger UI " width="400" /></a></div>
<br />
<br />
Out of the box, Springfox provides five predicates and they are any, none, withClassAnnotation, withMethodAnnotation and basePackage.<br />
<div>
<br /></div>
<b>ApiInfo</b><br />
<br />
Swagger provides some default values such as “API Documentation”, “Created by Contact Email”, “Apache 2.0”. So you can change these default values by adding apiInfo(ApiInfo apiInfo) method. The ApiInfo class contains custom information about the API.<br />
<div>
<br /></div>
<div>
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(getApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.chandana.helloworld.controllers"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo getApiInfo() {
Contact contact = new Contact("Chandana Napagoda", "http://blog.napagoda.com", "cnapagoda@gmail.com");
return new ApiInfoBuilder()
.title("Example Api Title")
.description("Example Api Definition")
.version("1.0.0")
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.contact(contact)
.build();
}
</code></pre>
<div>
<br /></div>
<div>
Once ApiInfo is added, the generated documentation looks similar to this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL1M0TfnMv-4O4UU3jcfTFPjh1AIPwFcwlcRb6XaQ01raT4NuvTaQYSxkRfZLBmxabqSi1kTTISI_zoB17xq9fdg_K8dhhsHgZcFPYgvCvP-PaJHC_gPLW-ZPjYMj0IhR73tcC3A/s1600/swagger-with-appinfo.png" imageanchor="1"><img alt="Swagger UI with App Info" border="0" data-original-height="522" data-original-width="1250" height="166" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL1M0TfnMv-4O4UU3jcfTFPjh1AIPwFcwlcRb6XaQ01raT4NuvTaQYSxkRfZLBmxabqSi1kTTISI_zoB17xq9fdg_K8dhhsHgZcFPYgvCvP-PaJHC_gPLW-ZPjYMj0IhR73tcC3A/s400/swagger-with-appinfo.png" title="Swagger UI with App Info" width="400" /></a></div>
<br />
<b><br /></b> <b>Controller and POJO Level Documentation</b><br />
<br />
@Api annotation is used to explain each rest controller class.<br />
@ApiOperation annotation is used to explain to describe the resources and methods.<br />
@ApiResponse annotation is used to explain to describe other responses that can be returned by the operation.ex: 200 ok or 202 accepted, etc.<br />
@ApiModelProperty annotation to describe the properties of the POJO(Bean) class.<br />
<br />
After adding above annotation, final generated swagger documentation looks like below:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpzmyVqKAR9JCu0xoG1g05OsYpYIML3zaNjzM7fv_ULlvCHVA5IHQP9wpPCbVSVVnbzuhlgidobjRVFeUp2PBBvpYG3cloFrB2gUTVhJ4-pg6w7jNvjI393Xv_5QINoFYbQYuJmg/s1600/final-swagger-ui.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Complex and Beautiful REST Documentation with Swagger" border="0" data-original-height="922" data-original-width="1207" height="305" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpzmyVqKAR9JCu0xoG1g05OsYpYIML3zaNjzM7fv_ULlvCHVA5IHQP9wpPCbVSVVnbzuhlgidobjRVFeUp2PBBvpYG3cloFrB2gUTVhJ4-pg6w7jNvjI393Xv_5QINoFYbQYuJmg/s400/final-swagger-ui.png" title="Complex and Beautiful REST Documentation with Swagger" width="400" /></a></div>
<br /></div>
<div>
<br /></div>
<div>
<div>
Spring RestController class:</div>
<div>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
package com.chandana.helloworld.controllers;
import com.chandana.helloworld.bean.Greeting;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
@Api(value = "user", description = "Rest API for user operations", tags = "User API")
public class HelloWorldController {
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET, produces = "application/json")
@ApiOperation(value = "Display greeting message to non-admin user", response = Greeting.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 404, message = "The resource not found")
}
)
public Greeting message(@PathVariable String name) {
Greeting msg = new Greeting(name, "Hello " + name);
return msg;
}
}
</code></pre>
<br /></div>
<div>
Greeting model class:</div>
<div>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
package com.chandana.helloworld.bean;
import io.swagger.annotations.ApiModelProperty;
public class Greeting {
@ApiModelProperty(notes = "Provided user name", required =true)
private String player;
@ApiModelProperty(notes = "The system generated greeting message" , readOnly =true)
private String message;
public Greeting(String player, String message) {
this.player = player;
this.message = message;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
</code></pre>
<br /></div>
<div>
AppConfig class:</div>
<div>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: "andale mono" , "lucida console" , "monaco" , "fixed" , monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
package com.chandana.helloworld.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class ApplicationConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(getApiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.chandana.helloworld.controllers"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo getApiInfo() {
Contact contact = new Contact("Chandana Napagoda", "http://blog.napagoda.com", "cnapagoda@gmail.com");
return new ApiInfoBuilder()
.title("Example Api Title")
.description("Example Api Definition")
.version("1.0.0")
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
.contact(contact)
.build();
}
}
</code></pre>
<br /></div>
<div>
You can download <a href="https://github.com/cnapagoda/spring-boot-swagger" target="_blank">Swagger Spring Boot Project source code</a> from my GitHub repo as well.</div>
</div>
<div>
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-35350591194577917832017-09-08T02:37:00.001+09:302017-09-12T10:58:15.885+09:30Building a RESTFul Service using Spring BootEveryone is talking about Microservices such as <a href="http://wso2.com/products/microservices-framework-for-java/" rel="nofollow" target="_blank">WSO2 Microservice Framework</a>, <a href="https://projects.spring.io/spring-boot/" rel="nofollow" target="_blank">Spring Boot</a>, etc. Since I haven't worked on any Spring related project since a very long time, I thought to implement a simple RESTFul service using Spring Boot.<br />
<br />
So I started with Spring documentation. It is straightforward. You can create the structure of your project using "<a href="http://start.spring.io/" rel="nofollow" target="_blank">Spring Initializr</a>". This is an online tool where you can add all the desired dependencies to your project POM file. Since I am a big fan of Maven, I am generating a maven project.<br />
<br />
In the Spring Initializr UI, you can choose the Language, Spring Boot Version, Project Group ID, artifact name, etc. Please refer below screenshot for information I have provided while generating the project.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibozwxW9YyEbK50k7M-5QOgxcNW9LQLdSXwdAVsIIQ674t1Q6k6ybyi01SMmqNom64Br7UinckXEL5QDut5qMwLY2YNVWP0J-XvTiOG3Yv_yX6CZKy6hBOuuXAjlzo1X7eR-5D_g/s1600/Spring+Initializr+%25282%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Spring Initializr view" border="0" data-original-height="776" data-original-width="1600" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibozwxW9YyEbK50k7M-5QOgxcNW9LQLdSXwdAVsIIQ674t1Q6k6ybyi01SMmqNom64Br7UinckXEL5QDut5qMwLY2YNVWP0J-XvTiOG3Yv_yX6CZKy6hBOuuXAjlzo1X7eR-5D_g/s400/Spring+Initializr+%25282%2529.png" title="Spring Initializr view" width="400" /></a></div>
<br />
<div>
<br /></div>
When clicking on "Generate Project", it will download zipped maven project into your computer. Unzip it and import into an IDE. The initial project structure is like below.<br />
<div>
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEistvSJr_pbZlv2I9VEsObtAIgXwxHIP9gcry6k04ObqGNarcbMKaRuVElwC2MehRoKbGJWgb_A-Ea8CaOuxOx3eIHaoWxM5WOcSwpbwFsRkCI-90ZaK54fkIaXw9B2T-s20yOtHw/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Spring Boot project view" border="0" data-original-height="465" data-original-width="448" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEistvSJr_pbZlv2I9VEsObtAIgXwxHIP9gcry6k04ObqGNarcbMKaRuVElwC2MehRoKbGJWgb_A-Ea8CaOuxOx3eIHaoWxM5WOcSwpbwFsRkCI-90ZaK54fkIaXw9B2T-s20yOtHw/s200/2.png" title="Spring Boot project view" width="192" /></a></div>
<br />
In my HelloWorld REST service implementation, it accepts user's name as a path parameter(or URL parameter) and returns a greeting JSON payload(response). So I am expecting to invoke my REST service by calling below URL: APP_NAME/api/hello/chandana.<br />
<br />
The <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RestController.html" rel="nofollow" target="_blank">@RestController</a> is a way to implement RESTFul service using Spring. So, this new controller class is going to name as HelloWorldController. @RequestMapping annotation maps HTTP requests to the handler. This @RequestMapping annotation can be used in class-level and/or method-level as well. If you have multiple request mappings for a method or class, you can add one @RequestMapping annotation with a list of values. So my HelloWorldController class looks like below.<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">chandana</span><span style="color: #333333;">.</span><span style="color: #0000cc;">helloworld</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">com.chandana.helloworld.bean.Greeting</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.web.bind.annotation.PathVariable</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.web.bind.annotation.RequestMapping</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.web.bind.annotation.RestController</span><span style="color: #333333;">;</span>
<span style="color: #555555; font-weight: bold;">@RestController</span>
<span style="color: #555555; font-weight: bold;">@RequestMapping</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/api"</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">HelloWorldController</span> <span style="color: #333333;">{</span>
<span style="color: #555555; font-weight: bold;">@RequestMapping</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/"</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">welcome</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span><span style="color: #888888;">//Welcome page, non-rest</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="background-color: #fff0f0;">"Welcome to RestTemplate Example."</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@RequestMapping</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/hello/{name}"</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">public</span> Greeting <span style="color: #0066bb; font-weight: bold;">message</span><span style="color: #333333;">(</span><span style="color: #555555; font-weight: bold;">@PathVariable</span> String name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Greeting msg <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Greeting<span style="color: #333333;">(</span>name<span style="color: #333333;">,</span> <span style="background-color: #fff0f0;">"Hello "</span> <span style="color: #333333;">+</span> name<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">return</span> msg<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
Note: If you notice Spring Boot 1.5.6 not importing classes correctly and displaying an error message as "Cannot resolve symbol RestController" in your IDE, you need to downgrade the spring version that is used in the project. Spring Boot 1.5.6 by default uses Spring 4.3.10.RELEASE dependency and it need to be downgraded to 4.3.9.RELEASE. So please add <spring.version>4.3.9.RELEASE</spring.version> on the properties section of your POM file.<br />
<div>
<br /></div>
So everything is in place. I can build and run Spring Boot project using below maven command. It will compile the project and run it.<br />
<br />
<div style="text-align: center;">
<b>mvn spring-boot:run</b></div>
<br />
While starting the server you can notice registered REST service URL in the console like below<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">INFO 9556 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "<b>{[/api/hello/{name}]}</b>" onto public com.chandana.helloworld.bean.Greeting com.chandana.helloworld.<b>HelloWorldController</b>.<b>message</b>(java.lang.String)</span><br />
<div>
<span style="font-family: "courier new" , "courier" , monospace;">INFO 9556 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "<b>{[/api/]}</b>" onto public java.lang.String com.chandana.helloworld.<b>HelloWorldController</b>.<b>welcome</b>()2017-0</span><br />
Finally, Can invoke REST Service by accessing this URL: http://localhost:8080/api/hello/<b>NAME</b><br />
<br />
<b>Final Project Structure:</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6X7A1Bn3gHOcO-w18JW6r7nJ1tngwyjxF5iD7Nd_5FWFQ5aeMzDqacuZC3daNTJAc6FDVdam_tw3pKoEFPsknKIXsV-j9rNH_x8XQMEKulDGEByVfSjJRrHP7X4lXE_tmjRsmHw/s1600/final+project.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Spring Boot REST API project view" border="0" data-original-height="601" data-original-width="476" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6X7A1Bn3gHOcO-w18JW6r7nJ1tngwyjxF5iD7Nd_5FWFQ5aeMzDqacuZC3daNTJAc6FDVdam_tw3pKoEFPsknKIXsV-j9rNH_x8XQMEKulDGEByVfSjJRrHP7X4lXE_tmjRsmHw/s320/final+project.png" title="Spring Boot REST API project view" width="252" /></a></div>
<br />
<br />
<b>Greeting POJO class:</b><br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">chandana</span><span style="color: #333333;">.</span><span style="color: #0000cc;">helloworld</span><span style="color: #333333;">.</span><span style="color: #0000cc;">bean</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">Greeting</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">private</span> String player<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">private</span> String message<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">Greeting</span><span style="color: #333333;">(</span>String player<span style="color: #333333;">,</span> String message<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">player</span> <span style="color: #333333;">=</span> player<span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">message</span> <span style="color: #333333;">=</span> message<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getPlayer</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> player<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setPlayer</span><span style="color: #333333;">(</span>String player<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">player</span> <span style="color: #333333;">=</span> player<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">getMessage</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">return</span> message<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">setMessage</span><span style="color: #333333;">(</span>String message<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">this</span><span style="color: #333333;">.</span><span style="color: #0000cc;">message</span> <span style="color: #333333;">=</span> message<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
<b>POM XML:</b><br />
<b><br /></b> <!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?xml version="1.0" encoding="UTF-8"?></span>
<span style="color: #007700;"><project</span> <span style="color: #0000cc;">xmlns=</span><span style="background-color: #fff0f0;">"http://maven.apache.org/POM/4.0.0"</span> <span style="color: #0000cc;">xmlns:xsi=</span><span style="background-color: #fff0f0;">"http://www.w3.org/2001/XMLSchema-instance"</span>
<span style="color: #0000cc;">xsi:schemaLocation=</span><span style="background-color: #fff0f0;">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span><span style="color: #007700;">></span>
<span style="color: #007700;"><modelVersion></span>4.0.0<span style="color: #007700;"></modelVersion></span>
<span style="color: #007700;"><groupId></span>com.chandana<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>helloworld<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"><version></span>0.0.1-SNAPSHOT<span style="color: #007700;"></version></span>
<span style="color: #007700;"><packaging></span>jar<span style="color: #007700;"></packaging></span>
<span style="color: #007700;"><name></span>helloworld<span style="color: #007700;"></name></span>
<span style="color: #007700;"><description></span>Demo project for Spring Boot<span style="color: #007700;"></description></span>
<span style="color: #007700;"><parent></span>
<span style="color: #007700;"><groupId></span>org.springframework.boot<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>spring-boot-starter-parent<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"><version></span>1.5.6.RELEASE<span style="color: #007700;"></version></span>
<span style="color: #007700;"><relativePath/></span> <span style="color: #888888;"><!-- lookup parent from repository --></span>
<span style="color: #007700;"></parent></span>
<span style="color: #007700;"><properties></span>
<span style="color: #007700;"><project.build.sourceEncoding></span>UTF-8<span style="color: #007700;"></project.build.sourceEncoding></span>
<span style="color: #007700;"><project.reporting.outputEncoding></span>UTF-8<span style="color: #007700;"></project.reporting.outputEncoding></span>
<span style="color: #007700;"><java.version></span>1.8<span style="color: #007700;"></java.version></span>
<span style="color: #007700;"><spring.version></span>4.3.9.RELEASE<span style="color: #007700;"></spring.version></span>
<span style="color: #007700;"></properties></span>
<span style="color: #007700;"><dependencies></span>
<span style="color: #007700;"><dependency></span>
<span style="color: #007700;"><groupId></span>org.springframework.boot<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>spring-boot-starter-web<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"></dependency></span>
<span style="color: #007700;"><dependency></span>
<span style="color: #007700;"><groupId></span>org.springframework.boot<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>spring-boot-starter-test<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"><scope></span>test<span style="color: #007700;"></scope></span>
<span style="color: #007700;"></dependency></span>
<span style="color: #007700;"></dependencies></span>
<span style="color: #007700;"><build></span>
<span style="color: #007700;"><plugins></span>
<span style="color: #007700;"><plugin></span>
<span style="color: #007700;"><groupId></span>org.springframework.boot<span style="color: #007700;"></groupId></span>
<span style="color: #007700;"><artifactId></span>spring-boot-maven-plugin<span style="color: #007700;"></artifactId></span>
<span style="color: #007700;"></plugin></span>
<span style="color: #007700;"></plugins></span>
<span style="color: #007700;"></build></span>
<span style="color: #007700;"></project></span>
</pre>
</div>
<b><br /></b> <b>HelloWorldController class:</b><br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">package</span> com<span style="color: #333333;">.</span><span style="color: #0000cc;">chandana</span><span style="color: #333333;">.</span><span style="color: #0000cc;">helloworld</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">com.chandana.helloworld.bean.Greeting</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.web.bind.annotation.PathVariable</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.web.bind.annotation.RequestMapping</span><span style="color: #333333;">;</span>
<span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">org.springframework.web.bind.annotation.RestController</span><span style="color: #333333;">;</span>
<span style="color: #555555; font-weight: bold;">@RestController</span>
<span style="color: #555555; font-weight: bold;">@RequestMapping</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/api"</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">HelloWorldController</span> <span style="color: #333333;">{</span>
<span style="color: #555555; font-weight: bold;">@RequestMapping</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/"</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">public</span> String <span style="color: #0066bb; font-weight: bold;">welcome</span><span style="color: #333333;">()</span> <span style="color: #333333;">{</span><span style="color: #888888;">//Welcome page, non-rest</span>
<span style="color: #008800; font-weight: bold;">return</span> <span style="background-color: #fff0f0;">"Welcome to RestTemplate Example."</span><span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@RequestMapping</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"/hello/{name}"</span><span style="color: #333333;">)</span>
<span style="color: #008800; font-weight: bold;">public</span> Greeting <span style="color: #0066bb; font-weight: bold;">message</span><span style="color: #333333;">(</span><span style="color: #555555; font-weight: bold;">@PathVariable</span> String name<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
Greeting msg <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Greeting<span style="color: #333333;">(</span>name<span style="color: #333333;">,</span> <span style="background-color: #fff0f0;">"Hello "</span> <span style="color: #333333;">+</span> name<span style="color: #333333;">);</span>
<span style="color: #008800; font-weight: bold;">return</span> msg<span style="color: #333333;">;</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
</pre>
</div>
<br />
<b>Conclusion:</b> As it seems, it is very straightforward to implement RESTFul services using Spring Boot. So I got an idea to implement backend of my “<a href="https://play.google.com/store/apps/details?id=com.chandana.marketprice&hl=en" rel="nofollow" target="_blank">Yield Price Sri Lanka</a>” android app using Spring Boot. Besides, hoping to implement an Admin UI to manage price and commodity information and also a public web UI to display price details for users who don't have an Android app. Keep in touch.<br />
<div>
<br /></div>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-71791902993718218702017-08-08T03:45:00.002+09:302017-08-08T03:45:46.456+09:30Java 8 lambda expression for list/array conversion<br />
1). Convert List<string> to List<integer> ( List of Strings to List of Integers)<br /><br />List<Integer> <integer> integerList = stringList.stream().map(Integer::parseInt).collect(Collectors.toList()); </integer></integer></string><br />
<div>
<br /></div>
<div>
// the longer full lambda version: </div>
<div>
List<Integer> <integer> integerList = stringList.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList());</integer></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
2). Convert List<string> to int[](List of Strings to int array)</string></div>
<div>
<br /></div>
<div>
int[] intArray = stringList.stream().mapToInt(Integer::parseInt).toArray();</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
3). Convert String[] to List<integer> ( String array to List of Integers)</integer></div>
<div>
<br /></div>
<div>
List<Integer> <integer> integerList = Stream.of(array).map(Integer::parseInt).collect(Collectors.toList());</integer></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
4). Convert String[] to int[] (String array to int array)</div>
<div>
<br /></div>
<div>
int[] intArray = Stream.of(stringArray).mapToInt(Integer::parseInt).toArray();</div>
<div>
<br /></div>
<div>
5). Convert String[] to List<double> (String array to Double List)</double></div>
<div>
<br /></div>
<div>
List<Double><double> doubleList = Stream.of(stringArray).map(Double::parseDouble).collect(Collectors.toList());</double></div>
<div>
<br /></div>
<div>
6). Convert int[] to String[] (int array to String array)</div>
<div>
<br /></div>
<div>
String[] stringArray = Arrays.stream(intArray).mapToObj(Integer::toString).toArray(String[]::new);</div>
<div>
<br /></div>
<div>
7). Convert 2D int[][] to List<list nteger="">> ( 2D int array to nested Integer List)</list></div>
<div>
<br /></div>
<div>
List<Integer> list = Arrays.stream(dataSet).map(Arrays::asList).collect(Collectors.toList());</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-19816957915104161182017-08-01T11:47:00.000+09:302017-08-01T12:06:53.327+09:30Manage Solr Data in WSO2 ServerRecently I was checking an issue faced by one of my colleague while automating <a href="http://wso2.com/api-management/#download" rel="nofollow" target="_blank">WSO2 API Manager</a> deployment. There, once the new pack is deployed by pointing to the existing databases, APIM Store didn't show existing APIs at once. It took some time to display all the existing APIs in the Store.<br />
<br />
The APIs are retrieved using the Solr based indexing in APIM. Therefore, the main reason for this behavior is that a fresh pack doesn't have existing Solr data and it takes some time to complete the indexing. Until that indexing process is completed, it will not show API in the Store instantly.<br />
<br />
To address this, you can follow one of the below approaches:<br />
<br />
1). Backup existing Solr data (<b>APIM_HOME/solr/data</b>) from the existing deployment and added it to newly created pack.<br />
<img src="https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif" /><br />
<br />
2). Externalize Solr data directory. Solr data stored location can be configured via <b>core.properties</b> file located in the <b>APIM_HOME/repository/conf/solr/registry-indexing</b> directory. So you can update core.properties to store Solr data outside the product directory.Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-54839331335057918572017-05-24T01:08:00.001+09:302017-09-11T16:32:42.298+09:30Lifecycle Managment with Governance PublisherWSO2 Governance Registry (WSO2 G-Reg) is a fully open source product for SOA governance. In G-Reg 5.0.0 release, we have introduced a revolutionary enterprise publisher and store for asset management. As I explained in my previous post, the Lifecycle of an asset is one of the critical requirements of enterprise asset management.<br />
<br />
<b>G-Reg Publisher Lifecycle Management: </b><br />
<br />
With WSO2 Governance Registry 5.3.0, we have introduced a new Lifecycle management feature for publisher application as well. After enabling lifecycle management in the publisher, you will be able to see new lifecycle management UI as below.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZVwGTYzM7Pq6G4XktbSPjiI-IgOwhvu6BSq0Y75wjVoNFQp137AD8KzuDiMUKi4MMCDIi2xbGIVIiVVFeX3IY2voVD_-0x0GVw1z3nrvhd0cJfT93CUaIS5PqLxNpNHHJdbP_cQ/s1600/Screenshot+from+2017-05-21+13-59-33.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="295" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZVwGTYzM7Pq6G4XktbSPjiI-IgOwhvu6BSq0Y75wjVoNFQp137AD8KzuDiMUKi4MMCDIi2xbGIVIiVVFeX3IY2voVD_-0x0GVw1z3nrvhd0cJfT93CUaIS5PqLxNpNHHJdbP_cQ/s400/Screenshot+from+2017-05-21+13-59-33.png" width="400" /></a></div>
<br />
<br />
This lifecycle management can be enabled for one asset type or all the generic asset types(RXT based). If you are enabling this for all the assets, you have to change '<b>lifecycleMgtViewEnabled</b>' value as true in the asset js file located in the GREG_HOME/repository/deployment/server/jaggeryapps/publisher/extensions/assets/default directory. By default, this publisher based lifecycle management has been disabled.<br />
<br />
<br />
If you want to enable publisher lifecycle management for a specific asset type, you have to add above attribute(<b>lifecycleMgtViewEnabled:true</b>) under lifecycle option in the asset js file.<br />
<pre> meta: {
ui: {
icon: 'fw fw-rest-service'
},
lifecycle: {
commentRequired: false,
defaultAction: '',
deletableStates: ['*'],
defaultLifecycleEnabled: false,
publishedStates: ['Published'],
lifecycleMgtViewEnabled:true
}
},
</pre>
<b>G-Reg Publisher Lifecycle Inputs: </b><pre>
</pre>
If you are using G-Reg 5.3.0, you can pass asset authors inputs from publisher UI to backend executor using "transitionInput'. Using lifecycle configurations, we can define this "transitionInput" for the each lifecycle operation available in a given state. <div>
<br /></div>
<div>
Example Lifecycle 'transitionInput' configuration:</div>
<div>
<br /></div>
<div>
<div>
<data name="transitionInput"></div>
<div>
<inputs forEvent="Promote"></div>
<div>
<input name="URL" required="true" label="Endpoint URL" tooltip="APIM Endpoint URL"/></div>
<div>
<input name="Username" required="true" label="Business Username" tooltip="Business owner name"/></div>
<div>
</inputs> </div>
<div>
</data></div>
<pre>
</pre>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-81491638710100012722017-04-10T18:13:00.000+09:302018-06-27T18:28:31.348+09:30How to clean Registry property (REG_PROPERTY) tablesIn WSO2 Carbon 4 based products, REG_PROPERTY and REG_RESOURCE_PROPERTY tables are getting added with a new set of properties per each resource update. Therefore, these tables will grow over time and it could cause a performance impact.<div>
<br /></div>
<div>
As a workaround, you can clean old properties by using below SQL commands:</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">CREATE TABLE TEMP_REG_RESOURCE_PROPERTY AS (SELECT REG_PROPERTY_ID FROM REG_RESOURCE_PROPERTY WHERE REG_PATH_ID IN (SELECT REG_PATH_ID FROM REG_RESOURCE));</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">INSERT INTO TEMP_REG_RESOURCE_PROPERTY(SELECT REG_PROPERTY_ID FROM REG_RESOURCE_PROPERTY WHERE REG_VERSION IN (SELECT REG_VERSION FROM REG_RESOURCE));</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">DELETE FROM REG_RESOURCE_PROPERTY WHERE REG_PROPERTY_ID NOT IN (SELECT REG_PROPERTY_ID FROM TEMP_REG_RESOURCE_PROPERTY);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">DELETE FROM REG_PROPERTY WHERE REG_ID NOT IN (SELECT REG_PROPERTY_ID FROM TEMP_REG_RESOURCE_PROPERTY);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">DROP TABLE TEMP_REG_RESOURCE_PROPERTY;</span></div>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-10274129170172292452017-02-19T21:42:00.000+10:302017-02-19T21:42:06.480+10:30How to clean Registry log (REG_LOG) tableIf you are using WSO2 Governance Registry or API Manager product, you might be already aware that all the registry related actions are being logged. This REG_LOG table being read for Solr indexing(store and publisher searching). Based on the REG_LOG table entries we are indexing artifact metadata. However, with the time this table size might grow. So as a maintain step you can clean up obsolete records from that table.<br />
<br />
So you can use below query to delete obsolete records from REG_LOG table.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 12.8px;">DELETE n1 FROM </span><span class="il" style="background-color: white; font-size: 12.8px;">REG_LOG</span><span style="background-color: white; font-size: 12.8px;"> n1, </span><span class="il" style="background-color: white; font-size: 12.8px;">REG_LOG</span><span style="background-color: white; font-size: 12.8px;"> n2 WHERE n1.REG_LOG_ID < n2.REG_LOG_ID AND n1.REG_PATH = n2.REG_PATH AND n1.REG_TENANT_ID = n2.REG_TENANT_ID;</span><br style="background-color: white; font-size: 12.8px;" /><br style="background-color: white; font-size: 12.8px;" /><span style="background-color: white; font-size: 12.8px;">DELETE FROM </span><span class="il" style="background-color: white; font-size: 12.8px;">REG_LOG</span><span style="background-color: white; font-size: 12.8px;"> WHERE REG_ACTION = 7;</span></span>Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-51046898954801315602017-02-05T03:42:00.000+10:302017-02-05T03:42:27.999+10:30WSO2 Governance Registry Lifecycle transition inputsWSO2 Governance Registry (WSO2 G-Reg) is a fully open source product for governing SOA deployments, which provides many extension points to ensure your business policies. With G-Reg 5.0.0 release, we have introduced revolutionary UIs for enterprise asset management and discovery. <div>
<br /></div>
The Lifecycle of an asset is one of the critical requirements of enterprise asset management and Lifecycle management is focused on various state changes in a given artifact through different phases. If you want to read more about this, please go through my article on "<a href="http://wso2.com/library/articles/2015/07/wso2-governance-registry-governance-framework-extension-points/" rel="nofollow" target="_blank">Governance Framework Extension Points</a>."<div>
<br /></div>
<div>
So here I am going to talk about, one of the feature enhancements which we added for G-Reg 5.3.0. With G-Reg 5.3.0, we have introduced lifecycle transition input for G-Reg publisher. With lifecycle transition inputs, you will be able to parse custom inputs from a user who is doing lifecycle operation. </div>
<div>
<br /></div>
<div>
As an example, you have integrated wso2 governance registry with API Management product using lifecycle executor. So when lifecycle transition happens G-Reg executor will create an API in an external API management product. So instead of defining APIM username password in the lifecycle configuration, using lifecycle transition inputs, you can popup an UI to provide credentials. These inputs can be directly accessed via lifecycle executor class. </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Use of Lifecycle Inputs:</div>
<div>
<br /></div>
<div>
<div>
<data name="transitionInput"></div>
<div>
<inputs forEvent="Promote"></div>
<div>
<input name="url" label="URL" tooltip="URL of APIM server"/></div>
<div>
<input name="userName" label="User Name" tooltip="User Name"/></div>
<div>
<input name="availability" label="Availability" tooltip="Availability Type"/></div>
<div>
</inputs> </div>
<div>
</data></div>
</div>
<div>
<br /></div>
<div>
Output:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgey5QxpEHlhPXekCSsC2w3myLSgfIKBvX-rklU6OaLKTLdrmFJ0NjTXrnqSJWvkaEgSMVlFCfsLdUK4ljD5iccTMeOIpy7ns90JIYqLn89WwRBqzghVyncVQscedtkkVLn0Vxkig/s1600/Screenshot+from+2017-02-04+22-38-04.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgey5QxpEHlhPXekCSsC2w3myLSgfIKBvX-rklU6OaLKTLdrmFJ0NjTXrnqSJWvkaEgSMVlFCfsLdUK4ljD5iccTMeOIpy7ns90JIYqLn89WwRBqzghVyncVQscedtkkVLn0Vxkig/s400/Screenshot+from+2017-02-04+22-38-04.png" width="400" /></a></div>
<div>
<br /></div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-8850694600764210252016-10-23T02:43:00.000+10:302017-08-24T02:26:33.378+09:30Test Your Web Service - POX<b>What is Web Service:</b><br />
<br />
"Web Service" is described as a standardized way of communicating and integrating different systems. This communication primarily happens over HTTP.<br />
<br />
When testing a Web Service, there are multiple tools and options available. With this "Test your Web Service" post, I am going to publish about few approaches to test a Web Service. In the first post, I use POX based approach to test it.<br />
<br />
<b>Testing Your Web Service using POX:</b><br />
<br />
POX(<a href="https://en.wikipedia.org/wiki/Plain_Old_XML" rel="nofollow" target="_blank">Plain Old XML</a>) means exchanging plain old XML documents over HTTP, and this is a subset of REST. Here you can parse values to the Web Service as URL query parameters.<br />
<br />
In this post, I am going to use the Global Weather service available online in below URL. It can be named as the web service URL.<br />
<br />
Web service URL : <a href="http://www.webservicex.com/globalweather.asmx" target="_blank">http://www.webservicex.com/globalweather.asmx</a><br />
<br />
You can see the contract(WSDL) of the test web service by navigating to the below URL: <a href="http://www.webservicex.com/globalweather.asmx?wsdl" target="_blank">http://www.webservicex.com/globalweather.asmx?wsdl</a><br />
<br />
So there you can see this Web Service supports two operations and they are "GetWeather" and "GetCitiesByCountry". Here I am going to invoke the "GetCitiesByCountry" operation in POX way.<br />
You can compose the web service URL to invoke an operation by appending the operation name to the end of the service URL.<br />
<br />
<a href="http://www.webservicex.com/globalweather.asmx/GetCitiesByCountry" rel="nofollow" target="_blank">http://www.webservicex.com/globalweather.asmx/GetCitiesByCountry</a><br />
<br />
Then to pass the query parameters to the operation you can use the "?" and name/value pairs of the parameters (?CountryName=Australia). For multiple parameters "&" should be used in between parameters.<br />
<br />
For that open your browser and enter the following URL: <a href="http://www.webservicex.com/globalweather.asmx/GetCitiesByCountry?CountryName=Australia" rel="nofollow" target="_blank">http://www.webservicex.com/globalweather.asmx/GetCitiesByCountry?CountryName=Australia</a><br />
<br />
This will display all the cities supported by this weather check web service.Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-81020402488693582862016-09-10T00:35:00.001+09:302016-09-10T00:35:48.679+09:30Java - String intern() Method<a href="https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#intern()" rel="nofollow" target="_blank">String Intern</a> method returns an individual representation for the given String object. When the intern() method get invoked on a String object, it will look up the other interned strings, and if a String object exists in the memory with the same content, it will return the existing reference. Otherwise, it will return a new reference.<br />
<br />
<b>Example usage of String intern:</b><br />
<br />
Think about a web application with a caching layer. If cache got missed, it would go to the Database. When the application is running with the high level of concurrency, we should not send all the request to the database. Such a situation we can check whether, multiple calls coming to the same reference by checking String intern.<br />
<br />
<b>Code: </b><br />
<br />
String name1 = "Value";<br />
String name2 = "Value";<br />
String name3 = new String("Value");<br />
String name4 = new String("Value").intern();<br />
<br />
if ( name1 == name2 ){<br />
System.out.println("name1 and name2 are same");<br />
}<br />
if ( name1 == name3 ){<br />
System.out.println("name1 and name3 are same" );<br />
}<br />
if ( name1 == name4 ){<br />
System.out.println("name1 and name4 are same" );<br />
}<br />
if ( name3 == name4 ){<br />
System.out.println("name1 and name4 are same" );<br />
}<br />
<br />
<b>output:</b><br />
<br />
name1 and name2 are same<br />
name1 and name4 are same<br />
<br />
<br />
<br />
You can see that name1, name2 and name4, objects have the same reference and name3 reference is different.Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0tag:blogger.com,1999:blog-18481069.post-6346482330912411132016-08-25T02:49:00.000+09:302017-08-21T11:13:33.535+09:30Service Discovery with WSO2 Governance Registry<div>
<span style="font-family: inherit;"><br /></span></div>
<span style="font-family: inherit;">This blog post explains about the service discovery capability of WSO2 Governance Registry. If you have heard about UDDI and WS-Discovery, we used those technologies to discover Services during 2009-2013 time.<br /><br /><b>What is UDDI:</b></span><br />
<div>
<span style="font-family: inherit;"><b><br /></b>UDDI stands for Universal Description, Discovery, and Integration. It is seen with SOAP and WSDL as one of the three foundation standards of web services. It uses Web Service Definition Language(WSDL) to describe the services. <br /><br /><b>What is WS-Discovery:</b></span><br />
<div>
<span style="font-family: inherit;"><b><br /></b>WS-Discovery is a standard protocol for dynamically discovering service endpoints. Using WS-Discovery, service providers multicast and advertise their endpoints with others. <br /><br />Since most of the modern services are REST based, above two approaches are considered as dead nowadays. Both UDDI and WS-Discovery target for SOAP based services and they are very bulky. In addition to that, industry is moving from Service Registry concept to Asset Store(Governance Center), and people tend to use REST API and Discovery clients. <br /><br /><b>How Discovery Client works</b></span><br />
<div>
<span style="font-family: inherit;"><b><br /></b>So, here I am going to explain how to write discovery client in WSO2 Governance Registry(WSO2 G-Reg) to discover services which are deployed in the WSO2 Enterprise Service Bus(WSO2 ESB)/WSO2 Enterprise Integrator(WSO2 EI). This service discovery client will connect to ESB/</span>EI<span style="font-family: inherit;"> server and find the services which are deployed there and catalog those into the G-Reg server. In addition to service metadata(endpoint, name, namespace, etc.), discovery client will import the WSDLs and XSDs as well. </span><br />
<span style="font-family: inherit;"><br /><b>Configure Service Discovery Client:</b></span><br />
<div>
<span style="font-family: inherit;"><br /></span></div>
<div>
<span style="font-family: inherit;">Sample service discovery client implementation can be found from the below </span>GitHub<span style="font-family: inherit;"> repo(</span><a href="https://github.com/cnapagoda/discovery-client" style="font-family: inherit;" target="_blank">Discovery Client</a><span style="font-family: inherit;">). </span><br />
<br />
<span style="font-family: inherit;">1). Download WSO2 Governance Registry and WSO2 ESB/WSO2 EI product and unzip it.</span><br />
<br />
<span style="font-family: inherit;">2). By default, both servers are running on 9443 port, so you have to change one of the server ports. Here I am changing </span>port<span style="font-family: inherit;"> offset of the ESB server. </span><br />
<br />
<span style="font-family: inherit;">Open the carbon.xml file located in </span><ESB_HOME><span style="font-family: inherit;">/repository/conf/carbon.xml and find the “Offset” element and change its value as follows: </span><Offset>1</Offset><br />
<br />
<span style="font-family: inherit;">3). Copy </span><ESB_HOME><span style="font-family: inherit;">/repository/components/plugins/org.wso2.carbon.service.mgt.stub_4.x.x.jar to </span><GREG_HOME><span style="font-family: inherit;">/repository/components/dropins.</span><br />
<br />
<span style="font-family: inherit;">4). Download or clone ESB </span><a href="https://github.com/cnapagoda/discovery-client" style="font-family: inherit;" target="_blank">service discovery client</a><span style="font-family: inherit;"> project and build it.</span><br />
<br />
<span style="font-family: inherit;">5). Copy build jar file into </span><GREG_HOME><span style="font-family: inherit;">/repository/components/</span>dropins<span style="font-family: inherit;"> directory. </span><br />
<br />
<span style="font-family: inherit;">6). Then open the registry.xml file located in </span><GREG_HOME><span style="font-family: inherit;">/repository/conf/registry.xml and register service discovery client as a Task. This task should be added under “tasks” element. </span><br />
<br />
<task name="ServiceDiscovery" class="com.chandana.governance.discovery.services.ServiceDiscoveryTask"><br />
<trigger cron="0/100 * * * * ?"/><br />
<property key="userName" value="admin" /><br />
<property key="password" value="admin" /><br />
<property key="serverUrl" value="https://localhost:9444/services/"/><br />
<property key="version" value="1.0.0" /><br />
</task><br />
<br />
<span style="font-family: inherit;">7). Change the userName, password, serverUrl and defaultVersion according to your setup.</span><br />
<br />
<span style="font-family: inherit;">8). Now Start ESB server first and then start the G-Reg server. </span><br />
<div>
<span style="font-family: inherit;"><br />So, you can see “</span># of service created :...<span style="font-family: inherit;">” message in G-Reg console once </span>server<span style="font-family: inherit;"> has discovered a service from the ESB server and mean </span>time related<span style="font-family: inherit;"> WSDL and XSD </span>has<span style="font-family: inherit;"> got imported into G-Reg. Above services are cataloged under “SOAP Service” asset type.</span></div>
<div>
<span style="font-family: inherit;"><br /><br />Read about <a href="https://blog.napagoda.com/2016/05/g-reg-and-esb-integration-scenarios-for.html" target="_blank"><b>G-Reg and ESB integration scenarios for Governance</b></a></span></div>
</div>
</div>
</div>
</div>
Chandana Napagodahttp://www.blogger.com/profile/11223582213733712096noreply@blogger.com0