<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Dhanushka madushan</title>
    <description>The latest articles on Forem by Dhanushka madushan (@dhanushkadev).</description>
    <link>https://forem.com/dhanushkadev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F145372%2F12c2743e-644f-40e8-9b39-fadb096f2395.jpg</url>
      <title>Forem: Dhanushka madushan</title>
      <link>https://forem.com/dhanushkadev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dhanushkadev"/>
    <language>en</language>
    <item>
      <title>How to start Jenkins Docker container with a given version</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Fri, 21 Apr 2023 07:32:45 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/how-to-start-jenkins-docker-container-with-a-given-version-1a01</link>
      <guid>https://forem.com/dhanushkadev/how-to-start-jenkins-docker-container-with-a-given-version-1a01</guid>
      <description>&lt;p&gt;Jenkins is a widely used automation server that helps to streamline software development processes. Docker, on the other hand, is a popular tool for creating and managing containers. Running Jenkins in a Docker container can offer several benefits, such as easy deployment and portability. However, it's important to make sure you're using the right version of Jenkins to ensure compatibility with your existing tools and processes. In this guide, we'll explore how to start a Jenkins Docker container with a specific version, ensuring you have the right tools for the job.&lt;/p&gt;

&lt;p&gt;Use the following docker registry to pull docker image to start a Jenkins Docker image:&lt;br&gt;
&lt;a href="https://hub.docker.com/r/bitnami/jenkins"&gt;https://hub.docker.com/r/bitnami/jenkins&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following is the docker pull command to pull 2.346.3 version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull bitnami/jenkins:2.346.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once pull is completed we can start the Jenkins Docker container with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker volume create --name jenkins_data
docker run -d -p 8080:8080 --name jenkins \
  --network jenkins-network \
  --volume jenkins_data:/bitnami/jenkins \
  bitnami/jenkins:2.346.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I set the port mapping from 8080 to 8080. If you need to map to another port(ex 9000), use &lt;code&gt;-p 9000:8080&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;It take some time and you can see jenkins logs with &lt;code&gt;docker logs &amp;lt;container_ID&amp;gt;&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Then, open a browser and go to &lt;code&gt;http://localhost:8080&lt;/code&gt; and you will see Jenkins login page. User the following credentials to log into it:&lt;br&gt;
Username: user&lt;br&gt;
Password: bitnami&lt;/p&gt;

</description>
      <category>docker</category>
      <category>jenkins</category>
      <category>cicd</category>
    </item>
    <item>
      <title>CAP theorem and what does it means</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Mon, 20 Feb 2023 16:13:31 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/cap-theorem-and-what-does-it-means-3dfg</link>
      <guid>https://forem.com/dhanushkadev/cap-theorem-and-what-does-it-means-3dfg</guid>
      <description>&lt;p&gt;The CAP theorem addresses the trade-off between consistency, availability, and partition tolerance in a distributed system. In this video, let's go through each of these properties and altogether what these properties mean in a distributed system.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/3tI3g_nqWlo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>captheorem</category>
      <category>cloudcomputing</category>
      <category>distributedsystem</category>
    </item>
    <item>
      <title>Decompile all the jar files in given directory</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Thu, 12 Jan 2023 04:57:52 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/decompile-all-the-jar-files-in-given-directory-1j99</link>
      <guid>https://forem.com/dhanushkadev/decompile-all-the-jar-files-in-given-directory-1j99</guid>
      <description>&lt;p&gt;Procyon is a Java decompiler for reverse engineering compiled Java code. It can be used to decompile Java 5 and Java 7 bytecode and is open-source. Procyon's ability to decompile complex Java code and generate comprehensible output is one of its benefits. Decompiling JAR files is one of Procyon's common uses. The file format known as a JAR file, or Java Archive, is used to store multiple files, including Java classes and resources, in a single archive. Typically, these files are turned into Java bytecode, which can then be run on any Java Virtual Machine (JVM).&lt;/p&gt;

&lt;p&gt;You must first download the &lt;a href="https://github.com/mstrobel/procyon/wiki/Java-Decompiler" rel="noopener noreferrer"&gt;Procyon decompiler&lt;/a&gt; file from the official website and put it in a directory on your system before you can use Procyon to decompile a JAR file. After that, you can run the JAR file from the command line while specifying the JAR file you want to decompile as an argument. For instance, the "example.jar" JAR file can be decompiled using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -jar procyon-decompiler.jar example.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing this, all of the class files in the JAR file will be extracted, and the decompiled source code will be written to separate files with the same name as the class file but a.java extension. The JAR file and the decompiled code will both be kept in the same directory.&lt;/p&gt;

&lt;p&gt;You can use &lt;a href="https://github.com/mstrobel/procyon/wiki/Java-Decompiler" rel="noopener noreferrer"&gt;Procyon decompiler&lt;/a&gt; and have a recursive look into folders with the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find &amp;lt;jar_files_directory&amp;gt; -name "*.jar" -exec java -jar &amp;lt;procyon_decompiler_location&amp;gt; -jar {} -o &amp;lt;output_directory&amp;gt; \;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -name "*.jar" -exec java -jar /Users/abc/Desktop/procyon-decompiler-0.6.0.jar -jar {} -o output/ \;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to keep in mind that Java code decompiling is not always correct, and the resulting source code might not exactly match the original. Decompiling Java code may also be permitted in some circumstances, but it frequently violates copyright regulations, so it should be used with caution.&lt;/p&gt;

&lt;p&gt;Procyon is a powerful resource for debugging Java code and has a wide range of applications. Procyon is a dependable decompiler that can assist you in achieving your objectives, whether you're looking to comprehend how a third-party library operates or recover lost source code.&lt;/p&gt;

</description>
      <category>decompile</category>
      <category>decompiler</category>
      <category>java</category>
      <category>jar</category>
    </item>
    <item>
      <title>7 Facts on securing your WSO2 Micro integrator</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Thu, 29 Sep 2022 13:33:08 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/7-facts-on-securing-your-wso2-micro-integrator-4dl7</link>
      <guid>https://forem.com/dhanushkadev/7-facts-on-securing-your-wso2-micro-integrator-4dl7</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/RMjMYoiXGXQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;WSO2 Micro Integrator is an integration solution that is widely used in enterprise integration. You can use MI(For short let's use Micro Integrator as MI) to implement mediation policies, message transformation, security, and many more. In this article, we are going to focus on how you can securely place MI on your deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  First thing first:
&lt;/h2&gt;

&lt;p&gt;WSO2 MI comes with a default Keystore that is used in many cryptography-related features including SSL, mutual SSL, password encryption, and so on. Since this is a public one, you should make sure that you have generated a new Keystore and truststore for the MI.&lt;/p&gt;

&lt;p&gt;If you are looking for steps on how you do it, then refer to the following document:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/install-and-setup/setup/mi-setup/security/configuring_keystores" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/install-and-setup/setup/mi-setup/security/configuring_keystores&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Avoid having the default H2 database and use a proper one&lt;/p&gt;

&lt;p&gt;By default WSO2 MI ships with H2 embedded database to store data for the following purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cluster coordination&lt;/li&gt;
&lt;li&gt;RDBMS user store&lt;/li&gt;
&lt;li&gt;Transaction counter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is not good practice to use the H2 database in the deployment environment as it is stored in the deployment environment where people who have access to the deployment able to acess this file. WSO2 MI provides the following list of databases that you can easily configure with MI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;MSSQL&lt;/li&gt;
&lt;li&gt;Oracle&lt;/li&gt;
&lt;li&gt;Postgre&lt;/li&gt;
&lt;li&gt;IBM DB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These databases are enterprise databases that provide much more security than the simple H2 database. Therefore, make sure to configure any of the databases given here rather than using the default H2 database to have a good security level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the secure vault to store sensitive data
&lt;/h2&gt;

&lt;p&gt;WSO2 MI use synapse-based XML document to specify and store mediation policies. In some cases, you might need to access secure services/endpoints with particular inputs such as passwords. Storing these inside the mediation flow might not good solution in case of attacker get access to the MI instance as these mediation sequences are stored in a file.&lt;/p&gt;

&lt;p&gt;MI provides a secure vault to store this sensitive information in an encrypted manner. Instead of keeping data as plain text, you can save data encrypted where MI is able to decrypt it whenever it is needed.&lt;/p&gt;

&lt;p&gt;You can configure the text you need to encrypt under the [secrets] section on the /conf/deployment.toml folder(Define this at the bottom of the file). Check the following example values that you are defined in the deployment.toml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[secrets]
hello=”[abcd]”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can notice that value is given as a plain text value and surrounded with square brackets. We will use the Keystore file to encrypt this content and replace this value. For that, you can use ./ciphertool.sh -Dconfigure command. It will ask you the Keystore password where by default it would be wso2carbon(Make sure to create a new one when you are using this in a production environment). If you check the deployment.toml file again, you may notice that the value with the square bracket gets changed into an encrypted value. This is the encrypted value and you can use the key whenever you need to use this particular secret.&lt;/p&gt;

&lt;p&gt;If you are using MI in a microservices environment, you have to generate these encrypted entities first and then copy them inside the image.&lt;/p&gt;

&lt;p&gt;Now you can use this key inside the MI sequences. Check the following example property mediator that retrieves an encrypted entity and logs it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;property expression="wso2:vault-lookup('hello')" name="helloProperty" scope="default" type="STRING"/&amp;gt;
&amp;lt;log level="custom"&amp;gt;
 &amp;lt;property expression="$ctx:helloProperty" name="secure valut log"/&amp;gt;
&amp;lt;/log&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wso2:vault-lookup() function lets you retrieve decrypted values you have specified in the deployment.toml in an encrypted format. Now, you can use this property anywhere in the mediation flow. As early mentioned this is an elegant way of storing passwords that you need to access third-party services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/install-and-setup/setup/mi-setup/security/encrypting_plain_text/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/install-and-setup/setup/mi-setup/security/encrypting_plain_text/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Hashicorp secure vault
&lt;/h2&gt;

&lt;p&gt;If you have dynamic content that you need to change, then you can consider using Hashicorp secure vault with the MI. Hashicorp Vault is a secure vault provided by Hashicorp, especially for microservices environments. In the Hashicorop vault, you can define the secrets you need and Vault API lets services access these secrets.&lt;/p&gt;

&lt;p&gt;You can configure MI to access the Hashicorp vault by Secure Vault driver into the &lt;code&gt;&amp;lt;MI_HOME&amp;gt;/lib&lt;/code&gt; directory and by adding the following TOML configuration into the &lt;code&gt;&amp;lt;MI_HOME&amp;gt;/conf/deployment.toml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[external_vault]] 
name = "hashicorp" 
address = "http://127.0.0.1:8200" 
# If Static Token authentication is used, apply the rootToken: rootToken = "ROOT_TOKEN" 
# If AppRole Pull authentication is used, apply the roleId and secretId: 
roleId = "ROLE_ID" 
secretId = "SECRET_ID" 
cachableDuration = 15000 
engineVersion = 2 
namespace = "NAMESPACE" 
trustStoreFile = "${carbon.home}/repository/resources/security/client-truststore.jks" keyStoreFile = "${carbon.home}/repository/resources/security/wso2carbon.jks" keyStorePassword = "KEY_STORE_PASSWORD"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can access secret values with &lt;code&gt;hashicorp:vault-lookup(‘path-name’, ‘field-name’)&lt;/code&gt; expression which is the same as the MI secure vault.&lt;/p&gt;

&lt;p&gt;For more instruction on how to do it, refer to the following documentation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/install-and-setup/setup/mi-setup/security/using-hashicorp-secrets" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/install-and-setup/setup/mi-setup/security/using-hashicorp-secrets&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Other than the local secure vault and Hashicorp secure vault, you can use Docker secrets and Kubernetes secrets as well. The implementation of those two methods is pretty much similar. Check the following documentation to learn more about these two methods:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/integrate/develop/creating-artifacts/using_docker_secrets/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/integrate/develop/creating-artifacts/using_docker_secrets/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/integrate/develop/creating-artifacts/using_k8s_secrets/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/integrate/develop/creating-artifacts/using_k8s_secrets/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hide observable data with log masking
&lt;/h2&gt;

&lt;p&gt;Logging is an important requirement when you are building a server-side application. Logging is the most basic observability principle that you can implement to track errors and find the root cause. While it makes simplify your process, it may cause a security impact if you log sensitive information. If you need to log sensitive information such as credit card numbers and passwords, you need to care about how you are going to keep it secure.&lt;/p&gt;

&lt;p&gt;MI may place where transactions with sensitive data are present. If you logging enabled and sensitive data may be logged with message payload or header. WSO2 MI let you mask this sensitive information while it logging in to the given destination. WSO2 MI uses log4j as the logging library and you can specify what are the logs that need to print and where they should print.&lt;/p&gt;

&lt;p&gt;You can enable log masking for WSO2 MI by adding an additional ‘m’ to the CARBON_CONSOLE layout appender in the &lt;code&gt;&amp;lt;MI_HOME&amp;gt;/conf/log4j2.properties&lt;/code&gt; file. Following is what looks like when you enable log masking for log4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;appender.CARBON_CONSOLE.layout.pattern = [%d] %5p {%c{1}} - %mm%ex%n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can define masking patterns in RegEx format in the deployment.toml file. This will search RegEx patterns on the log line and replace those with ***** values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[masking_pattern.properties] 
"CREDIT_CARD_VISA" = "4[0-9]{6,}$"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/administer/logging-and-monitoring/logging/masking-sensitive-information-in-logs" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/administer/logging-and-monitoring/logging/masking-sensitive-information-in-logs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Secure your proxy services in MI
&lt;/h2&gt;

&lt;p&gt;One of the main purposes of MI is to expose its mediation endpoints to the client endpoint. When you need to expose MI services outside, you need to have a proper security mechanism to authorize your services. Web Service Security(WS Security) helps you to achieve this by applying different authentication and authorization policies to the MI endpoints.&lt;/p&gt;

&lt;p&gt;With MI, you can authenticate and authorized client before access its endpoint. MI provide multiple different ways including Username Token, Non-repudiation, Integrity, Confidentiality and so on. For an example, you can configure your proxy services with Username Token, where you can authenticate request with username and password against MI user store. In MI, you can create user and roles with MI CLI tool. Then you can map those roles with WS security policies created by using a registry resource project.&lt;/p&gt;

&lt;p&gt;Do you wan’t more details on how to configure WS security for MI, then follow the instruction in here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/integrate/develop/advanced-development/applying-security-to-a-proxy-service/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/integrate/develop/advanced-development/applying-security-to-a-proxy-service/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Secure your REST APIs in MI
&lt;/h2&gt;

&lt;p&gt;Now you know how to secure proxy service with WSO2 MI. How about APIs? Now web services are fading away and APIs take the lead of web space. WSO2 MI gives you to define your API and do some mediations same as the proxy services do.&lt;/p&gt;

&lt;p&gt;APIs WSO2 MI does not directly provide you a way to secure REST API and you need to use WSO2 API Manager(APIM) Gateway to expose your services. If you already have a proxy service that you need to expose, then you can easily configure WSO2 APIM to access MI APIs. Here MI automatically publish artefacts to the APIM service catalog such that you can manage MI APIs with the APIM.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/tutorials/integration-tutorials/service-catalog-tutorial/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/tutorials/integration-tutorials/service-catalog-tutorial/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the other hand, you can do API first integration by starting creating API specs. First you need to create mock API with APIM that include how the API looks like. Then you can import API specs into the Integration Studio and implement the mediation logics in there. Following is the detailed steps to how to do it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/tutorials/develop-an-integration-with-a-managed-api/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/tutorials/develop-an-integration-with-a-managed-api/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you know how to expose WSO2 MI API through the WSO2 APIM. WSO2 APIM let you to apply various different policies of exposing APIs that include securing APIs as well. You can enable transport level security with SSL verification and authentication with OAuth2 protocol.&lt;/p&gt;

&lt;p&gt;Other than those security features, you can use other features such as API lifecycle management, throttling, monotization as well.&lt;/p&gt;

&lt;p&gt;If you don’t need to use APIM to secure your MI APIs, you can use MI handlers and some JAVA code to secure MI APIs. MI API handlers is a JAVA hook that get trigger before the request hit the API mediation flow and before send the response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2gjxlt0sb5l3jjqjfeo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2gjxlt0sb5l3jjqjfeo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It provide two methods handleRequest() and handleResponse() to handle request and the response. Both of these methods return a boolean value that say whether the request or response should be proceed as usual or restricted. Now you know the trick. You can implement authorization on the handleRequest() method and limit the access to the API. The API that need to have this authorization mechanism can be specified in the MI Synapse API definition. You can get more details on how to configure it with the following documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apim.docs.wso2.com/en/latest/integrate/develop/advanced-development/applying-security-to-an-api/" rel="noopener noreferrer"&gt;https://apim.docs.wso2.com/en/latest/integrate/develop/advanced-development/applying-security-to-an-api/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get a WSO2 MI subscription and always up to date
&lt;/h2&gt;

&lt;p&gt;Finally, non of the software is one hundred present secure where vulnerabilities get discovered when the time goes on. Therefore, the software product that you are using, should always get updated to withstand cyber attacks. MI security scans are performed frequently and check if there are any vulnerabilities. If there are any vulnerabilities, WSO2 sends security updates to subscription customers. For more security, get a subscription and keep on updating the deployment.&lt;/p&gt;

&lt;p&gt;In this article we have focus on the basic security practices that you should follow to secure your Micro Integrator from vulnerabilities. Keep it mind that there are lot more of best practices that you need to follow inorder to secure you whole deployment. Always keep on mind to secure links with SSL or mutual SSL, update vulnerable dependencies, handle attacks such as DDoS and XSS to make sure your deployment is secure.&lt;/p&gt;

</description>
      <category>wso2</category>
      <category>security</category>
      <category>cloudnative</category>
      <category>integration</category>
    </item>
    <item>
      <title>Simple tool to read messages on RabbitMQ</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Thu, 05 May 2022 06:07:19 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/simple-tool-to-read-messages-on-rabbitmq-21l2</link>
      <guid>https://forem.com/dhanushkadev/simple-tool-to-read-messages-on-rabbitmq-21l2</guid>
      <description>&lt;p&gt;I found the following repository that let you to read RabbitMQ messages easily.&lt;br&gt;
&lt;a href="https://github.com/dubek/rabbitmq-dump-queue"&gt;https://github.com/dubek/rabbitmq-dump-queue&lt;/a&gt;&lt;br&gt;
This is Go lang based tool and you can use it with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go get github.com/dubek/rabbitmq-dump-queue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will compile the code into the &lt;code&gt;$GOPATH/bin&lt;/code&gt; and you can use the tool from there.&lt;br&gt;
Following is a sample command that you can dump upto 500 messages from the rabbitmq along with its header data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./rabbitmq-dump-queue  -uri="amqp://guest:guest@localhost:5672/" -queue=queue1 -max-messages=500 -output-dir=/output/locaiton -full
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Undestanding Java OSGI framework</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Wed, 22 Sep 2021 03:46:25 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/undestanding-java-osgi-framework-j8d</link>
      <guid>https://forem.com/dhanushkadev/undestanding-java-osgi-framework-j8d</guid>
      <description>&lt;p&gt;OSGI is a framework used in building complex Java applications that contain multiple components. With OSGI, you can build Java application that can load dynamically. When you are building a basic Java application, you might create a jar file for each module and load it with the class path. But, with the OSGI framework, you can load OSGI jar file dynamically whenever you needed.&lt;br&gt;
Lets discuss some of the terminologies and concepts that you should know about OSGI framework:&lt;/p&gt;
&lt;h2&gt;
  
  
  Bundle
&lt;/h2&gt;

&lt;p&gt;Bundle is the OSGI module that contain all your logics. Bundle is a jar file that contain your business logic that provide some service. Other than a regular jar file, it also contain information about how it supposed to work in OSGI runtime in MANIFEST.MF file. These information include a bundle name, version, exported and imported libraries.&lt;br&gt;
Following is a sample definition of OSGI bundle definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Bundle-Name: Hello World
 Bundle-SymbolicName: org.dhanushka.helloworld
 Bundle-Description: A Hello World bundle
 Bundle-ManifestVersion: 2
 Bundle-Version: 1.0.0
 Bundle-Activator: org.dhanushka.Activator
 Export-Package: org.dhanushka.helloworld;version="1.0.0"
 Import-Package: org.osgi.framework;version="1.3.0"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Bundle-name&lt;/strong&gt; is used to identify the bundle. This is just a optional string value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle-SymbolicName&lt;/strong&gt; is a unique identifier for the bundle. This follows the common java package naming standard.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle-Description&lt;/strong&gt; is a description about what this bundle does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle-ManifestVersion&lt;/strong&gt; is versioning used by OSGI framework to read bundle manifest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle-Version&lt;/strong&gt; is the version number you allocated for the OSGI bundle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundle-Activator&lt;/strong&gt; is the starting point of your module. You bundle can have multiple class implementations. OSGI use this property to mark what is the class that used as starting point of the bundle. We will discuss about bundle activator more later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Export-Package&lt;/strong&gt; is a set of packages that you need to expose to other OSGI bundles. If you didn't specify export packages, then other OSGI bundles unable to access classes in your OSGI bundle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Import-Package&lt;/strong&gt; is a set of packages that required to your OSGI bundle. You should import packages in here if you need to refer any other OSGI bundles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bundle is simply a module that contain all of your programming logics. You can import another bundle functionality into it and expose your own functionality to other bundles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Services
&lt;/h2&gt;

&lt;p&gt;Services are the way how each of the bundles are connected together. As I have already explained, multiple bundles can be connected together to provide some service.&lt;br&gt;
Check the following sample bundle implementation that has activation method on it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Activator&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;BundleActivator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;BundleContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BundleContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Starting"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BundleContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stopping"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this source code, the bundle activator is the &lt;code&gt;Activator&lt;/code&gt; class. When the OSGI starting up it start executing the &lt;code&gt;start&lt;/code&gt; method. This is much similar to the &lt;code&gt;main&lt;/code&gt; method. When the OSGI framework stopping, it trigger the &lt;code&gt;stop&lt;/code&gt; method. Whenever you add this bundle into the OSGI runtime, it will start execution by calling the &lt;code&gt;start&lt;/code&gt; method and end its execution by calling the &lt;code&gt;stop&lt;/code&gt; method.&lt;br&gt;
As you can see, this bundle does not have any dependency with other OSGI bundles. It can start its execution independently. In some scenarios, you might need to start this bundle when some conditions are met. Until condition satisfy, OSGI runtime does not call the &lt;code&gt;start&lt;/code&gt; method.&lt;br&gt;
This can be achieved with references. References let you to call &lt;code&gt;start&lt;/code&gt; method once given conditions are met. Check the following modification done to the &lt;code&gt;Activator&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Activator&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;BundleActivator&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;BundleContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BundleContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Starting"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="nd"&gt;@Reference&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"activator.service"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ActivatorService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;cardinality&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ReferenceCardinality&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MANDATORY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;policy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ReferencePolicy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;DYNAMIC&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;unbind&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"unsetActivatorService"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setActivatorService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ActivatorService&lt;/span&gt; &lt;span class="n"&gt;activatorService&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Set values&lt;/span&gt;
     &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;unsetActivatorService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ActivatorService&lt;/span&gt; &lt;span class="n"&gt;activatorService&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Unset values&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BundleContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Stopping"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, other than previous &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;stop&lt;/code&gt; method, there are another two methods. &lt;code&gt;@Reference&lt;/code&gt; annotation used here to mark these dependencies. Here, we have given a service name and service class. Under the reference annotation, we defined the &lt;code&gt;cardinality&lt;/code&gt; as mandatory. Since the cardinality marked as mandatory, to trigger &lt;code&gt;start&lt;/code&gt; function, &lt;code&gt;setActivatorService&lt;/code&gt; should be satisfied. If the cardinality is optional, then it is not mandatory to call &lt;code&gt;setActivatorService&lt;/code&gt; to start this bundle. This method can be triggered from another bundle. Following is a sample code, how to trigger &lt;code&gt;setActivatorService&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;context.getBundleContext().registerService(ActivatorService.class.getName(), activatorService, null);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;activatorService&lt;/code&gt; is the object that contain details that need to send to the &lt;code&gt;setActivatorService&lt;/code&gt;. Once this method get called, OSGI bundle will start the &lt;code&gt;ActivatorService&lt;/code&gt; &lt;code&gt;start&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;You can build more advanced applications by using the OSGI framework. You build dynamically pluggable components with dependency injection design pattern.  &lt;/p&gt;

</description>
      <category>osgi</category>
      <category>java</category>
      <category>standalone</category>
    </item>
    <item>
      <title>Change Elasticsearch watermark size</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Tue, 27 Jul 2021 04:01:04 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/change-elasticsearch-watermark-size-4k7h</link>
      <guid>https://forem.com/dhanushkadev/change-elasticsearch-watermark-size-4k7h</guid>
      <description>&lt;p&gt;Storage overflow watermark error message is a common message that throws when disk space is not enough on your elasticsearch cluster. You can reduce the allocated disk watermark size by sending a HTTP request to the elasticsearch. Following is the curl command that you can use to change the watermark size on elasticsearch instance running on the localhost:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "10gb",
    "cluster.routing.allocation.disk.watermark.high": "5gb",
    "cluster.routing.allocation.disk.watermark.flood_stage": "5gb",
    "cluster.info.update.interval": "1m"
  }
}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Important keytool commands to work with keystores and truststores</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Thu, 29 Apr 2021 08:37:00 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/important-key-tool-commands-to-work-with-keystores-and-truststores-1nhm</link>
      <guid>https://forem.com/dhanushkadev/important-key-tool-commands-to-work-with-keystores-and-truststores-1nhm</guid>
      <description>&lt;p&gt;Generate Keystore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;keytool -genkey -alias alice -keyalg RSA -keysize 2048 -keystore interop2.jks -dname "CN=Alice, OU=Wso2, O=Wso2, L=Wso2, ST=Wso2, C=LK" -storepass password -keypass password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View Keystore details&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;keytool -v -list -keystore interop2.jks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Export certificate from Keystore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;keytool -export -alias alice -keystore interop2.jks -file interop2alice.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Import certificates to Truststore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;keytool -import -alias alice -file interop2alice.pem -keystore sts.jks -storepass password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ssl</category>
      <category>certificates</category>
      <category>keytool</category>
    </item>
    <item>
      <title>Creating a simple HTTP server with NPM</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Thu, 28 Jan 2021 16:46:53 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/creating-a-simple-http-server-with-npm-33m9</link>
      <guid>https://forem.com/dhanushkadev/creating-a-simple-http-server-with-npm-33m9</guid>
      <description></description>
    </item>
    <item>
      <title>What is Git and how it works</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Mon, 15 Jun 2020 18:26:07 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/what-is-git-and-how-it-works-3km6</link>
      <guid>https://forem.com/dhanushkadev/what-is-git-and-how-it-works-3km6</guid>
      <description>&lt;p&gt;As programmers we use Git to save last successful state of a code. Git has simple way of keeping and versioning history in Git repository. Git keep data as combination of following objects.&lt;/p&gt;

&lt;p&gt;Blob : This object used to store content of single file&lt;br&gt;
Tree : Reference to another blog or sub-tree&lt;br&gt;
Commit : Commit data (Auther, Commiter ect) and reference to tree object&lt;br&gt;
Tag : Reference to Commit object.&lt;/p&gt;

&lt;p&gt;Here, what is git and how it works.&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=AfZcSewF-qw"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vn0devJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://img.youtube.com/vi/AfZcSewF-qw/0.jpg" alt="How Git works"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>versioning</category>
      <category>svn</category>
    </item>
    <item>
      <title>First glimpse of Ballerina language: The Language of Integration</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Tue, 03 Sep 2019 05:04:41 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/first-glimpse-of-ballerina-language-language-of-integration-4efj</link>
      <guid>https://forem.com/dhanushkadev/first-glimpse-of-ballerina-language-language-of-integration-4efj</guid>
      <description>&lt;p&gt;Ballerina is the latest programming language released on the alpha version on August 3rd of this year. There are more than a thousand programming languages out there. Why do you need another programming language? Ballerina language intended to simplify the particular programming domain known as integration. You may be a developer who develops different kinds of web services and intends to interconnect those services. Then the Ballerina language will be your next programming companion.&lt;/p&gt;

&lt;p&gt;This post is intended to give you an introduction to Ballerina, a flexible, powerful and beautiful programming language that helps you implement any sort of integration requirements. You can download and install Ballerina from the official &lt;a href="https://ballerina.io/downloads/"&gt;Ballerinalang&lt;/a&gt; website.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does it look like?
&lt;/h2&gt;

&lt;p&gt;When I said that this is a programming language, the first concern that comes to your mind is how it looks. Ballerina language syntax takes shape based on programming languages such as Java, Go and JavaScript. Ballerina is a static typed language. For example, if you need to define an integer, the syntax would be the following.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int total = 99;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Same as the other languages, Ballerina has the main method, which is the primary program entry point. You can write a simple "hello world" as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ballerina/io;

public function main() {
    io:println("Hello, World!");
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Apart from regular primitive data types, Ballerina provides various non-primitive data types, such as Arrays, Tuples, Maps, Tables, Union, etc. Ballerina represent nil as bracket "()"&lt;/p&gt;

&lt;p&gt;Another special type of variable is that "anydata" data type. This type is a union  of the &lt;code&gt;()|boolean|int|float|decimal|string|(anydata|error)[]|map&amp;lt;anydata|error&amp;gt;|xml|table&lt;/code&gt; data types. anydata variables can be used in places where you expect pure values.&lt;/p&gt;

&lt;p&gt;Since Ballerina specifically designed to construct apps operating on networks, it natively supports JSON and XML.  You can easily define a JSON variables as the following in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;json user = {
         fname: "Peter",
         lname: "Stallone",
         "age": age,
         address: {
             line: "20 Palm Grove",
             city: "Colombo 03",
             country: "Sri Lanka"
         }
    };
io:println(user.address.country);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Same way you can define XML object as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xml x1 = xml `&amp;lt;book&amp;gt;The Lost World&amp;lt;/book&amp;gt;`;
io:println(x1);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ballerina offers built-in libraries for the implementation of different kinds of functionalities. In Ballerina, this is called modules. Modules are working the same as Java packages. You can import built-in modules or your own modules into your application. Ballerina has built-in logging, math, encoding, string, caching, time, file processing, and many more modules.&lt;/p&gt;

&lt;p&gt;Flow control of the syntax is the same as other languages. It provides support for the syntax "if else," "while" and "foreach." Foreach syntax provides iteration support over arrays and maps. If you are looking for an appealing way to verify the null, then Ballerina will give the to Elvis operator to verify whether the specified variable is null or not. Syntax would be as 'expression?: expressionIfNil' and, below, an example to verify whether variable x is null or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string elvisOutput = x ?: "value is nil";
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Object Oriented Programming with Ballerina
&lt;/h2&gt;

&lt;p&gt;Ballerina does provide assistance for object-oriented programming. The Ballerina OOP syntax seems closer to the Python OOP syntax. Here is an example for defining objects with a constructors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Person object {
    public int age;
    public string firstName;
    public string lastName;

    function __init(int age, string firstName, string lastName) {
        self.age = age;
        self.firstName = firstName;
        self.lastName = lastName;
    }

    function getFullName() returns string {
        return self.firstName + " " + self.lastName;
    }

    function checkAndModifyAge(int condition, int a);
};

function Person.checkAndModifyAge(int condition, int a) {

    if (self.age &amp;lt; condition) {
        self.age = a;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Instantiating object is simple and straight forward as "Person p1 = new(5, "John", "Doe");". Object can be access with dot(".") operator which is same as other languages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p1.getFullName()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ballerina is providing assistance for Encapsulation. Here you can define variables within an object with the appropriate access level. Ballerina supports the following access modifiers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;public — visible everywhere&lt;/li&gt;
&lt;li&gt;private — visible only within the same object&lt;/li&gt;
&lt;li&gt;no modifier — visible only within same package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also use abstraction concepts with Ballerina. Abstraction is a powerful OOP concept that is essential in the design of big modular software. You can define and reuse abstract objects in ballerina. You can convert an object to an abstract object by using an abstract keyword.  Example abstract Person object would be as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Person abstract object {
    public int age;
    public string firstName;
    public string lastName;

    function getFullName() returns string;

    function checkAndModifyAge(int condition, int a);
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can reuse the Person object as follows to reuse the variables and methods in the Person objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Employee abstract object {

    *Person;    
    public float salary;

    function __init(int age, string firstName, string lastName) {
        self.age = age;
        self.firstName = firstName;
        self.lastName = lastName;
    }
    function getSalary() returns float;

};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There is one more remaining concept of OOP known as Polymorphism to finish OOP concepts in the Ballerina languages. Polymorphism can also be implemented in the Ballerina language as follows in previous code segments. Here, a person object can have many types, as it is an abstract class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Person p = new Employee(5, "John", "Doe");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Integration with Ballerina language
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier on the introduction, Ballerina was specially designed to solve integration problems. We live in a globe where thousands of web servers are running and interacting with each other. Early developers had problems of connecting these services with each other. Enterprise Integration Bus emerges as a solution to the problems of integration. The ESB model offers an elegant way to interconnect distinct kinds of services with each other. The common issue with these ESB products is that it is difficult to configure and less flexible.&lt;/p&gt;

&lt;p&gt;Compared to ESB, Ballerina is more user-friendly so that developers can design the system by coding. Ballerina offers built-in libraries to solve all kinds of integration problems.&lt;/p&gt;

&lt;p&gt;The general requirement of integration is to read, forward and transform messages between distinct protocols. Ballerina provides built-in assistance for HTTP, HTTPS, HTTP2, Websockets, GRPC, TCP, UDP, etc transports.&lt;/p&gt;

&lt;p&gt;Ballerina can function as both a client and a server. Sending a request to another endpoint is simple, as it requires only three lines of code. You can easily call the REST API backend by setting the request headers as needed. Since Ballerina supports JSON natively, you can directly manipulate JSON content within the software without importing modules from third parties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ballerina/http;
http:Client clientEndpoint = new("https://postman-echo.com");
public function main() {
    var response = clientEndpoint-&amp;gt;get("/get?test=123");
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;On the other hand, you can create an HTTP server with a ballerina language. You can use built-in security features to secure your HTTPS link.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ballerina/http;
import ballerina/log;
http:ServiceEndpointConfiguration helloWorldEPConfig = {
    secureSocket: {
        keyStore: {
            path: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
            password: "ballerina"
        }
    }
};

listener http:Listener helloWorldEP = new(9095, config = helloWorldEPConfig);

@http:ServiceConfig {
    basePath: "/hello"
}
service helloWorld on helloWorldEP {
    @http:ResourceConfig {
        methods: ["GET"],
        path: "/"
    }
    resource function sayHello(http:Caller caller, http:Request req) {
        var result = caller-&amp;gt;respond("Hello World!");
        if (result is error) {
            log:printError("Error in responding ", err = result);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ballerina also provides support for streaming through the HTTP interface. Building GRPC and web socket based servers is straight forward and easy as building HTTP servers.&lt;/p&gt;

&lt;p&gt;Message brokers are one of the most important aspects of integration when it comes to reliable messaging. If you need to send messages reliably, you can use the Message Broker along with the Ballerina Integrator. Ballerina provides assistance for famous Message Brokers such as ActiveMQ, RabbitMQ and NATS. You can generate messages and receive messages with only a few lines of Ballerina codes that make it the best language to use with all integration requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, I attempted to explain the capabilities of Ballerina as a generic programming language as well as a specialized programming language for integration. There are a lot more features like threading, streaming, security, and native support for microservices that I haven't addressed here. I'm going to clarify these features to you in detail in another article. &lt;/p&gt;

&lt;p&gt;You can learn more about Ballerina language from their &lt;a href="https://ballerina.io"&gt;official site&lt;/a&gt;. There you can find example implementation for each use cases. You can follow me in &lt;a href="https://twitter.com/dhanushkadev"&gt;twitter&lt;/a&gt; to know more about tech stuff. Go to the Ballerina &lt;a href="https://ballerina.io/downloads/"&gt;download&lt;/a&gt; page and try it now. As its name suggests, it is flexible, powerful and beautiful.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>integration</category>
      <category>microservices</category>
      <category>ballerinalang</category>
    </item>
    <item>
      <title>A Weird Java Code and How It Works</title>
      <dc:creator>Dhanushka madushan</dc:creator>
      <pubDate>Mon, 22 Jul 2019 15:28:49 +0000</pubDate>
      <link>https://forem.com/dhanushkadev/a-weird-java-code-and-how-it-works-1ll</link>
      <guid>https://forem.com/dhanushkadev/a-weird-java-code-and-how-it-works-1ll</guid>
      <description>&lt;p&gt;I discovered following strange Java code that print &lt;code&gt;Just another Java hacker&lt;/code&gt; on your terminal.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Obviously, that piece of code looks like mess. Even if you copy this code into your favorite IDE, IDE could not figure out the syntax of this code. Trust me, this piece of code works,  and this is how it works.&lt;/p&gt;

&lt;p&gt;Obviously it has class name with main method. Let's clear out the code and format it. Now it look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Sig{
    public static void main(String...args){
        \u0066or(int\u0020$:"vÌÈÊ\"¤¾ÀÊ²¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
        )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($&amp;gt;&amp;gt;
        +(~'"'&amp;amp;'#'))+('&amp;lt;'&amp;gt;&amp;gt;('\\'/'.')/\u002Array.const(~1)\*\u002F)));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can see that there are some unicode characters in this code. Next we'll extract all unicode characters. Also I'm removing &lt;code&gt;/*goto/*$/%\u0126//^\u002A\u002F&lt;/code&gt; and &lt;code&gt;\u002Array.const(~1)\*\u002F&lt;/code&gt; section since those code sections are just commented line written in unicode characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Sig{
    public static void main(String...args){
        for(int $:"vÌÈÊ\"¤¾ÀÊ²¬Æ\"v¤Î¤\"²¤¨¸¬Æ".toCharArray())
            System.out.print((char)(($&amp;gt;&amp;gt;+(~'"'&amp;amp;'#'))+('&amp;lt;'&amp;gt;&amp;gt;('\\'/'.'))));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you replace &lt;code&gt;(char)(($&amp;gt;&amp;gt;+(~'"'&amp;amp;'#'))+('&amp;lt;'&amp;gt;&amp;gt;('\\'/'.')))&lt;/code&gt; expression with relevant ascii values then it would be something like &lt;code&gt;(char)(($&amp;gt;&amp;gt;+(~42&amp;amp;35))+(60&amp;gt;&amp;gt;(92/46)))&lt;/code&gt;. This is equivalent to &lt;code&gt;(char)(c / 2 + 15)&lt;/code&gt;. Final output of the simplified code would be something like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Sig{
    public static void main(String...args){
        for(int $:"vÌÈÊ\"¤¾ÀÊ²¬Æ\"v¤Î¤\"²¤¨¸¬Æ".toCharArray())
            System.out.print((char)($ / 2 + 15));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the mystery has been resolved. For loop take each of the characters from the string change it value according to the equation and print it.&lt;/p&gt;

&lt;p&gt;Why don't you give it a try to write such a code with your favaourite language and comment it down?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning: Don't ever write this type of code in production repositories.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
