<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Irunika Weeraratne on Medium]]></title>
        <description><![CDATA[Stories by Irunika Weeraratne on Medium]]></description>
        <link>https://medium.com/@irunika?source=rss-583726918cbb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Mv9-zmFX2VCeyQdd-Vq9ag.jpeg</url>
            <title>Stories by Irunika Weeraratne on Medium</title>
            <link>https://medium.com/@irunika?source=rss-583726918cbb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 04:45:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@irunika/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Working with WSO2 Puppet Modules]]></title>
            <link>https://medium.com/@irunika/working-with-wso2-puppet-modules-560769bf4ac2?source=rss-583726918cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/560769bf4ac2</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[puppet-5]]></category>
            <category><![CDATA[puppet]]></category>
            <dc:creator><![CDATA[Irunika Weeraratne]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 04:48:36 GMT</pubDate>
            <atom:updated>2018-10-17T04:48:36.083Z</atom:updated>
            <content:encoded><![CDATA[<p>WSO2 has a variety of middleware products which are ready to run as a distributed system. Running a distributed system is not an easy task and that is where puppet modules for WSO2 products come into the picture.</p><p><em>Note: Before beginning this article, I assume that you have the basic knowledge of Puppet 5.</em></p><p>Following are the Puppet modules for each product</p><ul><li>WSO2 API Manager — <a href="https://github.com/wso2/puppet-apim">https://github.com/wso2/puppet-apim</a></li><li>WSO2 Enterprise Integrator — <a href="https://github.com/wso2/puppet-ei">https://github.com/wso2/puppet-ei</a></li><li>WSO2 Identity Server — <a href="https://github.com/wso2/puppet-is">https://github.com/wso2/puppet-is</a></li><li>WSO2 Stream Processor — <a href="https://github.com/wso2/puppet-sp">https://github.com/wso2/puppet-sp</a></li></ul><p>These modules have been written in a consistent pattern so if someone needs to work with them, the easiest way is to understand is how they are organized.</p><h3>Puppet Module</h3><p>All the modules of Puppet are contained in the modules directory and each module contains following directories.</p><ul><li>manifests</li><li>templates</li><li>files</li></ul><p>Let’s talk about each directory.</p><h3>manifests</h3><p>The manifest directory contains all the manifests need to manage configurations. WSO2 puppet modules contain only four manifest files to make it simple for a user to understand and we believe this is more than enough to install and configure a product. So we highly recommend to use existing manifest files rather than introducing new ones.<br>But in order to know how they work, let us go through each manifest.</p><h4>init.pp</h4><p>This is the main script of the module. This is written in a way that user does not need to modify this script. So in best practices, you will not need to modify this script. (<em>Note: If you get any requirement to change the init.pp then either we or you are doing something wrong :)</em>)<br>This script identifies the OS family (<em>Debian or Redhat</em>) and installs the required package in the puppet agent.<br>Then it copies all the required configuration files to relevant locations after rendering the templates.<br>So if something needs to be changed it should only be done in the params.pp which init.pp inherits from and uses to do the needful.</p><h4>params.pp</h4><p>This is the file that user should use most of the time. This contains all the necessary details to configure a product. <br>You can identify 3 main sections in here. To describe it I will be using the <a href="https://github.com/wso2/puppet-apim/blob/master/modules/apim/manifests/params.pp">params.pp of <strong><em>apim</em></strong> module</a> in API Manager puppet modules and note that this is the structure of each params.pp across all the puppet 5 modules of WSO2 products.</p><ol><li><strong>Basic details of the OS and product setup.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*Ej9hfmWCTUz800h4ki3I2g.png" /></figure><p><strong>2. Start script which starts the server and Template list which contains the paths to the config files from the carbon home. These files can be found in the same path under <em>templates/carbon-home</em> directory.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*8gUZv_m0Ypr7ra1EU0iwJw.png" /></figure><p><strong>3. Configuration params for each configuration file in human readable manner.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*smDeK87N6ZlaEwbeXTVINQ.png" /></figure><h4>custom.pp</h4><p>This is where the users run their own custom configuration scripts. This script runs after init.pp and before startserver.pp. So you can have any customization that you wanna have within this script.</p><h4>startserver.pp</h4><p>This script runs in the final stage and starts the server as a service.</p><h3>templates</h3><p>This directory contains all files which are templated with <strong><em>erb</em></strong> (embedded ruby) extension. You can find more details about <strong>erb</strong> in <a href="https://puppet.com/docs/puppet/5.5/lang_template_erb.html">here</a>. This directory contains a special directory called <strong>carbon-home.<br>carbon-home</strong> has the same structure as the product home. This is where the user should put files which have to be templated before copying it to the product home. As you can identify files are in the same path where it could find in the product home.</p><h4>Identifying the correlation between params.pp and templates</h4><p>Let’s take the same examples, <a href="https://github.com/wso2/puppet-apim/tree/master/modules/apim">apim puppet module</a>. In params.pp there is a template added for the api-manager.xml in <a href="https://github.com/wso2/puppet-apim/blob/7c651c635d7468a92c3cb868cb0f579dab581485/modules/apim/manifests/params.pp#L36">here</a>. Also there are configurations which are related to api-manager.xml in <a href="https://github.com/wso2/puppet-apim/blob/7c651c635d7468a92c3cb868cb0f579dab581485/modules/apim/manifests/params.pp#L47">here</a>.<br>Then if we go to the template <a href="https://github.com/wso2/puppet-apim/blob/master/modules/apim/templates/carbon-home/repository/conf/api-manager.xml.erb">api-manager.xml.erb</a> you can find that we have referred the same configs in params.pp to fill the template up. <br>So if you need to introduce new config to api-manager.xml, you just need to add the parameter in params.pp under api-manager.xml and use the same parameter in the template.<br>Likewise, you can add any parameter to the params.pp.</p><h3>files</h3><p>This is where all the files needed for the module including packages (eg: deb &amp; rpm files) are kept.</p><p>Hope you understand the way Puppet modules of WSO2 products have been organized. We believe that this structure is more than enough for a user to configure the product and keep it running.</p><p>We highly encourage everyone to report issues if you find any difficulties when working with these modules so we can make them better and better…<br>:)</p><p>Thanks and have a nice day !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=560769bf4ac2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Philosophy of WebSocket Support in Ballerina]]></title>
            <link>https://medium.com/@irunika/design-philosophy-of-websocket-support-in-ballerina-95df07430793?source=rss-583726918cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/95df07430793</guid>
            <category><![CDATA[ballerinalang]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[ballerina]]></category>
            <dc:creator><![CDATA[Irunika Weeraratne]]></dc:creator>
            <pubDate>Mon, 30 Apr 2018 11:18:52 GMT</pubDate>
            <atom:updated>2018-06-26T09:39:03.202Z</atom:updated>
            <content:encoded><![CDATA[<p>Last time I wrote how we can work with HTTP + WebSockets using the same host and port in Netty (<a href="https://medium.com/@irunika/how-to-write-a-http-websocket-server-using-netty-f3c136adcba9">learn?</a>). But as it seems Netty is too low level programming for most of us. Also most of the WebSocket APIs does not support powerful features of WebSocket spec out of the box. There is something out there to solve these problems. That is ballerina! Yeah a great dancer ;).</p><p>Ballerina is a cloud native programming language targeting to heal the pain of network integration and it is a pure programming language which is built from the scratch. I had a great opportunity to work in this project focusing WebSocket integration and we had a great chance to do everything in the best way we can.</p><p>Since we had all the time to think on how we can integrate WebSocket into Ballerina as purely as possible according to the <a href="https://tools.ietf.org/html/rfc6455">Spec</a> (No workarounds anymore) and also make the developers life as easier as possible.</p><p>This article is to describe how and why we designed WebSocket support in Ballerina in such a way (There may be pros and cons and your suggestions are warmly welcome.)</p><h3>WebSocket service</h3><p>Service is a top level concept in Ballerina which is a network entry point for inbound messages. WebSocket service is a endpoint which reads inbound WebSocket frames. WebSocket service has fixed resources which are triggered in specific events</p><p><strong>onOpen(endpoint ep)</strong><br>Triggered when new connection is opened. Note that until the logic in this code block finishes messages will not be read from the channel. This will allow you to block the message reading until you need. This is specially useful in WebSocket gateway scenarios.<br><strong>onText(endpoint ep, string text, boolean finalFragment)</strong><br>Triggers when new text message is received. <em>finalFragment</em> is an optional parameter.<br><strong>onBinary(endpoint ep, blob data, boolean finalFragment)</strong><br>Triggers when new binary message is received. <em>finalFragment</em> is an optional parameter.<br><strong>onIdleTimeout(endpoint ep)</strong><br>Triggers when a connection reaches it’s idle timeout. Note that this resource is useless without WebSocket service configuration idleTimeoutInSecs<br><strong>onPing/onPong(endpoint ep, blob data)</strong><br>These resources trigger when ping and pong messages are received.<br><strong>onClose(endpoint ep, int statusCode, string reason)</strong><br>Triggers when a connection is getting closed. (When a close frame is received)</p><p><strong>WebSocket Endpoint</strong><br>Endpoint can be used to take a action to remote endpoint. <br>eg: pushing a text message to remote endpoint <strong><em>ep-&gt;pushText(“hi&quot;) </em></strong><br>Followings are the available actions in the current WebSocket endpoint<br><strong>pushText(string text, final = true)</strong> final is a optional parameter<br><strong>pushBinary(blob b, final = true)</strong> final is a optional parameter<br><strong>ping(blob data)<br></strong><strong>pong(blob data)<br></strong><strong>close(int statusCode, string reason)</strong></p><p>Following is a simple example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01cefa2fde94369ae6dfb3b46ea7ce56/href">https://medium.com/media/01cefa2fde94369ae6dfb3b46ea7ce56/href</a></iframe><p>As you can observe in the above example we tried simplify the API as much as possible. You can just say <br><strong><em>ballerina run simple_websocket_service.bal</em></strong> <br>to run this program. Nothing more! It will open the socket for you and run the program as a service. Use <br><strong><em>ws://localhost:9090/simple/ws</em></strong> <br>to connect to this service endpoint.</p><h3>WebSocket Client</h3><p>Since WebSocket is a full duplex, bidirectional protocol after a successful handshake both WebSocket server and client behave symmetrically. Only difference between client and server is that the client initiates the WebSocket handshake.</p><p>So it is obvious that after a successful handshake both client and server are just endpoints. Which means to read inbound messages a client also needs a WebSocket service. So we designed it that way. In ballerina, after a successful handshake you need to treat both WebSocket server and client as just endpoints which receives messages and push data to the other endpoint.</p><p>Check the following client example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10fd1043604fb47fcaf9f193d7146ad9/href">https://medium.com/media/10fd1043604fb47fcaf9f193d7146ad9/href</a></iframe><p>This client endpoint can be used in any place you want and use the wsClientEp to push messages to the server. (Check WebSocket examples in our website for more advanced examples of WebSocket client like <a href="https://ballerina.io/learn/by-example/websocket-proxy-server.html"><strong><em>websocket gateway service</em></strong></a>)</p><h3>HTTP to WebSocket Upgrade</h3><p>This is where client and server negotiate to create a WebSocket connection on top of already existing underlying TCP connection. But I could not find anyone who could easily expose this moment to the user. Which is very important if we can see what is happening when a client is connecting to a server using a HTTP request(Upgrade request) like “Are there any custom headers involved?” or “Do we need to authenticate before the WebSocket connection is established?”, etc…</p><p>Also we should be able to run HTTP endpoints and WebSocket endpoints in the same host+port. Because it is just a upgrade from HTTP.</p><p>This can be very easily done in ballerina. Please refer the following example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7681ae18f81d9288fe063288e9cb5902/href">https://medium.com/media/7681ae18f81d9288fe063288e9cb5902/href</a></iframe><p>By doing so developer can easily see what is happening and also gives the full capability to handle the initial HTTP request in the upgrading stage. Also this demonstrate the capability of upgrading the same HTTP connection to WebSocket in Ballerina.</p><h3>Conclusion</h3><p>We believe in giving the user a great opportunity to fade away the pain of integration using Ballerina. We just saw the surface of it in these examples (This is just WebSocket). Current ballerina/http package supports WebSocket Sub protocol negotiation, Custom headers support in WebSocket handshake, idle timeout and secure WebSocket in addition to what we talked in this article.</p><p>This design of WebSockets gives the developers the opportunity to purely focus on business logic rather than worrying about protocol level implementation.</p><p>Ballerina is still a child. We believe she has a great future. We invite you to become a part of it. Your suggestions on this are warmly welcome.</p><p>Cheers to you and ballerina!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95df07430793" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write a HTTP + WebSocket server using Netty]]></title>
            <link>https://medium.com/@irunika/how-to-write-a-http-websocket-server-using-netty-f3c136adcba9?source=rss-583726918cbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3c136adcba9</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[netty]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Irunika Weeraratne]]></dc:creator>
            <pubDate>Sun, 04 Dec 2016 14:21:02 GMT</pubDate>
            <atom:updated>2018-07-05T16:31:38.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*4J5WXH1dFHtoCq-P8RLyYQ.png" /></figure><p>For most of the developers who are working in the low level in web services area, there is this problem with exposing HTTP + WebSocket services using a single server.</p><p>I am currently working on a project of adding WebSocket support to a Netty based HTTP micro-services server. I had the same problem and after studying so many things, I finally came up with a solution to handle it.</p><p>Today we are going to talk about how we can actually use Netty libraries to receive HTTP + WebSocket requests in a single server and serve them separately in a very basic level implementation.</p><p><strong>Note : We are not going to talk about how to handle client requests instead we are going to talk about handling HTTP vs WebSocket protocol in a very basic level</strong>.</p><p>So let’s begin. :D</p><p>Before beginning the implementation we have to understand the relationship between HTTP and WebSocket protocol based servers.</p><h3>HTTP Server</h3><p>In single terms what it does is, for incoming client requests, process it and sends back responses to the client. That’s it. Nothing more nothing less. If client needs something else then client has to send another request to the server. Imagine that you need data periodically or you want to know if something happened in server side ASAP. With HTTP what you can do is polling. That is annoying right? That is heavy weight for the client application as well as to the server. It consumes more data every time you use the app.</p><h3>WebSocket Server</h3><p>This is the solution for the problems we discussed above in the section “HTTP Server”. In WebSocket what happens is, it actually sends a HTTP request with specific attributes for the very first time saying the connection needs to be upgraded to WebSocket. So we can do a handshake with the client and then the protocol will be upgraded from HTTP to WS (WebSocket).</p><p>The specific request for protocol upgrade would looks like</p><pre>GET <strong>ws://websocket.example.com/</strong> HTTP/1.1<br>Origin: http://example.com<br><strong>Connection: Upgrade</strong><br>Host: websocket.example.com<br><strong>Upgrade: websocket</strong></pre><p>This indicates the server that the client needs to establish a websocket connection. If the server supports websocket then it send the response agreeing to establish connection using the “Upgrade” header.</p><pre><strong>HTTP/1.1 101 WebSocket Protocol Handshake</strong><br>Date: Sun, 20 Nov 2016 12:45:56 GMT<br><strong>Connection: Upgrade<br>Upgrade: WebSocket</strong></pre><p>Once this message is sent the handshake is completed and initial HTTP connection is replaced by websocket connection using the same underlying TCP/IP connection.</p><p>Now the connection is established. Once the connection is established there will be a <a href="https://en.wikipedia.org/wiki/Full-duplex">f</a>ull-duplex communication channels over a single TCP connection for a given client. One of the specific feature in WebSocket which HTTP doesn’t have is <strong>Server Push. </strong>Server push means that even without a client request server can push data to the client. Isn’t it nice? So client doesn’t have to worry about sending periodic requests to access real time data or server side changes. This is real real time. Not a manipulated real time :D I think you got the point ;)</p><p>Now if you want to read more about WebSocket please click <a href="https://tools.ietf.org/html/rfc6455">here</a>.</p><p>So since we have the basic knowledge about those 2 protocols we can start the implementation.</p><p>Before the implementation, if you want to understand the basics of Netty please click <a href="http://netty.io/">here</a>.</p><p>I am not going to talk about Netty simply because there are enough resources to learn the basics instead I want to talk about the specific topic that I have mentioned above.</p><p>So lets start implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44668c16ab4fda8c77ef213ff98fbd65/href">https://medium.com/media/44668c16ab4fda8c77ef213ff98fbd65/href</a></iframe><p>HTTPInitializer is the class which initialize the Channel for a given connection. SocketChannel Pipeline is the place that we do all the processing we want to do with a given request. I’m not going to talk more about it you can find all the details on the documentation. What I want to focus here is that the classes I added to this pipeline. HttpServerCodec is a class provided by Netty which does the decoding and encoding for incoming requests.</p><p>HttpServerHandler is the class that we should write to handle the upcoming HTTP request.</p><p>Let’s see</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33ddd2ac619abad06aa020fea2c4d97f/href">https://medium.com/media/33ddd2ac619abad06aa020fea2c4d97f/href</a></iframe><p>As you can see in the above class, <strong>if conditions starts from line no. 26 </strong>is<strong> </strong>doing the magic. What it does is, it checks whether the incoming request is a WebSocket upgrade and does the handshake accordingly. But it is not a good practice to mix up WebSocket message handling with HTTP request handling in the same class. So what I did is that I added another class to handle WebSocket messages into the pipeline.</p><p>But the problem is from the “else” part, it drops all the incoming WebSocket messages from the pipeline before it arrives to the WebSocketHandler. So after the handshake is properly done I replaced the existing HttpServerHandler with WebSocketHandler since we surely know that after the handshake all the incoming messages to that given channel are WebSocketFrames.</p><pre><strong>ctx.pipeline().replace(this, &quot;websocketHandler&quot;, new WebSocketHandler());</strong></pre><p>Here is the code for WebSocketFrame handling.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0866c461a7a4cc691a75b50bf6701fa7/href">https://medium.com/media/0866c461a7a4cc691a75b50bf6701fa7/href</a></iframe><p>So now we are done. Now we can write a typical Netty server to handle any incoming requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74482bbaff231918994a55cfcbac94bd/href">https://medium.com/media/74482bbaff231918994a55cfcbac94bd/href</a></iframe><p>Now just run the above code.</p><p>You can use any WebSocket Client or HTTP Client to see whether the given implementation is working.</p><p>I have specified the port as 9000 you can change it as you want.</p><p>So just connect to the server using</p><pre>ws://localhost:9000 + URI (or without URI)</pre><p>with any WebSocket Client</p><p>or</p><pre>http://localhost:9000 + URI (or without URI)</pre><p>with any HTTP client.</p><p>Thats it.</p><p>Hope you enjoyed the tutorial.</p><p>Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3c136adcba9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>