<?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 Danushka Madhuranga on Medium]]></title>
        <description><![CDATA[Stories by Danushka Madhuranga on Medium]]></description>
        <link>https://medium.com/@danushka.15?source=rss-ddd4f7a219ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7gUU1KgKFcBu-RBX.jpg</url>
            <title>Stories by Danushka Madhuranga on Medium</title>
            <link>https://medium.com/@danushka.15?source=rss-ddd4f7a219ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:09:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danushka.15/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[Masking Client IP addresses in the Access logs of Nginx Ingress Controller]]></title>
            <link>https://medium.com/@danushka.15/masking-client-ip-addresses-in-the-access-logs-of-nginx-ingress-controller-7ff508740298?source=rss-ddd4f7a219ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ff508740298</guid>
            <category><![CDATA[logs]]></category>
            <category><![CDATA[lua]]></category>
            <category><![CDATA[nginx-ingress-controller]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ip-masking]]></category>
            <dc:creator><![CDATA[Danushka Madhuranga]]></dc:creator>
            <pubDate>Sat, 07 Aug 2021 05:42:13 GMT</pubDate>
            <atom:updated>2021-08-07T05:42:13.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*-0vnJmFdhNDA4mXp6UUz6A.jpeg" /><figcaption>Image credit: <a href="https://dev.to/forkbomb/creating-an-api-with-lua-using-openresty-42mc">https://dev.to/forkbomb/creating-an-api-with-lua-using-openresty-42mc</a></figcaption></figure><p>Organizations, especially serving customers in the EU, are trying to save as little data as possible due to GDPR. As such, they are trying to strip personal data from logs as much as possible. An IP address, presents in most logs, is considered as an online identifier that falls under “personal information” category in the GDPR <a href="https://gdpr-info.eu/issues/personal-data/">[#]</a>. This forces internet service providers to take many additional steps to protect stored IP addresses. To avoid these hassles, many organizations either decides not to save IP addresses or to save masked IP addresses. By default, Nginx Ingress Controller saves client IP addresses in access logs. Though you can easily customize the log format to exclude IP addresses, some of the features of log processing tools may not work without a unique IP address in the logs. Therefore, in many cases, the best option is to save masked ip addresses. In this article, we’ll discuss how to mask client IP addresses in the Nginx access logs.</p><p>Masking IP address with Nginx and Nginx Plus can be realized in a couple of ways. We can use the Javascript module and write a simple Javascript code to mask the IP address <a href="https://www.nginx.com/blog/data-masking-user-privacy-nginscript/#njs-enable">[#]</a>. Unfortunately, the <a href="http://k8s.gcr.io/ingress-nginx/controller">ingress-nginx/controller</a> image does not have the Javascript module. When you instal the Nginx Ingress Controller following the official guide in Kubernetes documentation, you’ll be using the k8s.gcr.io/ingress-nginx/controller image <a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/cloud/deploy.yaml">[#]</a>. Another way to implement masking is to use Lua Scripts. Lua plugging is already used by the Nginx Ingress controller so we don’t even need to import anything. We can simply inject the code we want to execute. Nginx ingress controller is usually configured with a config map. We can inject all the changes required for masking using this config map.</p><p>The following is the default access log format of the controller which is defined in the <strong>http</strong> block in the configuration file (nginx.conf).</p><pre>log_format upstreaminfo ‘$remote_addr - $remote_user [$time_local] “$request” ‘$status $body_bytes_sent “$http_referer” “$http_user_agent” $request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id’;</pre><p>In this log format, “$remote_addr” represent the client’s IP address. We need to define a new log format replacing “$remote_addr” with a custom variable that contains the masked IP address. We’ll use a variable called “$masked_remote_addr”. To inject the definition of the new log format to the <strong>http</strong> block, we can add the following to the config map under the data field, “<strong>http-snippet</strong>”.</p><pre>log_format maskedFormat ‘$masked_remote_addr - $remote_user [$time_local] “$request” $status $body_bytes_sent “$http_referer” “$http_user_agent” $request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id’;</pre><p>By default, all the servers in the Nginx, use the default access log format. To use the <strong>maskedFormat</strong> instead, it should be specified as the log format in each server block as the following.</p><pre>access_log /var/log/nginx/access.log maskedformat if=$loggable;</pre><p>We can inject this to all the server blocks by adding it under the “<strong>server-snippet</strong>” field in the config map.</p><p>Next, we have to generate the “$masked_remote_addr”. For this, we use a Lua script. The following Lua script, first hashes the IP address with <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function">FNV‑1a hash algorithm</a> and secondly, converts the hash value to a format similar to an IP address. Thus, giving a unique irreversible IP address for each real client IP address.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bc34b56aeede824a89afa909f267383/href">https://medium.com/media/8bc34b56aeede824a89afa909f267383/href</a></iframe><p>This can also be added to the “<strong>server-snippet</strong>” field in the config map. The final configmap will look similar to the following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e35958c48c22af287de655409d6ce63e/href">https://medium.com/media/e35958c48c22af287de655409d6ce63e/href</a></iframe><p>That’s it. We’ve completed masking of IP addresses in Nginx Ingress Controller’s access logs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ff508740298" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use special characters in XPATH expressions in WSO2 Enterprise Integrator / MI]]></title>
            <link>https://medium.com/@danushka.15/how-to-use-special-characters-in-xpath-expressions-in-wso2-enterprise-integrator-mi-1084bbeb1eae?source=rss-ddd4f7a219ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/1084bbeb1eae</guid>
            <category><![CDATA[quotes]]></category>
            <category><![CDATA[xpath]]></category>
            <category><![CDATA[wso2-ei]]></category>
            <category><![CDATA[expression]]></category>
            <dc:creator><![CDATA[Danushka Madhuranga]]></dc:creator>
            <pubDate>Thu, 31 Dec 2020 07:52:59 GMT</pubDate>
            <atom:updated>2020-12-31T08:01:11.939Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*mUZfoQBao-TkpF5yTlMCHg.png" /></figure><p>Many mediators in WSO2 EI/MI support expressions. Property mediator <a href="https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/property-Mediator/">[1]</a>, Call mediator <a href="https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/call-Mediator/">[2]</a>, and Filter mediator <a href="https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/filter-Mediator/">[3]</a> all support expressions to name a few. Though not frequently, you may want to use special characters such as single quote (‘), double quote (“), and &amp; inside XPath expressions. In many cases, you cannot directly use the character and instead have to use different tricks. We have provided a few examples here and you can use similar techniques in other use cases as well.</p><h4><strong>Example 1: Single quotes</strong></h4><p>One of the common use of expressions in property mediator is to create a new property from existing properties and other parameters. More often than not, users will rely on <strong><em>fn:concat</em></strong> function to create a new property combining existing ones. Suppose we want to create the following URL by combining the other properties.</p><p>Existing properties:</p><pre>&lt;property name=”BASE_URL” scope=”default” type=”STRING” value=”http://example.com&quot;/&gt;</pre><pre>&lt;property name=”SEARCH_PATH” scope=”default” type=”STRING” value=”/search”/&gt;</pre><pre>&lt;property name=”SEARCH_ITEM” scope=”default” type=”STRING” value=”apple”/&gt;</pre><p>Required URL: <a href="http://example.com/"><em>https://example.com/</em></a><em>search?query=’name=apple’</em></p><p>Note that in this case, we want to wrap <strong><em>name=apple</em></strong> between two single quotes.</p><p>Since inside a function we are already using single quotes to wrap strings, we cannot derive this URL with the following expression. This will throw an error.</p><pre>&lt;property expression=”fn:concat($ctx:BASE_URL, $ctx:SEARCH_PATH, ‘?query=’name=’, $ctx:SEARCH_ITEM, ‘’’)” name=”testProperty” scope=”default” type=”STRING”/&gt;</pre><p>Instead, we have to wrap every single quote (‘) with two <strong>&amp;quot; </strong>similar to the following. Note that <strong>&amp;quot;</strong> in Xpath represent the double quote, therefore, what we are doing is wrapping the single quote inside two double quotes.</p><pre>&lt;property expression=”fn:concat($ctx:BASE_URL, $ctx:SEARCH_PATH, ‘?query=’, &amp;quot;’&amp;quot;, ‘name=’, $ctx:SEARCH_ITEM, &amp;quot;’&amp;quot;)” name=”testProperty” scope=”default” type=”STRING”/&gt;</pre><h4><strong>Example 2: Double quotes</strong></h4><p>Suppose we want to create the following URL by wrapping <strong><em>name=apple </em></strong>with double-quotes instead.</p><p>Required URL: <a href="http://example.com/"><em>https://example.com/</em></a><em>search?query=”name=apple”</em></p><p>We can simply replace double-quotes (“) with <strong>&amp;quot; </strong>similar to the following.</p><pre>&lt;property expression=”fn:concat($ctx:BASE_URL, $ctx:SEARCH_PATH, ‘?query=&amp;quot;’, ‘name=’, $ctx:SEARCH_ITEM, ‘&amp;quot;’)” name=”testProperty” scope=”default” type=”STRING”/&gt;</pre><h4><strong>Example 3: AND (&amp;)</strong></h4><p>Now, suppose we want to create the following URL with the additional parameter <strong><em>age=19</em></strong>.</p><p>Required URL: <a href="http://example.com/"><em>https://example.com/</em></a><em>search?query=”name=apple”&amp;price=10</em></p><p>The following expression won’t work.</p><pre>&lt;property expression=”fn:concat($ctx:BASE_URL, $ctx:SEARCH_PATH, ‘?query=&amp;quot;’, ‘name=’, $ctx:SEARCH_ITEM, ‘&amp;quot;&amp;price=10’)” name=”testProperty” scope=”default” type=”STRING”/&gt;</pre><p>Instead, we should replace the &amp; with <strong>&amp;amp;</strong>.</p><pre>&lt;property expression=”fn:concat($ctx:BASE_URL, $ctx:SEARCH_PATH, ‘?query=&amp;quot;’, ‘name=’, $ctx:SEARCH_ITEM, ‘&amp;quot;&amp;amp;price=10’)” name=”testProperty” scope=”default” type=”STRING”/&gt;</pre><p>More details on special characters can be found in <a href="https://www.w3.org/TR/2010/REC-xpath20-20101214/">[4]</a>.</p><p>[1]. <a href="https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/property-Mediator/">https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/property-Mediator/</a></p><p>[2]. <a href="https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/call-Mediator/">https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/call-Mediator/</a></p><p>[3]. <a href="https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/filter-Mediator/">https://ei.docs.wso2.com/en/7.0.0/micro-integrator/references/mediators/filter-Mediator/</a></p><p>[4]. <a href="https://www.w3.org/TR/2010/REC-xpath20-20101214/">https://www.w3.org/TR/2010/REC-xpath20-20101214/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1084bbeb1eae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use custom log4j appenders with WSO2 Micro Integrator/ Enterprise Integrator]]></title>
            <link>https://medium.com/@danushka.15/how-to-use-custom-log4j-appenders-with-wso2-micro-integrator-enterprise-integrator-6c875a78f4df?source=rss-ddd4f7a219ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c875a78f4df</guid>
            <category><![CDATA[log4j2]]></category>
            <category><![CDATA[micro-integrator]]></category>
            <category><![CDATA[log4j2-extension]]></category>
            <category><![CDATA[wso2-ei]]></category>
            <category><![CDATA[custom-appender]]></category>
            <dc:creator><![CDATA[Danushka Madhuranga]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 23:49:15 GMT</pubDate>
            <atom:updated>2020-10-11T23:49:15.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m90lWSRkLVnptdy0O0HMDw.png" /></figure><p>WSO2 Micro Integrator (MI) and Enterprise Integrator (EI) both use the log4j2 framework for logging purposes. Log4j2 configurations, such as log level configurations and appenders configurations, are specified in the &lt;MI_HOME&gt;/conf/log4j2.properties file of Micro Integrator and &lt;EI_HOME&gt;/conf/log4j2.properties file of Enterprise Integrator. One can easily add a new logger or an appender easily by adding a few lines of configuration details to the jog4j2.properties file as long as the logger or the appender is a built-in component provided by the log4j2 itself. However, if you want to configure a custom appender or any other customized component, you will need to follow a few more steps.</p><p>Log4j2 in WSO2 Micro Integrator works in an OSGI environment. Therefore, in order for custom appenders to work, we need to build the project containing the appender as a plugin. Often times, you will use an available custom appender written by someone else rather than writing one on your own. In this post, I’ll configure <em>Log4j-s3-search</em> <a href="https://github.com/bluedenim/log4j-s3-search">[1]</a>, an opensource appender that can be used to publish logs to S3, Azure, Google Cloud, and some search platforms, to work with WSO2 MI. <em>Log4j-s3-search</em> is written as a multi-module maven project with 3 modules; appender-core, appender-log4j, and appender-log4j2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*k08F3HwFWAkElo5rSY-1Ow.png" /><figcaption>Structure of log4j-s3-search project</figcaption></figure><p>We need only the appender-core and appender-log4j2 modules as we are using lo4j2. If you are using log4j instead of log4j2, replace appender-log4j2 with appender-log4j. Appender-log4j2 contains the custom appender class, which is named <strong>Log4j2Appender</strong> in <em>Log4j-s3-search</em>. So, we need to build the appender-log4j2 module as a plugin. For that, we need to use the <strong>maven-bundle-plugin</strong> with <strong>maven-compiler-plugin</strong> in the pom.xml file of the appender-log4j2 module. You can find the configuration that I have used in the pom.xml file of the module below. You can rebuild the appender-log4j2 module with this configuration and add the JAR to &lt;MI_HOME&gt;/dropins. Appender-core contains utils functions and it does not directly interact with log4j2. Therefore, you can simply build it without any changes and add the JAR file to the &lt;MI_HOME&gt;/lib folder or &lt;EI_HOME&gt;/lib folder.</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;<br>&lt;project xmlns=&quot;<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a>&quot; xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot; xsi:schemaLocation=&quot;<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a> <a href="http://maven.apache.org/xsd/maven-4.0.0.xsd">http://maven.apache.org/xsd/maven-4.0.0.xsd</a>&quot;&gt;<br>    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br>    &lt;artifactId&gt;appender-log4j2&lt;/artifactId&gt;<br>    &lt;version&gt;2.7.1-SNAPSHOT&lt;/version&gt;<br>    &lt;name&gt;appender-log4j2&lt;/name&gt;<br>    &lt;description&gt;Core functionality to send content to various channels using Log4j 2.7+&lt;/description&gt;<br>    &lt;packaging&gt;bundle&lt;/packaging&gt;</pre><pre>&lt;parent&gt;<br>        &lt;groupId&gt;com.therealvan&lt;/groupId&gt;<br>        &lt;artifactId&gt;log4j-s3-search&lt;/artifactId&gt;<br>        &lt;version&gt;2.7.0&lt;/version&gt;<br>    &lt;/parent&gt;</pre><pre>&lt;properties&gt;<br>        &lt;powermock.version&gt;1.6.6&lt;/powermock.version&gt;<br>    &lt;/properties&gt;</pre><pre>&lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;com.therealvan&lt;/groupId&gt;<br>            &lt;artifactId&gt;appender-core&lt;/artifactId&gt;<br>            &lt;version&gt;2.7.0&lt;/version&gt;<br>            &lt;exclusions&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;<br>                    &lt;artifactId&gt;aws-java-sdk-s3&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;com.microsoft.azure&lt;/groupId&gt;<br>                    &lt;artifactId&gt;azure-storage&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;com.google.cloud&lt;/groupId&gt;<br>                    &lt;artifactId&gt;google-cloud-storage&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;org.apache.solr&lt;/groupId&gt;<br>                    &lt;artifactId&gt;solr-solrj&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;<br>                    &lt;artifactId&gt;transport&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;<br>                    &lt;artifactId&gt;log4j-to-slf4j&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>                &lt;exclusion&gt;<br>                    &lt;groupId&gt;org.slf4j&lt;/groupId&gt;<br>                    &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;<br>                &lt;/exclusion&gt;<br>            &lt;/exclusions&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;<br>            &lt;version&gt;2.12.0&lt;/version&gt;<br>        &lt;/dependency&gt;</pre><pre>&lt;dependency&gt;<br>            &lt;groupId&gt;junit&lt;/groupId&gt;<br>            &lt;artifactId&gt;junit&lt;/artifactId&gt;<br>            &lt;version&gt;4.12&lt;/version&gt;<br>            &lt;scope&gt;test&lt;/scope&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.easymock&lt;/groupId&gt;<br>            &lt;artifactId&gt;easymock&lt;/artifactId&gt;<br>            &lt;version&gt;3.4&lt;/version&gt;<br>            &lt;scope&gt;test&lt;/scope&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.powermock&lt;/groupId&gt;<br>            &lt;artifactId&gt;powermock-module-junit4&lt;/artifactId&gt;<br>            &lt;version&gt;${powermock.version}&lt;/version&gt;<br>            &lt;scope&gt;test&lt;/scope&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.powermock&lt;/groupId&gt;<br>            &lt;artifactId&gt;powermock-api-easymock&lt;/artifactId&gt;<br>            &lt;version&gt;${powermock.version}&lt;/version&gt;<br>            &lt;scope&gt;test&lt;/scope&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;</pre><pre>&lt;build&gt;<br>        &lt;finalName&gt;log4j-s3-search-log4j2&lt;/finalName&gt;<br>        &lt;plugins&gt;<br>            &lt;plugin&gt;<br>                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>                &lt;executions&gt;<br>                    &lt;execution&gt;<br>                        &lt;id&gt;log4j-plugin-processor&lt;/id&gt;<br>                        &lt;goals&gt;<br>                            &lt;goal&gt;compile&lt;/goal&gt;<br>                        &lt;/goals&gt;<br>                        &lt;phase&gt;process-classes&lt;/phase&gt;<br>                        &lt;configuration&gt;<br>                            &lt;proc&gt;only&lt;/proc&gt;<br>                            &lt;annotationProcessors&gt;<br>                                &lt;annotationProcessor&gt;<br>                                    org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor<br>                                &lt;/annotationProcessor&gt;<br>                            &lt;/annotationProcessors&gt;<br>                        &lt;/configuration&gt;<br>                    &lt;/execution&gt;<br>                &lt;/executions&gt;<br>            &lt;/plugin&gt;<br>            &lt;plugin&gt;<br>                &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;<br>            &lt;/plugin&gt;<br>   &lt;plugin&gt;<br>                &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;<br>                &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;<br>                &lt;extensions&gt;true&lt;/extensions&gt;<br>                &lt;configuration&gt;<br>                    &lt;instructions&gt;<br>                        &lt;Bundle-SymbolicName&gt;${project.artifactId}&lt;/Bundle-SymbolicName&gt;<br>                        &lt;Bundle-Name&gt;${project.artifactId}&lt;/Bundle-Name&gt;<br>                        &lt;Fragment-Host&gt;org.ops4j.pax.logging.pax-logging-log4j2&lt;/Fragment-Host&gt;<br>                        &lt;Export-Package&gt;<br>                            com.van.logging.log4j2.*<br>                        &lt;/Export-Package&gt;<br>                        &lt;DynamicImport-Package&gt;*&lt;/DynamicImport-Package&gt;<br>                        &lt;Import-Package&gt;<br>                        &lt;/Import-Package&gt;<br>                        &lt;Include-Resource&gt;${project.build.directory}/classes/&lt;/Include-Resource&gt;<br>                    &lt;/instructions&gt;<br>                &lt;/configuration&gt;<br>            &lt;/plugin&gt;<br>        &lt;/plugins&gt;<br>    &lt;/build&gt;<br>    &lt;distributionManagement&gt;<br>        &lt;snapshotRepository&gt;<br>            &lt;id&gt;ossrh&lt;/id&gt;<br>            &lt;url&gt;<a href="https://oss.sonatype.org/content/repositories/snapshots">https://oss.sonatype.org/content/repositories/snapshots</a>&lt;/url&gt;<br>        &lt;/snapshotRepository&gt;<br>        &lt;repository&gt;<br>            &lt;id&gt;ossrh&lt;/id&gt;<br>            &lt;url&gt;<a href="https://oss.sonatype.org/service/local/staging/deploy/maven2">https://oss.sonatype.org/service/local/staging/deploy/maven2</a>&lt;/url&gt;<br>        &lt;/repository&gt;<br>    &lt;/distributionManagement&gt;<br>    &lt;scm&gt;<br>        &lt;connection&gt;scm:git:git://github.com/dexecutor/dependent-tasks-executor.git&lt;/connection&gt;<br>        &lt;developerConnection&gt;scm:git:<a href="/service/mailto:git@github.com">git@github.com</a>:dexecutor/dexecutor.git&lt;/developerConnection&gt;<br>        &lt;url&gt;<a href="https://github.com/dexecutor/dependent-tasks-executor">https://github.com/dexecutor/dependent-tasks-executor</a>&lt;/url&gt;<br>        &lt;tag&gt;appender-log4j2-2.0.0&lt;/tag&gt;<br>    &lt;/scm&gt;<br>    &lt;profiles&gt;<br>        &lt;profile&gt;<br>            &lt;id&gt;release-sign-artifacts&lt;/id&gt;<br>            &lt;activation&gt;<br>                &lt;property&gt;<br>                    &lt;name&gt;performRelease&lt;/name&gt;<br>                    &lt;value&gt;true&lt;/value&gt;<br>                &lt;/property&gt;<br>            &lt;/activation&gt;<br>            &lt;build&gt;<br>                &lt;plugins&gt;<br>                    &lt;plugin&gt;<br>                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>                        &lt;artifactId&gt;maven-gpg-plugin&lt;/artifactId&gt;<br>                        &lt;version&gt;1.6&lt;/version&gt;<br>                        &lt;executions&gt;<br>                            &lt;execution&gt;<br>                                &lt;id&gt;sign-artifacts&lt;/id&gt;<br>                                &lt;phase&gt;verify&lt;/phase&gt;<br>                                &lt;goals&gt;<br>                                    &lt;goal&gt;sign&lt;/goal&gt;<br>                                &lt;/goals&gt;<br>                            &lt;/execution&gt;<br>                        &lt;/executions&gt;<br>                    &lt;/plugin&gt;<br>                &lt;/plugins&gt;<br>            &lt;/build&gt;<br>        &lt;/profile&gt;<br>    &lt;/profiles&gt;<br>&lt;/project&gt;</pre><p>To add the custom appender, named <strong>Log4j2Appender</strong> in this library, add the following lines to the log4j2.properties file.</p><pre>appender.log4j2Custom.type = Log4j2Appender<br>appender.log4j2Custom.name = log4j2Custom<br>appender.log4j2Custom.layout.type = PatternLayout<br>appender.log4j2Custom.layout.pattern = [%d] %5p {%c} - %m%ex%n</pre><p>That is it and now you have successfully configured a custom appender to work with WSO2 MI. You can follow the same steps to configure custom filters, layout, or any other custom log4j2 component.</p><p>When you start the MI, you may see some error messages due to missing dependencies related to amazon AWS S3 and missing parameters on configuring AWS, which are specific to this appender.</p><p>[1]. <a href="https://github.com/bluedenim/log4j-s3-search">https://github.com/bluedenim/log4j-s3-search</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c875a78f4df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial 2: 11 Cool queries in Solr]]></title>
            <link>https://medium.com/@danushka.15/tutorial-2-11-cool-queries-in-solr-86907e5a36fc?source=rss-ddd4f7a219ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/86907e5a36fc</guid>
            <category><![CDATA[solr-queries]]></category>
            <category><![CDATA[solr]]></category>
            <category><![CDATA[irs]]></category>
            <category><![CDATA[query]]></category>
            <category><![CDATA[apache-solr]]></category>
            <dc:creator><![CDATA[Danushka Madhuranga]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 07:17:11 GMT</pubDate>
            <atom:updated>2019-08-15T07:17:11.454Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jqL5p500O7Rxf1nY.png" /></figure><p>Apache solr support varies types of queries. Here are some of the most used queries in building IR systems.</p><ol><li><strong>Default query</strong></li></ol><p>If a default query field is set, the documents can be searched without specifying a field. Accessible via: http://localhost:8983/solr/&lt;core-name&gt;/select?q=&lt;query-string&gt;</p><p><strong>2. Search in a field</strong></p><p>Can be used to search in a specific field only. Following query looks for articles containing a keyword in the title. Accessible via: http://localhost:8983/solr/&lt;core-name&gt;/select?q=&lt;title:term&gt;</p><p><strong>3. Searching with operators</strong></p><p>Operators such as AND, OR, and NOT can be used in field searches. For instance, search articles containing a keyword both in the title and heading.</p><p>Accessible via:</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?q=title:&lt;term&gt; AND heading:&lt;term&gt;</p><p><strong>4. Wildcard query</strong></p><p>If you search for the term “Mo*”, this will gives documents that contain Monday, Moon, Monster or any other term. These are wild card queries and they are very useful specially when the user is not sure about the spelling. start with Mo. Accessible via:</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?q=title:fr*nd</p><p><strong>5. Proximity query</strong></p><p>If you search ”word1 word2”~n, this will gives documents containing both word1 and word2, but with maximum n other terms between them. For example, if you search for “president Obama” ~1, it will not match “president of Mexico met Obama” because there are 3 words between “president” and “Obama”. Accessible via:</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?q=title:”word1 word2”~2</p><p><strong>6. Boosts</strong></p><p>Solr ranks the documents in the results based on the score given to the documents. Boosts decide which term in the query get higher weights in calculating the score. Accessible via:</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?q=”title:word1^2 AND paragraphs:word2 ^4”</p><p><strong>7. Search for a value range</strong></p><p>If the field type support range queries, it can be used to retrieve documents with values in a given range. For instance, fields of type pdates can be used to retrieve documents in a given time period. Accessible via:</p><p>http://localhost:8983/solr/news/select?q=field:[NOW-31DAY TO NOW]</p><p>http://localhost:8983/solr/news/select?q=timestamp:[2019-06-09T12:09:00Z TO NOW]</p><p><strong>8. Faceting</strong></p><p>Faceting allows categorizing results based on indexed terms. It gives a summary of the number number of documents found in each category. Faceting can be done by values or range.</p><p>Faceting by value:</p><p>For instance, this can be used to get the number of documents by each author.</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?facet.field=author&amp;facet=on&amp;q=</p><p>Faceting by range:</p><p>Also can be used to get number of documents in each day.</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?facet.range=timestamp&amp;facet=true&amp;f.timestamp.facet.range.start=NOW-1MONTH&amp;f.timestamp.facet.range.end=NOW&amp;f.timestamp.facet.range.gap=%2B1DAY&amp;q=””</p><p><strong>9. Highlighting</strong></p><p>Highlighting the searched terms in the given results. This makes it easier for the user to focus and select the most relevant result. Accessible via:</p><p>http://localhost:8983/solr/&lt;core-name&gt;/select?q=””&amp;hl=true&amp;hl.fl=spellcontent_txt_en_and_si&amp;hl.fragsize=75&amp;hl.snippets=10</p><p><strong>10. Morelikethis query</strong></p><p>Morelikethis queries return documents that are similar to each document in the result. Accessible via:</p><p>Example: http://localhost:8983/solr/&lt;core-name&gt;/select?q=””&amp;mlt=true&amp;mlt.fl=”fields”</p><p><strong>11. Spell check</strong></p><p>When spell check is on, each term in the query is checked for spelling.</p><p>Example: http://localhost:8983/solr/&lt;core-name&gt;/spell?spellcheck.q=””</p><p>Spellcheck should be configured prior to use. The following block in the solrconfig.xml should be configured properly by adding the relevant <strong><em>queryAnalyzerFieldType </em></strong>and name of the field to be checked against. Terms in the <strong><em>name-of-the-field-to-be-checked-against</em></strong> will be used as the dictionary. The following spellchecker uses the Levenshtein metric which is based on the edit distance.</p><p>&lt;searchComponent name=<strong>”spellcheck”</strong> class=<strong>”solr.SpellCheckComponent”</strong>&gt;</p><p>&lt;str name=<strong>”queryAnalyzerFieldType”</strong>&gt;type-of-the-field&lt;/str&gt;<br> &lt;lst name=<strong>”spellchecker”</strong>&gt;<br> &lt;str name=<strong>”name”</strong>&gt;<strong>default</strong>&lt;/str&gt;<br> &lt;str name=<strong>”field”</strong>&gt;name-of-the-field-<strong>to</strong>-be-checked-against&lt;/str&gt;<br> &lt;str name=<strong>”classname”</strong>&gt;solr.DirectSolrSpellChecker&lt;/str&gt;<br> &lt;str name=<strong>”distanceMeasure”</strong>&gt;internal&lt;/str&gt;<br> &lt;float name=<strong>”accuracy”</strong>&gt;0.5&lt;/float&gt;<br> &lt;int name=<strong>”maxEdits”</strong>&gt;2&lt;/int&gt;<br> &lt;int name=<strong>”minPrefix”</strong>&gt;1&lt;/int&gt;<br> &lt;int name=<strong>”maxInspections”</strong>&gt;5&lt;/int&gt;<br> &lt;int name=<strong>”minQueryLength”</strong>&gt;4&lt;/int&gt;<br> &lt;float name=<strong>”maxQueryFrequency”</strong>&gt;0.01&lt;/float&gt;<br> &lt;/lst&gt;</p><p>&lt;/searchComponent&gt;</p><p>Thank you and best of luck with solr.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86907e5a36fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial 1: How to configure Apache Solr]]></title>
            <link>https://medium.com/@danushka.15/tutorial-1-how-to-configure-apache-solr-da47f6d15e3e?source=rss-ddd4f7a219ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/da47f6d15e3e</guid>
            <category><![CDATA[solr]]></category>
            <category><![CDATA[information-retrieval]]></category>
            <category><![CDATA[how-to-solr]]></category>
            <category><![CDATA[configure-solr]]></category>
            <category><![CDATA[solr-tutorial]]></category>
            <dc:creator><![CDATA[Danushka Madhuranga]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 04:30:32 GMT</pubDate>
            <atom:updated>2019-08-15T04:30:32.894Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uxk7OJgI-wMPYPhe.png" /></figure><p>This is a walkthrough on how to set up and configure a solr core. This tutorial will use a corpse composed of news article for explanations. You can use your own corpse.</p><h3>Corpse</h3><p>In this tutorial, we will be using a corpse that contains around 1500 Sinhala news articles crapped from a news website and saved as a JSON file using the Scrappy[1] web crawling framework. Each news article has the following structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*_YVfEmiXpaCARqC2Y7mIjA.png" /><figcaption>Structure of news articles</figcaption></figure><p>While author field contains only English characters, title, content, and heading all contains both English and Sinhala characters. Following table contains statistical data about the number of words in each field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*F-9gCIBjMBIA4NtNKHf6bA.png" /></figure><h3>Setting up the core</h3><p>First, a new core is created using the command <strong><em>solr create -c &lt;core-name&gt;</em></strong>. Or you can use the admin UI. Solr has two main configuration files for a core; <strong><em>solrconfig.xml</em></strong> file and schema file. Schema file specifies the structure of the documents in the core and how they are to be processed both at indexing time and querying time. The solrconfig.xml file contains all other configuration details. These two files are required to be configured for a properly functioning solr core.</p><p>The corpse should to be uploaded for indexing and searching. Since the uploading data is structured, it contains fields. The fields contain different types of data. Solr has the capability to process different fields in the documents differently. For example, it can completely ignore some fields and index only a few selected fields. You should configure the schema before uploading the corpse.</p><h3>Configure the schema</h3><p>The schema defines the structure of documents and how the documents are indexed. The schema can be configured manually or automatically(Schemaless mode) by solr. In the schemaless-mode, there is limited control of the indexing and querying process. In the manual configuration mode, the schema file can be edited by hand. To enable manual configuration mode,</p><ol><li>Rename managed-schema file to schema.xml in the <strong><em>&lt;solr_home&gt;\server\solr\mynews\conf</em></strong> directory.</li><li>Remove the following declaration in solrconfig.xml if exists,</li></ol><pre>&lt;<strong>schemaFactory</strong> class=<strong>”ManagedIndexSchemaFactory”</strong>&gt;<br>  &lt;<strong>bool</strong> name=<strong>”mutable”</strong>&gt;true&lt;/<strong>bool</strong>&gt;<br>  &lt;<strong>str</strong> name=<strong>”managedSchemaResourceName”</strong>&gt;managed-schema&lt;/<strong>str</strong>&gt;<br>&lt;/<strong>schemaFactory</strong>&gt;</pre><p>3. Add following line to the solrconfig.xml file in the same directory.</p><pre>&lt;schemaFactory <strong>class</strong>=<strong>”ClassicIndexSchemaFactory”</strong>/&gt;</pre><p>4. Set <strong><em>update.autoCreateFields:true</em></strong> to false in <strong><em>updateRequestProcessorChain</em></strong> block in <strong><em>solrconfig.xml</em></strong> file.</p><p>5. Finally, reload the core using the solr admin UI. (http://localhost:8983/solr/#/~cores/&lt;core-name&gt;)</p><p>Following is the basic structure of the schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*Jv9XBP5Al_2zk2IpbVMQCQ.png" /></figure><p><strong>UniqueKey</strong></p><p>Uniquekey should be defined at the beginning of the schema. Uniquekey is used to separately identify documents. It can be one of the fields in the dataset (If the documents had a unique field such as a name or an id field) or an automatically generated value. A unique id can be generated by adding the following block to the solrconfig.xml file.</p><pre>&lt;<strong>updateRequestProcessorChain</strong>&gt;<br>  &lt;<strong>processor</strong> class=<strong>”solr.UUIDUpdateProcessorFactory”</strong>&gt;<br>     &lt;<strong>str</strong> name=<strong>”fieldName”</strong>&gt;name-of-the-unique-field&lt;/<strong>str</strong>&gt;<br>  &lt;/<strong>processor</strong>&gt;<br>  &lt;<strong>processor </strong>class=<strong>”solr.LogUpdateProcessorFactory”</strong> /&gt;<br>  &lt;<strong>processor</strong> class=<strong>”solr.RunUpdateProcessorFactory”</strong> /&gt;<br>&lt;/<strong>updateRequestProcessorChain</strong>&gt;</pre><p><strong>FieldType</strong></p><p>Field type defines the type of the fields in the documents. For instance, the author field in news articles can be considered to be of type String and the timestamp field to be of type date. The types of fields to be used should be declared in fieldType elements.</p><p><strong>Field</strong></p><p>Field elements are used to capture the information in the documents. If there is a declared field with the name “X” in the schema and there is a field name “X” in the documents, this element will capture the value under field X in the document. The following field element will capture the author field in the news articles.</p><pre>&lt;field <strong>name</strong>=<strong>”author”</strong> <strong>type</strong>=<strong>”string”</strong> <strong>indexed</strong>=<strong>”true”</strong> <strong>stored</strong>=<strong>”false”</strong>/&gt;</pre><p><strong>DynamicFields</strong></p><p>Dynamic fields are similar to regular fields. Dynamic fields have wildcard names such as *_str. Thus, the dynamic fields can capture any field that matches its name to the wildcard string. The following dynamic field will capture a field, named en_str, temp_str, or si_str in the document. It is useful when there could be documents with unknown fields.</p><pre>&lt;dynamicField <strong>name</strong>=<strong>”*_str”</strong> <strong>type</strong>=<strong>”pfloat”</strong> <strong>indexed</strong>=<strong>”true”</strong>/&gt;</pre><p><strong>CopyFields</strong></p><p>Copyfields can be used to process the same field in the documents in different ways. For instance, multiple fields can be copied by a copyfield to create a default search field. The following copyField element will capture the author field to copy_author field.</p><pre>&lt;copyField <strong>source</strong>=<strong>”author”</strong> <strong>dest</strong>=<strong>”copy_author”</strong>/&gt;</pre><h3>Set up a default search field</h3><p>A default field for searching can be set by adding the following block to the solrconfig.xml file.</p><pre>&lt;<strong>initParams</strong> path=<strong>”/query,/select,/tvrh,/elevate,/spell,/browse”</strong>&gt;<br>  &lt;<strong>lst</strong> name=<strong>”defaults”</strong>&gt;<br>    &lt;<strong>str</strong> name=<strong>”df”</strong>&gt;name-of-the-default-field&lt;/<strong>str</strong>&gt;<br>  &lt;/<strong>lst</strong>&gt;<br>&lt;/<strong>initParams</strong>&gt;</pre><h3>Uploading the corpse</h3><p>The corpse can be uploaded from the admin ui which is accessible by the following link http://localhost:8983/solr/#/&lt;core-name&gt;/documents. If you are uploading documents from a saved file, select the “file upload” option from the document type field. Before uploading the documents, the core should be reloaded. After uploading documents, they can be searched using the following link.http://localhost:8983/solr/#/&lt;core-name&gt;/query</p><p><strong>IMPORTANT </strong>: reload the core using admin ui after each change to the solrconfig.xml file. Accessible by the following link http://localhost:8983/solr/#/~cores/&lt;core-name&gt;</p><h3>View indexed values</h3><p>Internal solr index can be viewed by enabling luke library. To enable luke, add the following line to the solrconfig.xml.</p><pre>&lt;requestHandler name=<strong>”/admin/luke”</strong> class=<strong>”org.apache.solr.handler.admin.LukeRequestHandler”</strong>/&gt;</pre><p>After enabling luke and reloading the core, indexed values of any field can be viewed by using the following link. Replace &lt;core-name&gt; and &lt;field-name&gt; with relevant values.</p><p>http://localhost:8983/solr/&lt;core-name&gt;/admin/luke?fl=&lt;field-name&gt;&amp;numTerms=100</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da47f6d15e3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>