Category Archives: Programming

Java – Break Filter Chain and Return Custom POJO Response from Servlet Filter

Java - Break Filter Chain and Return Custom POJO Response from Servlet Filter

Java – Break Filter Chain and Return Custom POJO Response from Servlet Filter

Java - Break Filter Chain and Return Custom POJO Response from Servlet Filter

Sample Servlet Filter : package com.application.test.security; import com.application.test.response.ErrorResponse; import com.fasterxml.jackson.databind.ObjectMapper; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class TestFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,ServletException { if(ANY CONDITION){ //ANY POJO CLASS ErrorResponse errorResponse = new ErrorResponse();… Read More »

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Sample Query : POST /test/test/_search { “query”: { “filtered”: { “filter”: { “bool”: { “must”: [{ “range”: { “dateOrTimeAttribute”: { “from”: “16:31:15”, “to”: “16:31:15||+10m” } } }] } } } } } Examples: “16:31:15||+10m” “16:31:15||+1d” “2016-02-02||-1M”  

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Maven Dependency : <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> <version>1.2</version> </dependency> Sample Java Program : package test; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; public class Test { public static void main(String[] args) { //Define Options Options options = new Options(); //Option Name – option1 //Has input value – true options.addOption(“option1”, true, “Option 1 Description”);… Read More »

Java JConsole – Local Process List Empty – Solved

JAVA JCONSOLE – LOCAL PROCESS LIST EMPTY – SOLVED.png

Java JConsole – Local Process List Empty – Solved

JAVA JCONSOLE – LOCAL PROCESS LIST EMPTY – SOLVED.png

JConsole or  Java Monitoring and Management Console Open command prompt Execute the command echo %TMP% Now you will get a path to a folder where temporary files are stored. E.g. C:\Users\Username\AppData\Local\Temp Go to that folder Remove the folder named hsperfdata_USERNAME Restart JConsole application and now you will have the list of currently running Java processes in the local process… Read More »

Elasticsearch – Compare/ScriptFilter/Condition on Two Fields using Script Filter – REST Query + Java API

Elasticsearch - Compare or Script Filter or Condition on Two Fields using Script Filter - REST Query + Java API

Elasticsearch – Compare/ScriptFilter/Condition on Two Fields using Script Filter – REST Query + Java API

Elasticsearch - Compare or Script Filter or Condition on Two Fields using Script Filter - REST Query + Java API

Example 1: GET /INDEX/TYPE/_search { “query”: { “filtered”: { “filter”: { “script”: { “script”: “doc[‘field1’].value < doc[‘field2’].value” } } } } } Example 2: GET /INDEX/TYPE/_search { “query”: { “filtered”: { “filter”: { “script”: { “script”: “doc[‘field1’].value – doc[‘field2’].value > 10” } } } } } Java API: import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import… Read More »