<?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 Asma Zinneera Jabir on Medium]]></title>
        <description><![CDATA[Stories by Asma Zinneera Jabir on Medium]]></description>
        <link>https://medium.com/@azinneera?source=rss-e502958d1f65------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IXsZgSqSPzHvZKKJ9wewgQ.jpeg</url>
            <title>Stories by Asma Zinneera Jabir on Medium</title>
            <link>https://medium.com/@azinneera?source=rss-e502958d1f65------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:51:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@azinneera/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[CI/CD with Cellery to update cell instances  in the k8s cluster]]></title>
            <link>https://medium.com/wso2-cellery/ci-cd-with-cellery-to-update-cell-instances-in-the-k8s-cluster-dbf0c1dbf5bb?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbf0c1dbf5bb</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[cellery]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 11:57:43 GMT</pubDate>
            <atom:updated>2019-08-16T06:53:46.025Z</atom:updated>
            <content:encoded><![CDATA[<h3>CI/CD with Cellery to update cell instances in the k8s cluster</h3><p>To ensure the speed and reliability of a changing deployment, CI/CD has become an important part and so DevOps engineers have a vital role in ensuring the upgrades/changes are incorporated into the deployment in a swift and automated manner. Therefore, CI/CD has become essential for a reliable deployment and Cellery has integral support for CI/CD and keeps improving to give a smooth ride for DevOps for creating and maintaining deployments.</p><p>To set a baseline for this article I shall brief out the terms CI/CD and Cellery.</p><h3>CI/CD</h3><p>CI/CD stands for Continuous Integration/Continuous Delivery and the official definitions of these terms are quoted below.</p><p><em>Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.</em></p><p><em>Continuous Delivery (CD) is the natural extension of Continuous Integration: an approach in which teams ensure that every change to the system is releasable, and that we can release any version at the push of a button. Continuous Delivery aims to make releases boring, so we can deliver frequently and get fast feedback on what users care about.</em></p><h3>Cellery</h3><p>Cellery is a code-first approach to building, integrating, running and managing composite microservice applications on Kubernetes. Cellery stands as a solution for lengthy yamls and eases out the extend-ability of k8s deployments. Also, it is secure by default and rich with observability, security and tooling. Read the <a href="https://github.com/wso2-cellery/sdk">Cellery Documentation</a> to explore more about Cellery. The article is written around the sample <a href="https://github.com/wso2-cellery/samples/tree/master/cells/hello-world">hello-world</a> and thus trying out this sample will make it easier to understand this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3Ttv3y5kAx-_VB6nfY5bg.png" /><figcaption>Image Source: <a href="https://github.com/wso2-cellery/sdk">https://github.com/wso2-cellery/sdk</a></figcaption></figure><p>As the initial features, Cellery supports CI/CD for updating cell images and for cell testing. For this writing, we shall focus on updating cell images and the cell testing will be discussed in a separate blog post.</p><p>Cellery supports updating container image of a running cell instance with a different version which is useful when changes are done in microservices. This writing will give you a kick-start on continuous deployment of cell images into a kubernetes cluster. I have used travis with GitOps to explain the simplicity of updating the changes to the k8s cluster using Cellery. Nonetheless, there is always room to explore and hence you can try out other CI/CD tools and educate us with your experience.</p><h3>GitOps</h3><p>GitOps is a productive way of incorporating changes into a k8s deployments. It is a developer friendly methodology for continuous development and deployment. Git is considered to be the single source of truth and any changes added will be set to reflect in the deployment through an automated deployment process.</p><h3>Travis</h3><p>Travis is a simple yet powerful continuous integration tool based on Github. Though travis is defined as a CI tool, it also has the ability to perform CD as well.</p><p>The example covers how CI/CD can be applied to existing cell based k8s deployment and therefore we need to create a k8s setup in order to test this example.</p><p><strong>Setting up a basic Cellery setup with a running cell instance.</strong></p><ol><li><a href="https://github.com/wso2-cellery/sdk#quickstart-guide">Download and Install Cellery</a></li><li>Create a basic cellery setup using the following command</li></ol><pre>cellery setup create local</pre><p>3. Build and run the <a href="https://github.com/wso2-cellery/samples/tree/master/cells/hello-world">hello-world sample</a></p><p>Build the cell image</p><pre>cellery build hello-world.bal myorg/hello:1.0.0</pre><p>Run the built cell image</p><pre>cellery run myorg/hello:1.0.0 -n foo</pre><p>4. Configure the host entries correctly as mentioned in the documentation and browse the url <a href="http://hello-world.com/">http://hello-world.com/</a>. You should see the message <strong>Hello World</strong> in the browser body.</p><p><strong>Steps for creating a CI/CD pipeline for updating cell images</strong></p><p>The sample repository used to test this scenario can be found <a href="https://github.com/azinneera/cicd-test">here</a>.</p><ol><li>Commit the cell definition ballerina file to the github repository</li><li>Create the template for .kube/config file</li><li>Create the travis config file</li><li>Configure settings in travis for building the repository by setting the appropriate environment variables</li></ol><p><strong>Creating the cell definition bal file</strong></p><p>A sample cell definition file written using Ballerina can be found <a href="https://medium.com/@azinneera/ci-cd-with-cellery-to-update-cell-instances-in-the-k8s-cluster-dbf0c1dbf5bb">here</a>. Commit this file to a github repository.</p><p><strong>Creating the .kube/config file</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e51331306a510c595cf425be18cc230a/href">https://medium.com/media/e51331306a510c595cf425be18cc230a/href</a></iframe><p>Make sure to keep the values of certificate-authority-data, client-certificate-data and client-key-data fields blank to set in the travis configuration file during the runtime using environment variables and these are sensitive information. Commit this skeleton file also to the the same repository.</p><p><strong>Creating the travis yaml file</strong></p><p>The travis yaml file should contain the instructions and configs. Travis will spawn a VM according to the configurations provided and run the instructions in the spawned VM.</p><p>Travis offers a template for this and the instructions should be saved in a file named .<em>travis.yml </em>and committed to the root level of the git repository.</p><p>For our scenario, the .travis.yml should contain the following steps.</p><p><strong><em>Prerequisites/Config</em></strong></p><p>Ballerina</p><p>Cellery</p><p>Kubectl</p><p>.kube/config</p><p><strong><em>Instructions</em></strong></p><p>Cellery build command</p><p>This will build the changed cell definition file with a tag different than the previous. I have used the git commit of the travis build.</p><p>Cellery update command</p><p>This will update the cell image of the running cell instance. Make sure to use the same instance name used when creating the deployment.</p><p>The .travis.yml for our scenario is shown below. Commit this file to the root of the github repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84b23c028807d6f688e1b4eab91d6127/href">https://medium.com/media/84b23c028807d6f688e1b4eab91d6127/href</a></iframe><p><strong>Configuring travis</strong></p><p>Go to build settings and configure general settings and set the environment variables for sensitive fields with encryption.</p><p>When a new commit is detected in the git repository, the travis build will run and the cell instance will be updated in the k8s cluster. After the first travis build browse the url <a href="http://hello-world.com/">http://hello-world.com/</a> and you should still see the message <strong>Hello World</strong> in the browser body.</p><p>Change the HELLO_NAME environment variable to Cellery in the cell definition bal file and commit it to the github.</p><pre>envVars: {<br>  HELLO_NAME: { value: “Cellery” }<br>}</pre><p>Once the travis build has completed, browse the url <a href="http://hello-world.com/">http://hello-world.com/</a> again and you should now see the message being changed to <strong>Hello Cellery</strong> in the browser body.</p><p>Cellery also supports updating the image of a specific component and environment variables attached to the component. refer to them <a href="https://github.com/wso2-cellery/sdk/blob/master/docs/cli-reference.md#cellery-update">here</a> and feel free to try out and share your thoughts and suggestions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbf0c1dbf5bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wso2-cellery/ci-cd-with-cellery-to-update-cell-instances-in-the-k8s-cluster-dbf0c1dbf5bb">CI/CD with Cellery to update cell instances  in the k8s cluster</a> was originally published in <a href="https://medium.com/wso2-cellery">wso2-cellery</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transforming backend error messages in WSO2 API Manager]]></title>
            <link>https://medium.com/@azinneera/transforming-backend-error-messages-in-wso2-api-manager-91bf8d744ad4?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/91bf8d744ad4</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[wso2-api-manager]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 18:17:33 GMT</pubDate>
            <atom:updated>2019-01-27T18:30:26.328Z</atom:updated>
            <content:encoded><![CDATA[<p>The default message mediation in the API Manager consists of three 3 sequences, namely in sequence, out sequence and the fault sequence. Once a request from a client is received at the gateway of the API Manager, the in sequence carries this message to the backend while the out sequences carries the response from the backend back to the client. The fault sequence is responsible for handling exceptions occurring in API Manager and carries the error response to the client.</p><p>API Manager provides extension points to the in sequence and out sequence which can be used to transform the request or response. There are many use cases where the request or response has to be customized and In this post I shall walk you through one of these use cases which I came across recently, that is, to change the message content sent to the client if the response from the backend is an error response such as a 500 or 404.</p><p>To learn more about the message flow between the client and the backend via API Manager, refer <a href="https://docs.wso2.com/display/AM220/Message+Flow+in+the+API+Manager+Gateway">Message Flow in the API Manager Gateway</a> section in the official API Manager documentation</p><p>When a request is initiated from the client to the API backend via gateway of the API Manager and when the backend responds with an error message, it is the out sequence of API Manager that carries the message back to the client. Some misthink this to be handled by the fault sequence but fault sequence will handle only the errors occurred within the API Manager product. Hence the error response sent from the backend is still routed back to the client by the out sequence. To transform this error message we can write an extension sequence to the out sequence. To learn more about mediation extensions you can refer the section <a href="https://docs.wso2.com/display/AM210/Adding+Mediation+Extensions"><strong>Adding Mediation Extensions</strong></a> in the official API Manager documentation.</p><p><strong>Writing the out sequence mediation extension</strong></p><p>The below sequence is written to transform the message if the backend response code is 500.</p><p>This scenario would need a filter mediator to filter out messages with the 500 error code and then a PayloadFactory mediator to transform the message. An out sequence extension for this can be written as shown below.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;sequence <br> xmlns=&quot;<a href="http://ws.apache.org/ns/synapse">http://ws.apache.org/ns/synapse</a>&quot; <br> name=&quot;WSO2AM--Ext--Out&quot;&gt;<br>    &lt;filter source=&quot;$axis2:HTTP_SC&quot; regex=&quot;500&quot;&gt;<br>       &lt;then&gt;<br>    &lt;!--Defines the message format to be sent out to the client--&gt;<br>          &lt;payloadFactory media-type=&quot;xml&quot;&gt;<br>              &lt;format&gt;<br>                 &lt;am:fault xmlns:am=&quot;<a href="http://wso2.org/apimanager">http://wso2.org/apimanager</a>&quot;&gt;<br>                     &lt;am:code&gt;500&lt;/am:code&gt;<br>                     &lt;am:message&gt;Runtime Error&lt;/am:message&gt;<br>                 &lt;/am:fault&gt;<br>              &lt;/format&gt;<br>           &lt;/payloadFactory&gt;<br>       &lt;/then&gt;<br>       &lt;else/&gt;<br>     &lt;/filter&gt;<br>     &lt;send/&gt;<br>&lt;/sequence&gt;</pre><p>When the response code received from the backend is 500 the client application will receive the following response message from API Manager.</p><pre>&lt;am:fault xmlns:am=”<a href="http://wso2.org/apimanager">http://wso2.org/apimanager</a>&quot;&gt;   <br>    &lt;am:code&gt;500&lt;/am:code&gt;<br>    &lt;am:message&gt;Runtime Error&lt;/am:message&gt;<br>&lt;/am:fault&gt;</pre><p><strong>Applying the extension</strong></p><p>Now this extension can be deployed in several ways. In a distributed setup, this should be deployed in the Gateway node.</p><ol><li>Per API extensions</li><li>Global extensions</li></ol><p>Per API extensions can be used when you need to apply the extension to only one API or a selected set of APIs.</p><p>Global extensions are used when the extensions should be applied globally (to all APIs). But this will be global only for the carbon.super tenant. If it is a multi-tenant environment, the sequence should be added to each tenant manually.</p><p>If you have a requirement to add it to all tenants, then this could be done by writing a custom tenant creation observer by extending the <strong><em>org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver </em></strong>similar to <a href="https://github.com/wso2/carbon-apimgt/blob/6.x/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/internal/TenantServiceCreator.java">TenantServiceCreator</a> in carbon-apimgt component to load custom sequences from a certain directory when creating a tenant. This custom bundle can be deployed into <strong>&lt;APIM_HOME&gt;/repository/component/dropins</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91bf8d744ad4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Log4J2 for custom bundles with WSO2 Carbon 4]]></title>
            <link>https://medium.com/@azinneera/log4j2-for-custom-bundles-with-wso2-carbon-4-11938ef8f912?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/11938ef8f912</guid>
            <category><![CDATA[wso2-ei]]></category>
            <category><![CDATA[wso2-api-manager]]></category>
            <category><![CDATA[wso2-carbon]]></category>
            <category><![CDATA[wso2esb]]></category>
            <category><![CDATA[log4j2]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Sat, 26 Jan 2019 11:54:38 GMT</pubDate>
            <atom:updated>2019-01-26T12:05:06.158Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*Bl1ZJwCkmAbAjKwOw3U24A.jpeg" /><figcaption>Image source: <a href="http://chrisdrury.co.uk/">http://chrisdrury.co.uk</a></figcaption></figure><h3><strong>Carbon 4.4.x VS. Log4J2</strong></h3><p>The logging framework of WSO2 Carbon Kernel 4.4.x versions is implemented with Log4J 1.x as the logging back-end and Apache Commons Logging as the logging front-end. All WSO2 products built on Carbon 4.4.x versions use this logging framework. There are custom appenders written, namely the CarbonConsoleAppender, CarbonDailyRollingfileAppender and the CarbonMemoryAppender to log messages to the Carbon console, log file and to manage logs in the Management Console respectively. More details on the carbon logging framework can be found at <a href="https://docs.wso2.com/display/ADMIN44x/Monitoring+Logs"><strong>Monitoring Logs</strong></a><strong> </strong>section in the Official Documentation.</p><p>With the release of Log4J2, feasibility of migrating Carbon 4.4.x was analyzed but since Log4J2 has major changes like the changes in the syntax and name of the configuration file, improvements in the custom appenders concept and the API separation in the implementation made it backward incompatible.</p><p>Log4J2 is incorporated in Carbon Kernel 5.x.x. So Log4J2 can be expected in an upcoming major release of WSO2 products.</p><p><strong>The Known Stuff</strong></p><p>WSO2 Carbon Kernel is built upon OSGi technology and therefore the carbon components are deployed as OSGi bundles. To have a better understanding about OSGi you can refer the <a href="https://www.osgi.org/developer/what-is-osgi/">What is OSGi?</a> section in the OSGi Alliance. Any WSO2 product is a collection of different components and these components use the logging framework of Carbon 4.4.x to log to different destinations.</p><p>The Carbon Kernel has the WSO2 Carbon Logging Component to serve the logging dependencies. This exposes Apache Commons Logging packages for the logging front-end and Log4J 1.x packages for the logging backend. Other components make a dependency on Carbon Logging and log through the Carbon Logging Framework.</p><h3><strong>Carbon 4.4.x AND Log4J2</strong></h3><p>But this limitation couldn’t stop custom bundles from using Log4J2. Since Log4J2 has some advanced logging capabilities there could be requirements to use Log4J2 which can be done for third-party bundles deployed in Carbon 4.4.x based products.</p><p><em>You might need a custom handler in API Manager 2.x with Log4J2 or a Class Mediator in ESB or EI with Log4J2.</em></p><p>The rest of the blog will walk you through the approach to achieve this.</p><p>According to the OSGi way of handling dependencies, what needs to be done is that the custom bundle should have Log4J2 in its classpath and not have Log4J 1. But Carbon logging component has already exposed Log4J1 and therefore, regardless of the logging API used in the classes (Commons Logging, SLF4J) these will be logged through Log4J 1.x at the logging back-end. Of course there are bridges to map from JCL-Log4J2 or SLF4J-Log4J2 but you will have to make sure these bridges are only exposed to your custom bundle because bridges don’t work well with custom appenders yet.</p><p>Alternatively, you can use Log4J2 both as the API in the front-end and at the back-end. This would be way to use Log4J2 in your custom bundle with minimal effort. Simply use the Log4J2 Logger in your java classes and add both log4j2-api and log4j2-core to the classpath and additionally the configuration file: log4j2.xml or log4j2.properties as well. This way your custom bundle will use only Log4J2.</p><p><strong>The Approach</strong></p><p>The default Log4J2 jars (log4j2-api and log4j-core) has some imports required and therefore if these external dependencies are not imported by some component, these bundles will not be activated in the OSGi console. You cannot find any WSO2 Carbon components exposing all of the libraries required by Log4J2.</p><p>To resolve this, you can create bundle as an uber jar using the <a href="https://maven.apache.org/plugins/maven-shade-plugin/">maven-shade-plugin</a> and package all the dependencies into this. As an alternative, you can also package this to your custom bundle but if you want log4J2 in more than one bundle then including the libraries in each of these bundles will make your bundles heavy and of course you are reinventing the wheel. Therefore, I prefer creating a separate bundle as the provider for Log4J2 packages which the custom bundles can consume.</p><p>I have written a sample custom authentication handler for API Manager and a Class Mediator for EI to Log with Log4J2. You can download the complete project from <a href="https://github.com/azinneera/C4Log4J2Samples">https://github.com/azinneera/C4Log4J2Samples</a>.</p><p>Now, lets walk through the steps for Creating a Class Mediator for EI and a Custom Handler for API Manager.</p><p>The steps are common for both unless for the places to deploy the bundles but for better clarity they are explained separately below. The steps required o be done which is common for both are:</p><ol><li>Create the Log4J2 uber jar</li><li>Create the custom bundle for the Class Mediator / Custom Handler</li><li>Create the Log4J2 configuration file</li><li>Add the above to the necessary places in the WSO2 product</li><li>Modify the integrator.sh / wso2carbon.sh to add the system property to set the Log4J2 configuration file</li><li>Restart the WSO2 server</li><li>Create an API and test the Class mediator / Custom Handler</li></ol><h3><strong>Creating a Class Mediator for EI</strong></h3><p>Though the sample is written for EI, it can be used with ESB built on Carbon 4.4.x as well. Just identify the correct places to deploy the bundles and modify the files.</p><ol><li>Create a Log4J2 uber jar to package Log4J2 and its required dependencies</li></ol><p><strong>i.</strong> Create a maven project containing a pom.xml and a java class for the Activator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/0*RbnVgU1H1cqraBXJ" /><figcaption>Maven Project Structure</figcaption></figure><p><strong>ii.</strong> Modify the pom to add the maven shade plugin and the required bundle configurations. Make sure to export ONLY org.apache.logging.log4j.*. Refer the complete <a href="https://github.com/azinneera/C4Log4J2Samples/blob/master/C4Log4J2Samples/ClassMediatorSample/org.wso2.carbon.test.class.mediator/pom.xml">pom in the sample</a>.</p><pre>&lt;<strong>plugin</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;org.apache.felix&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;maven-bundle-plugin&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>extensions</strong>&gt;true&lt;/<strong>extensions</strong>&gt;<br>    &lt;<strong>configuration</strong>&gt;<br>        &lt;<strong>instructions</strong>&gt;<br>            &lt;<strong>Bundle-SymbolicName</strong>&gt;<br>             ${project.artifactId}<br>            &lt;/<strong>Bundle-SymbolicName</strong>&gt;<br>            &lt;<strong>Bundle-Name</strong>&gt;${project.artifactId}&lt;/<strong>Bundle-Name</strong>&gt;<br>            &lt;<strong>Import-Package</strong>&gt;<br>                org.osgi.framework.*,<br>                org.osgi.service.*<br>            &lt;/<strong>Import-Package</strong>&gt;<br>            &lt;<strong>Export-Package</strong>&gt;<br>                org.apache.logging.log4j.*<br>            &lt;/<strong>Export-Package</strong>&gt;<br>            &lt;<strong>Bundle-Activator</strong>&gt;<br>             org.wso2.carbon.log4j2.internal.CarbonLog4J2Activator<br>            &lt;/<strong>Bundle-Activator</strong>&gt;<br>        &lt;/<strong>instructions</strong>&gt;<br>    &lt;/<strong>configuration</strong>&gt;<br>&lt;/<strong>plugin</strong>&gt;<br>&lt;<strong>plugin</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;org.apache.maven.plugins&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;maven-shade-plugin&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>version</strong>&gt;2.4.3&lt;/<strong>version</strong>&gt;<br>    &lt;<strong>executions</strong>&gt;<br>        &lt;<strong>execution</strong>&gt;<br>            &lt;<strong>phase</strong>&gt;package&lt;/<strong>phase</strong>&gt;<br>            &lt;<strong>goals</strong>&gt;<br>                &lt;<strong>goal</strong>&gt;shade&lt;/<strong>goal</strong>&gt;<br>            &lt;/<strong>goals</strong>&gt;<br>        &lt;/<strong>execution</strong>&gt;<br>    &lt;/<strong>executions</strong>&gt;<br>&lt;/<strong>plugin</strong>&gt;</pre><p><strong>iii. </strong>Create the CarbonLog4J2Activator Java class to activate the bundle</p><pre><strong>package </strong>org.wso2.carbon.log4j2.internal;</pre><pre><strong>import </strong>org.apache.logging.log4j.LogManager;<br><strong>import </strong>org.apache.logging.log4j.Logger;<br><strong>import </strong>org.osgi.framework.BundleActivator;<br><strong>import </strong>org.osgi.framework.BundleContext;<br><br><strong>public class </strong>CarbonLog4J2Activator <strong>implements </strong>BundleActivator {<br>    <strong>private static final </strong>Logger logger = <br>          LogManager.getLogger(CarbonLog4J2Activator.<strong>class</strong>);<br><br>    <strong>public void </strong>start(BundleContext bundleContext) <br>          <strong>throws </strong>Exception {<br>        <strong>if </strong>(logger.isDebugEnabled()) {<br>            logger.debug(<strong>&quot;Carbon Log4J2 bundle is activated.&quot;</strong>);<br>        }<br>    }<br><br>    <strong>public void </strong>stop(BundleContext bundleContext) <br>          <strong>throws </strong>Exception {<br>        <em>//do nothing<br>    </em>}<br>}</pre><p>2. Create the Class Mediator</p><p><strong>i.</strong> Create another maven project containing a pom.xml and a Java class for the class mediator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/0*T9dLoj7SCelxVhqW" /></figure><p><strong>ii.</strong> Modify the pom as below to add the maven shade plugin and the required bundle configurations. Make sure to import <em>org.apache.logging.log4j.*</em> and export only the classes related to the Class Mediator. Add the Log4J2 dependencies as well.</p><pre>&lt;<strong>plugin</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;org.apache.felix&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;maven-bundle-plugin&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>version</strong>&gt;1.4.0&lt;/<strong>version</strong>&gt;<br>    &lt;<strong>extensions</strong>&gt;true&lt;/<strong>extensions</strong>&gt;<br>    &lt;<strong>configuration</strong>&gt;<br>        &lt;<strong>instructions</strong>&gt;<br>            &lt;<strong>Bundle-SymbolicName</strong>&gt;<br>              org.wso2.carbon.test<br>            &lt;/<strong>Bundle-SymbolicName</strong>&gt;<br>            &lt;<strong>Bundle-Name</strong>&gt;org.wso2.carbon.test&lt;/<strong>Bundle-Name</strong>&gt;<br>            &lt;<strong>Export-Package</strong>&gt;<br>                org.wso2.carbon.test.*,<br>            &lt;/<strong>Export-Package</strong>&gt;<br>            &lt;<strong>Import-Package</strong>&gt;<br>                org.apache.logging.log4j.*,<br>                *; resolution:=optional<br>            &lt;/<strong>Import-Package</strong>&gt;<br>        &lt;/<strong>instructions</strong>&gt;<br>    &lt;/<strong>configuration</strong>&gt;<br>&lt;/<strong>plugin</strong>&gt;</pre><pre>&lt;<strong>dependency</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;org.apache.logging.log4j&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;log4j-core&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>version</strong>&gt;2.11.1&lt;/<strong>version</strong>&gt;<br>&lt;/<strong>dependency</strong>&gt;<br>&lt;<strong>dependency</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;org.apache.logging.log4j&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;log4j-api&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>version</strong>&gt;2.11.1&lt;/<strong>version</strong>&gt;<br>&lt;/<strong>dependency</strong>&gt;</pre><p><strong>iii.</strong> Develop a simple Class Mediator. For the sample I have used the sample code given in the EI documentation for <a href="https://docs.wso2.com/display/EI611/Class+Mediator">Class Mediator</a> and modified to add a log statement.</p><pre><strong>package </strong>org.wso2.carbon.test;<br><br><strong>import </strong>org.apache.logging.log4j.LogManager;<br><strong>import </strong>org.apache.logging.log4j.Logger;<br><strong>import </strong>org.apache.synapse.MessageContext;<br><strong>import </strong>org.apache.synapse.mediators.AbstractMediator;<br><br><strong>public class </strong>SimpleClassMediator <strong>extends </strong>AbstractMediator {<br><br>    <strong>private static final </strong>Logger logger = <br>       LogManager.getLogger(SimpleClassMediator.<strong>class</strong>);<br><br>    <strong>private </strong>String variable1=<strong>&quot;10&quot;</strong>;<br><br>    <strong>private </strong>String variable2=<strong>&quot;10&quot;</strong>;<br><br>    <strong>private int </strong>variable3=0;<br><br>    <strong>public </strong>SimpleClassMediator(){}<br><br>    <strong>public boolean </strong>mediate(MessageContext mc) {<br>        <em>// Do somthing useful..<br>        // Note the access to the Synapse Message context<br>        </em>logger.info(<strong>&quot;----------Simple Class Medaitor. This line is logged by Log4J2----------&quot;</strong>);<br>        <strong>return true</strong>;<br>    }<br><br>    <strong>public </strong>String getType() {<br>        <strong>return null</strong>;<br>    }<br><br>    <strong>public void </strong>setTraceState(<strong>int </strong>traceState) {<br>        traceState = 0;<br>    }<br><br>    <strong>public int </strong>getTraceState() {<br>        <strong>return </strong>0;<br>    }<br><br>    <strong>public void </strong>setVariable1(String newValue) {<br>        variable1=newValue;<br>    }<br><br>    <strong>public </strong>String getVariable1() {<br>        <strong>return </strong>variable1;<br>    }<br><br>    <strong>public void </strong>setVariable2(String newValue){<br>        variable2=newValue;<br>    }<br><br>    <strong>public </strong>String getVariable2(){<br>        <strong>return </strong>variable2;<br>    }<br>}</pre><p>3. Create a Log4J2 configuration file. I have created a sample log4j2.xml for the sample. The below sample config file will print the log statements in the Class Mediator to the Carbon console and <strong>&lt;EI_HOME&gt;/repository/logs/carbon.log</strong> file.</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>Configuration</strong>&gt;    &lt;<strong>Appenders</strong>&gt;<br>        &lt;<strong>Console name=&quot;CARBON_CONSOLE&quot; target=&quot;SYSTEM_OUT&quot;</strong>&gt;<br>            &lt;<strong>PatternLayout pattern=&quot;[%d] %5p {%c} - %m%ex%n&quot;</strong>/&gt;<br>        &lt;/<strong>Console</strong>&gt;<br>        &lt;<strong>RollingFile name=&quot;CARBON_LOGFILE&quot; <br>          fileName=&quot;${sys:carbon.home}/repository/logs/carbon.log&quot;<br>          filePattern=&quot;${sys:carbon.home}/logs/carbon-%d{MM-dd-yyyy}.log&quot;</strong>&gt;<br>            &lt;<strong>PatternLayout pattern=&quot;[%d] %5p {%c} - %m%ex%n&quot;</strong>/&gt;<br>            &lt;<strong>Policies</strong>&gt;<br>                &lt;<strong>TimeBasedTriggeringPolicy</strong>/&gt;<br>            &lt;/<strong>Policies</strong>&gt;<br>        &lt;/<strong>RollingFile</strong>&gt;<br>    &lt;/<strong>Appenders</strong>&gt;</pre><pre>    &lt;<strong>Loggers</strong>&gt;<br>        &lt;<strong>Root level=&quot;info&quot;</strong>&gt;<br>            &lt;<strong>AppenderRef ref=&quot;CARBON_CONSOLE&quot;</strong>/&gt;<br>            &lt;<strong>AppenderRef ref=&quot;CARBON_LOGFILE&quot;</strong>/&gt;<br>        &lt;/<strong>Root</strong>&gt;<br>        <em>&lt;!--&lt;Logger name=&quot;org.wso2.carbon.kernel&quot; level=&quot;debug&quot;/&gt;--&gt;<br>     </em>&lt;<strong>Logger name=&quot;org.hibernate.validator&quot; level=&quot;error&quot;</strong>/&gt;<br>    &lt;/<strong>Loggers</strong>&gt;<br>&lt;/<strong>Configuration</strong>&gt;</pre><p>4. Build the maven projects, obtain the jars and place them in &lt;<strong>EI_HOME&gt;/dropins </strong>and place the log4j2.xml file in <strong>&lt;EI_HOME&gt;/conf</strong></p><p>5. Set the system property for log4j2 configuration by adding the following line to <strong>&lt;EI_HOME&gt;/bin/integrator.sh</strong></p><pre>-Dlog4j.configurationFile=”$CARBON_HOME/conf/log4j2.xml” \</pre><p>6. Restart the EI server</p><p>7. Add this class mediator to an API in EI and check for the log line printed by <strong>org.wso2.carbon.test.SimpleClassMediator</strong> in the Carbon Console and the <strong>&lt;PRODUCT_HOME&gt;/repository/logs/carbon.log</strong> file.</p><h3><strong>Creating a Custom Handler for API Manager</strong></h3><ol><li>Create a Log4J2 uber jar to package Log4J2 and its required dependencies.</li><li>Create the Custom Handler</li></ol><p><strong>i. </strong>Create another maven project containing a pom.xml and a Java class for the custom handler</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/0*oKRgRahnmw08r6mC" /></figure><p><strong>ii.</strong> Modify the pom to add the maven shade plugin and the required bundle configurations. Make sure to import <em>org.apache.logging.log4j.*</em> and export only the classes related to the Custom handler. Refer the complete <a href="https://github.com/azinneera/C4Log4J2Samples/blob/master/C4Log4J2Samples/CustomAuthHandlerSample/org.wso2.carbon.test.authenticator/pom.xml">pom in the sample</a>.</p><p><strong>iii.</strong> Develop a simple Custom Handler. For the sample I have used the sample code given in the API Manager documentation for <a href="https://docs.wso2.com/display/AM220/Writing+Custom+Handlers#WritingCustomHandlers-Writingacustomhandler">Writing a custom handler</a> and modified to add a log statement.</p><pre><strong>package </strong>org.wso2.carbon.test;<br><br><strong>import </strong>org.apache.logging.log4j.LogManager;<br><strong>import </strong>org.apache.logging.log4j.Logger;<br><strong>import </strong>org.apache.synapse.MessageContext;<br><strong>import </strong>org.apache.synapse.core.axis2.Axis2MessageContext;<br><strong>import </strong>org.apache.synapse.rest.AbstractHandler;<br><strong>import </strong>org.wso2.carbon.apimgt.gateway.handlers.security.APISecurityException;<br><br><strong>import </strong>java.util.Map;<br><br><strong>public class </strong>CustomAPIAuthenticationHandler <strong>extends </strong>AbstractHandler {<br><br>  <strong>public static final </strong>Logger logger = <br>       LogManager.getLogger(CustomAPIAuthenticationHandler.<strong>class</strong>);<br><br>  <strong>public boolean </strong>handleRequest(MessageContext messageContext) {<br>     <strong>try </strong>{<br>          <strong>if </strong>(authenticate(messageContext)) {<br>                <strong>return true</strong>;<br>          }<br>     } <strong>catch </strong>(APISecurityException e) {<br>            e.printStackTrace();<br>     }<br>     <strong>return false</strong>;<br>  }<br><br>  <strong>public boolean </strong>handleResponse(MessageContext messageContext) {<br>     <strong>return true</strong>;<br>  }<br><br>  <strong>public boolean </strong>authenticate(MessageContext synCtx) <br>     <strong>throws </strong>APISecurityException {</pre><pre>     logger.info(<strong>&quot;-----------Custom Auth Handler - This should be logged by Log4J2 --------------&quot;</strong>);</pre><pre>     Map headers = getTransportHeaders(synCtx);<br>     String authHeader = getAuthorizationHeader(headers);<br>     <strong>if </strong>(authHeader.startsWith(<strong>&quot;userName&quot;</strong>)) {<br>            <strong>return true</strong>;<br>     }<br>     <strong>return false</strong>;<br>  }<br><br>  <strong>private </strong>String getAuthorizationHeader(Map headers) {<br>     <strong>return </strong>(String) headers.get(<strong>&quot;Authorization&quot;</strong>);<br>  }<br><br>  <strong>private </strong>Map getTransportHeaders(MessageContext messageContext) {<br>     <strong>return </strong>(Map) ((Axis2MessageContext) messageContext).<br>       getAxis2MessageContext().getProperty(<br>       org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);<br>    }<br>}</pre><p>3. Create a Log4J2 configuration file. You can use the same log4j2.xml given for the EI Class mediator. This will print the log statements in the Class Mediator to the Carbon console and <strong>&lt;APIM_HOME&gt;/repository/logs/carbon.log</strong> file.</p><p>4. Build the maven projects, obtain the jars and place them in &lt;<strong>APIM_HOME&gt;/repository/components/dropins/ </strong>and place the log4j2.xml file in <strong>&lt;APIM_HOME&gt;/repository/conf</strong></p><p>5. Set the system property for log4j2 configuration by adding the following line to <strong>&lt;PRODUCT_HOME&gt;/bin/wso2server.sh</strong></p><pre>-Dlog4j.configurationFile=”$CARBON_HOME/repository/conf/log4j2.xml” \</pre><p>6. Engage the custom handler by modifying the <strong>&lt;APIM_HOME&gt;/repository/resources/api_templates/velocity_template.xml</strong> according to the instructions given in<a href="https://docs.wso2.com/display/AM220/Writing+Custom+Handlers#WritingCustomHandlers-Engagingthecustomhandler"> Engaging the custom handler</a> section of the API Manager documentation.</p><p>7. Create a new API</p><p>8. Invoke the API and check for the log line printed by org.wso2.carbon.test.CustomAPIAuthenticationHandler in the Carbon Console and the <strong>&lt;APIM_HOME&gt;/repository/logs/carbon.log</strong> file</p><p>This the the simplest way I found so far to incorporate Log4J2 in to custom bundles. Any clarifications or suggestions for improvements are welcome :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11938ef8f912" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating multiple UUIDs during XSLT transformation in WSO2 ESB]]></title>
            <link>https://medium.com/@azinneera/generating-multiple-uuids-during-xslt-transformation-in-wso2-esb-f1c5747242f8?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1c5747242f8</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[esb]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 17:25:13 GMT</pubDate>
            <atom:updated>2018-06-30T17:35:12.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Nz72nI3bctUUPku3E_uKw.jpeg" /></figure><p>In some cases you might need to generate UUIDs before sending it to the backend. WSO2 ESB directly accommodates generation of a single UUID or a fixed number of UUIDs.</p><h3><strong>Generating a UUID per message</strong></h3><p>Generation of a single UUID can be done with a property mediator. By using the messageID property mediator as below a UUID can be generated which will be unique to that request.</p><p><strong><em>&lt;property name=”MessageID” expression=”fn:substring-after(get-property(‘MessageID’), ‘urn:uuid:’)”/&gt;</em></strong></p><p>This can be used simply in your proxy services or APIs in ESB. More details on using property mediators can be found in the WSO2 ESB official documentation on <a href="https://docs.wso2.com/display/ESB490/Property+Mediator">Property Mediator</a>.</p><h3>Generating a fixed number of UUIDs per message</h3><p>When you want to generate more than one UUID per message, you can use a script mediator. A detailed description with an example on using the Script Mediator to generate UUIDs can be found <a href="http://mytecheye.blogspot.com/2013/10/wso2-esb-generate-uuid-using-script.html">here</a>.</p><h3>Generating an unknown number of UUIDs</h3><p>Script mediators will not be the approach if you need to generate an unknown number of UUIDs during an XSLT transformation. For example say you send a request in the following format.</p><pre>&lt;Order&gt;<br>    &lt;lunch&gt;<br>        &lt;meal&gt;Rice and Curry&lt;/meal&gt;<br>        &lt;mealPrice&gt;USD 10&lt;/mealPrice&gt;<br>        &lt;drinkName&gt;Dark Coffee&lt;/drinkName&gt;<br>        &lt;drinkPrice&gt;USD 1.8&lt;/drinkPrice&gt;<br>    &lt;/lunch&gt;<br>    &lt;lunch&gt;<br>        &lt;meal&gt;Sandwiches&lt;/meal&gt;<br>        &lt;mealPrice&gt;USD 4&lt;/mealPrice&gt;<br>        &lt;drinkName&gt;Milk Shake&lt;/drinkName&gt;<br>        &lt;drinkPrice&gt;USD 2.6&lt;/drinkPrice&gt;<br>    &lt;/lunch&gt;<br>    &lt;lunch&gt;<br>        &lt;meal&gt;Chicken Burger&lt;/meal&gt;<br>        &lt;mealPrice&gt;USD 5&lt;/mealPrice&gt;<br>        &lt;drinkName&gt;Iced Coffee&lt;/drinkName&gt;<br>        &lt;drinkPrice&gt;USD 1.5&lt;/drinkPrice&gt;<br>    &lt;/lunch&gt;<br>    &lt;lunch&gt;<br>        &lt;meal&gt;Noodles&lt;/meal&gt;<br>        &lt;mealPrice&gt;USD 8&lt;/mealPrice&gt;<br>        &lt;drinkName&gt;Bottled Water&lt;/drinkName&gt;<br>        &lt;drinkPrice&gt;USD 2.5&lt;/drinkPrice&gt;<br>    &lt;/lunch&gt;<br>&lt;/Order&gt;</pre><p>When you need a UUID for each &lt;li&gt; item and when the number of &lt;li&gt; items containing in the message vary this has to be handled in the XSLT stylesheet.</p><p><strong>Suggestion #1 — uuid:randomUUID() function</strong></p><p>The common solution is to use uuid:randomUUID() function in Saxon. But this would not work with Saxon HE licenses. WSO2 ESB uses Saxon HE.</p><p><strong>Suggestion #2 — DIY using the generate-id() function</strong></p><p>The widely proposed solution for Saxon HE users is to write their own function for this. A sample can be found <a href="https://github.com/opendatacz/TED_extractor/blob/master/xslt/uuid.xsl">here</a>.</p><p>This method uses the timestamp and the nodeID to generate UUIDs. But this does not work as expected as this produces the same nodeID and if the timestamp is identical, the UUIDs will be duplicated.</p><p>With a slight improvement I could get this to generate unique UUIDs :)</p><h3>Solution</h3><p>I tested using the <a href="https://www.w3schools.com/xml/func_generateid.asp">generate-id(node-set?)</a> method to generate unique IDs for each &lt;li&gt; item. After confirming, I used the same approach to generate unique UUIDs by improving the above XSLT template by modifying the required functions to accept the node as an argument.</p><p>The improved XSLT for the above example can be found <a href="https://gist.github.com/azinneera/778f69ae6b0049b5edcd69da70072405">here</a>. The response produced by this XSLT transformation is shown below.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;<br>   &lt;soapenv:Body&gt;<br>      &lt;Payment xmlns=&quot;http://ws.apache.org/ns/synapse&quot; xmlns:uuid=&quot;http://www.uuid.org&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;<br>         &lt;discount&gt;<br>            &lt;li uid=&quot;65DF0403-6973-11E8-1599-09173F13E4C5&quot;&gt;<br>               Dark Coffee<br>               &lt;span&gt;USD 1.8&lt;/span&gt;<br>            &lt;/li&gt;<br>         &lt;/discount&gt;<br>         &lt;discount&gt;<br>            &lt;li uid=&quot;65DF046C-6973-11E8-1599-09173F13E4C5&quot;&gt;<br>               Milk Shake<br>               &lt;span&gt;USD 2.6&lt;/span&gt;<br>            &lt;/li&gt;<br>         &lt;/discount&gt;<br>         &lt;discount&gt;<br>            &lt;li uid=&quot;65DF047B-6973-11E8-1599-09173F13E4C5&quot;&gt;<br>               Iced Coffee<br>               &lt;span&gt;USD 1.5&lt;/span&gt;<br>            &lt;/li&gt;<br>         &lt;/discount&gt;<br>         &lt;discount&gt;<br>            &lt;li uid=&quot;65DF048A-6973-11E8-1599-09173F13E4C5&quot;&gt;<br>               Bottled Water<br>               &lt;span&gt;USD 2.5&lt;/span&gt;<br>            &lt;/li&gt;<br>         &lt;/discount&gt;<br>      &lt;/Payment&gt;<br>   &lt;/soapenv:Body&gt;<br>&lt;/soapenv:Envelope&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1c5747242f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using non-OSGi jars with WSO2 Products]]></title>
            <link>https://medium.com/@azinneera/using-non-osgi-jars-with-wso2-products-b93e3920ada8?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/b93e3920ada8</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[osgi]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 15:51:46 GMT</pubDate>
            <atom:updated>2018-06-30T17:54:27.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*pvFy7C-v-5jKtaQMOoptxA.jpeg" /></figure><p>WSO2 products allow deploying non-OSGi libraries in &lt;PRODUCT_HOME&gt;/repository/components/lib. These will be converted to OSGi bundles by WSO2 Carbon platform and exposed with the version <strong>0.0.0</strong>. regardless of the version of the original jar. For example foo-1.5.7 jar when copied to &lt;PRODUCT_HOME&gt;/repository/components/lib it will be converted to and OSGi bundle and exposed as foo_1.5.7_0.0.0.jar which can be found in &lt;PRODUCT_HOME&gt;/repository/components/dropins.</p><h3><strong>Approach for using non-OSGi libraries</strong></h3><p>This way WSO2 products allow you to use your non-OSGi jars in an OSGi environment. This approach works perfect for a non-OSGi jar which is not exposed by the WSO2 product be default. If you have a requirement to use a different version of a library this approach will not be the best. It is not recommended to use a version other than the one exposed by the WSO2 product on which grounds this implementation is done but if there are third-party bundles/jars requiring a version that is higher than of what is offered by the WSO2 product the approach to be taken is different. This will always give the priority to which is packed in the WSO2 product by default since the external bundle is given the version 0.0.0.</p><h3>Approach to use a different version of a library already exposed in WSO2 product</h3><p>When there are several versions of the same library, the usual OSGi way is to use &lt;Import-Package&gt; with a strict version range import. Refer <a href="http://www.eclipse.org/virgo/documentation/virgo-documentation-3.7.0.M01/docs/virgo-user-guide/html/ch02s02.html">here</a> for more details. But since the bundle you require is now exposed as v0.0.0, the applicable way is to pack all the dependent libraries into your bundle using these libraries as private packages and expose only the classes written in your bundle through &lt;Export-Package&gt;. When you use this approach it is not needed to deploy the non-OSGi jar in the &lt;PRODUCT_HOME&gt;/repository/components/lib.</p><p>This way you can use a higher version of a library that is already being exposed by WSO2 products.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b93e3920ada8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localizing your web application with WSO2 Identity Server]]></title>
            <link>https://medium.com/@azinneera/localizing-your-web-application-with-wso2-identity-server-single-sign-on-82f53556da14?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/82f53556da14</guid>
            <category><![CDATA[web-apps]]></category>
            <category><![CDATA[sso]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[localization]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Sun, 21 Jan 2018 19:43:47 GMT</pubDate>
            <atom:updated>2018-01-23T05:17:06.234Z</atom:updated>
            <content:encoded><![CDATA[<h4>An approach using Single Sign-On with SAML 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GwOz-0-ekDQPe4tloaSpzw.jpeg" /></figure><h4>Not one size fits all</h4><p>An important aspect to consider when developing web applications is localization. For a web application that aims to serve customers of multiple regions, localization is vital to scale up the reach. The stickiness or the user retention of a web application hugely increases when it is able to adapt itself to suit the user’s locale. This includes conversion of units of measure and currencies, adapting local formats for phone numbers and dates, etc.</p><h4><strong>Localization with WSO2 IS 5.3.0 Single Sign-On with SAML 2</strong></h4><p>With federated authentication, WSO2 IS already served passing additional parameters to the IdP initiated SSO (Single Sign-On)URL. This could be achieved by making use of the “Additional Query Parameter” textbox but this had been restricted to static values. With WSO2 Carbon 4.4.X Update 2018–01–15, WSO2 IS 5.3.0 supports passing dynamic values to the query parameters. With this update, WSO2 IS paves the way for localization and the web applications can send the locale in the SSO URL to detect the language of the user to localize the web application consistently across interfaces.</p><h4><strong>Using the Additional Query Parameter field for localization</strong></h4><p>WSO2 documentation on using Additional Query Parameters field is available <a href="https://docs.wso2.com/display/IS530/Configuring+Google">here</a> [1]. Both static and dynamic values are supported with the aforementioned WUM Update. Localization can be achieved by passing the locale as a dynamic query string parameter. Passing of the locale can be done as shown in the below example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nqGv5JC1m7anngcZD_1g-A.png" /></figure><p>A dynamic query parameter can be defined within <em>{}</em> as shown in the above example. Explaining with the above example, the SAML Request sent from the web application should contain a query parameter having the key <em>lang (eg: lang=en). </em>This will replace the value <em>{lang}</em> with <em>en</em> and append it to the IdP SSO URL as locale=en.</p><p><em>Based on the above, the query string parameters defined in the SAML request and how it is passed to the corresponding SSO URL are shown below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySTsclYenA_K0ktnhCLFhg.png" /><figcaption>String Query Parameters of the sample SAML Request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKhwIKIXAYIEYMr0lDAKTg.png" /><figcaption>String Query Parameters of the corresponding SSO URL</figcaption></figure><h4><strong>Testing with Single Sign-On travelocity sample web application</strong></h4><p>The travelocity sample can be used to test the passing of the locale as a dynamic query parameter using the Additional Query Parameter textbox. Configuring the travelocity can be found at <a href="https://docs.wso2.com/display/IS530/Configuring+Single+Sign-On.">Configuring Single Sign-On</a> [2].</p><p>After configuring the sample according to the documentation, additionally do the following.</p><ol><li>Open <em>&lt;TOMCAT_HOME&gt;/webapps/travelocity.com/WEB-INF/classes/travelocity.properties </em>and add query parameter strings as required.</li></ol><blockquote><strong>#Additional request parameters</strong></blockquote><blockquote><strong><em>SAML.Request.Query.Param=&amp;lang=en</em></strong></blockquote><p>2. Run the sample with the option “login with SAML from Identity Server”</p><p>You will see the string query parameters in the SAML request and the SSO URL similar to the above sample SAML request and the corresponding response.</p><h4>References</h4><p>[1] <a href="https://docs.wso2.com/display/IS530/Configuring+Google">https://docs.wso2.com/display/IS530/Configuring+Google</a></p><p>[2] <a href="https://docs.wso2.com/display/IS530/Configuring+Single+Sign-On">https://docs.wso2.com/display/IS530/Configuring+Single+Sign-On</a></p><p>[3] <a href="https://www.welocalize.com/three-reasons-localize-website/">https://www.welocalize.com/three-reasons-localize-website/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82f53556da14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Log4J2 in OSGi Environment]]></title>
            <link>https://medium.com/@azinneera/configuring-log4j-2-in-osgi-environment-70be42e95ef8?source=rss-e502958d1f65------2</link>
            <guid isPermaLink="false">https://medium.com/p/70be42e95ef8</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[osgi]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Asma Zinneera Jabir]]></dc:creator>
            <pubDate>Sat, 21 Oct 2017 12:15:53 GMT</pubDate>
            <atom:updated>2017-10-25T15:21:51.543Z</atom:updated>
            <content:encoded><![CDATA[<p>Unlike Log4J 1.x Log4J 2 comes with API separation with it being broken down into log4j-core and log4j-api. Log4J-core contains the implementation and the log4j-api can be used as a logging facade providing the adapter components required for implementers to create a logging implementation.</p><p>Due to the separation, Log4J 2 is not directly implementable in an OSGi environment. This is due to the separate classloaders loading the different bundles. Nonetheless, it can be configured in an OSGi environment in two ways.</p><p><strong>Solutions</strong></p><ol><li>Using the <a href="http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html">ServiceLoader</a> interface</li><li>Using <a href="https://github.com/ops4j/org.ops4j.pax.logging">pax-logging</a></li></ol><p>I would go for the second and thus this piece of writing will cover the way Log4J2 is configured with pax-logging. But before that, let me explain why not the first.</p><p>Making use of the ServiceLoader will require implementing Log4J 2 as a service provider and the bundles consuming as service consumers, and if you have used a different logging facade other than log4j like <em>jcl</em>(Jakarta Commons Logging) you might as well need the log4j bridge in the classpath. Not only that, you also need a workaround using two OSGi fragments: one for log4j-core and one for log4j-api. Due to different classloaders, log4j-core cannot identify the configuration file in its classpath and therefore a fragment should be created with the host being log4j-core with the configuration file packed inside of it. The log4j-api needs the log4j-provider.properties (residing in log4j-core bundle) in its classpath and hence another fragment with the host being log4-api has to provide this. If you have custom appenders, then these too have to go as a fragment of log4j-core. So you need the log4j-core, log4j-api, the bridge jar depending on your logging front-end (e.g. log4j-jcl) and at least two OSGi fragments.</p><p><strong>Using pax-logging</strong></p><p>Pax-logging is a logging framework that supports OSGi and thus eliminates the need for ServiceLoader and the workaround for classloading issues. Pax-logging provides the pax-logging-api which contains most of the logging facades. For the logging back-end it provides the pax-logging-log4j2 bundle. If you need to configure custom appenders for Log4J2, they should go into a fragment of pax-logging-log4j bundle.</p><h3>Setting up Log4J2 with pax-logging in the OSGi environment</h3><ol><li>Add the dependencies into the pom file of the bundle.</li></ol><pre>&lt;dependency&gt;<br>   &lt;groupId&gt;org.ops4j.pax.logging&lt;/groupId&gt;<br>   &lt;artifactId&gt;pax-logging-api&lt;/artifactId&gt;<br>   &lt;version&gt;1.10.1&lt;/version&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>   &lt;groupId&gt;org.ops4j.pax.logging&lt;/groupId&gt;<br>   &lt;artifactId&gt;pax-logging-log4j2&lt;/artifactId&gt;<br>   &lt;version&gt;1.10.1&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>2. Load the <em>pax-logging-api-1.10.1.jar</em> and <em>pax-logging-log4j2–1.10.1.jar</em> into the OSGi environment</p><p>3. Configure logging</p><p>Pax-logging has pax-logging.properties configuration file. It also allows to use the log4j2 configuration file. For this, you need to add an entry into pax-logging.properties to get the log4j2 configurations as shown below.</p><p><em>org.ops4j.pax.logging.log4j2.config.file=path/to/log4j2.properties</em></p><p>4. Writing custom appenders</p><p>Log4J 2 allows to extend and customize in a number of ways using Plugins. For adding a custom field you can use a converter or a lookup plugin. For appending to a destination of your own, you may use the appender plugin type (See <em>manual for </em><a href="https://logging.apache.org/log4j/2.x/manual/extending.html"><em>Extending Log4J2</em></a><em> for more</em>). All or any of these should be written in a OSGi fragment bundle of pax-logging-log4j2. You can find an example below.</p><p>A. Write a custom appender</p><pre>@Plugin(name = <strong>&quot;MemoryAppender&quot;</strong>, category = <strong>&quot;Core&quot;</strong>, elementType = <strong>&quot;appender&quot;</strong>, printObject = <strong>true</strong>)<br><strong>public final class </strong>MemoryAppender <strong>extends </strong>AbstractAppender {</pre><pre><strong> private </strong>MemoryAppender(<strong>final </strong>String name, <strong>final </strong>Filter filter,<br>     <strong>final </strong>Layout&lt;? <strong>extends </strong>Serializable&gt; layout,<br>     <strong>final boolean </strong>ignoreExceptions) <br> {<br>        <strong>super</strong>(name, filter, layout, ignoreExceptions);<br> }<br><br> @PluginFactory<br> <strong>public static </strong>MemoryAppender createAppender( <br>  @PluginAttribute(<strong>&quot;name&quot;</strong>) <strong>final </strong>String name,    <br>  @PluginElement(<strong>&quot;Filters&quot;</strong>) <strong>final </strong>Filter filter,<br>  @PluginElement(<strong>&quot;Layout&quot;</strong>) Layout&lt;? <strong>extends </strong>Serializable&gt; layout,   <br>  @PluginAttribute(<strong>&quot;ignoreExceptions&quot;</strong>) <strong>final </strong>String ignore) <br> {<br>        <br>   <strong>if </strong>(name == <strong>null</strong>) {<br>     <strong><em>LOGGER</em></strong>.error(<strong>&quot;No name provided for MemoryAppender&quot;</strong>);<br>     <strong>return null</strong>;<br>   } <strong>else </strong>{<br>     <strong>if </strong>(layout == <strong>null</strong>) {<br>        layout = PatternLayout.<em>createDefaultLayout</em>();<br>     }<br>     <strong>final boolean </strong>ignoreExceptions =  <br>        Booleans.<em>parseBoolean</em>(ignore, <strong>true</strong>);<br>     <strong>return new </strong>MemoryAppender(name,filter,layout,ignoreExceptions);<br>   }<br> }<br><em><br> </em>@Override<br> <strong>public void </strong>append(LogEvent logEvent) <br> {<br>       //append to detination<br> }</pre><pre>}</pre><p>B. Add the fragment host and plugin processor into the pom.xml</p><pre>&lt;<strong>Fragment-Host</strong>&gt;org.ops4j.pax.logging.pax-logging-log4j2&lt;/<strong>Fragment-Host</strong>&gt;</pre><pre>&lt;<strong>plugin</strong>&gt;<br>    &lt;<strong>groupId</strong>&gt;org.apache.maven.plugins&lt;/<strong>groupId</strong>&gt;<br>    &lt;<strong>artifactId</strong>&gt;maven-compiler-plugin&lt;/<strong>artifactId</strong>&gt;<br>    &lt;<strong>executions</strong>&gt;<br>        &lt;<strong>execution</strong>&gt;<br>            &lt;<strong>id</strong>&gt;log4j-plugin-processor&lt;/<strong>id</strong>&gt;<br>            &lt;<strong>goals</strong>&gt;<br>                &lt;<strong>goal</strong>&gt;compile&lt;/<strong>goal</strong>&gt;<br>            &lt;/<strong>goals</strong>&gt;<br>            &lt;<strong>phase</strong>&gt;process-classes&lt;/<strong>phase</strong>&gt;<br>            &lt;<strong>configuration</strong>&gt;<br>                &lt;<strong>proc</strong>&gt;only&lt;/<strong>proc</strong>&gt;<br>                &lt;<strong>annotationProcessors</strong>&gt;<br>                    &lt;<strong>annotationProcessor</strong>&gt;<br>                        org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor<br>                    &lt;/<strong>annotationProcessor</strong>&gt;<br>                &lt;/<strong>annotationProcessors</strong>&gt;<br>            &lt;/<strong>configuration</strong>&gt;<br>        &lt;/<strong>execution</strong>&gt;<br>    &lt;/<strong>executions</strong>&gt;<br>&lt;/<strong>plugin</strong>&gt;</pre><p>Build the bundle and you should see the Plugins.dat file created inside <em>META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat</em> of the jar. If it does not exist, then the resources are not packed by default. To solve this you need to specify to include the resource in the pom as shown in the line below.</p><pre>&lt;<strong>Include-Resource</strong>&gt;${project.build.directory}/classes/&lt;/<strong>Include-Resource</strong>&gt;</pre><p>C. Define the appender in the configuration file</p><pre><strong>appenders </strong>= <strong>MEMORY</strong></pre><pre><strong>appender.CARBON_MEMORY.type </strong>= <strong>MemoryAppender<br>appender.CARBON_MEMORY.name </strong>= <strong>MEMORY<br>appender.CARBON_MEMORY.layout.type </strong>= <strong>PatternLayout<br>appender.CARBON_MEMORY.layout.pattern </strong>= <strong>[%d] %5p {%c} — %m%ex%n</strong></pre><p>That’s it! Log4J 2 is configured in OSGi.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70be42e95ef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>