Posts

Showing posts from 2019

OpenAPI vs Swagger

Image
Most of the people think Swagger and openAPI is same. But, it is not. Then what are those. It is true that, until 2015, openAPI specification is called as Swagger specification. But, in 2015, SmartBear donated the fostering of openAPI to openAPI initiatives. Hence, since 2015, this specification was renamed to the OpenAPI specification.  https://smartbear.com/news/news-releases/smartbear-launches-open-api-initiative-with-key-in/ Then let me explain the difference between openAPI and Swagger. What is OpenAPI? OpenAPI is a standard specification which can be used to describe your REST API including, All the endpoints defined in your Rest API     Operations defined on each endpoint Operation parameters (input and output parameters) Request bodies Response bodies Authentication Methods (Basic, OpenID) License Information, terms of use This openAPI specification can be written in both YAML and JSON. These specifications...

PIVOT clause in Orcale

Image
PIVOT and UNPIVOT clause in Oracle - this is something I learnt recently. PIVOT and UNPIVOT is introduced from Oracle 11g version. This post will explain about PIVOT clause in Oracle. PIVOT Assume a scenario as below. You have a table which stores some parameter information. it has two columns called PARAMETER_NAME and PARAMETER_VALUE those are used to save parameter names and values. Now you get a requirement, that you need to create a new view  from old table. But, in this new view, there should be a separate column for each parameter.  To achieve this requirement, you can get help of PIVOT clause. PIVOT clause is allowed you to transpose the rows in a table to columns by aggregating the data. Hence, PIVOT clause returns the more columns and fewer rows than the starting data set (table). Syntax for PIVOT clause. SELECT      col0, col1, col2 FROM      table_name PIVOT  (   aggregate_fun...

How to generate direct line token to start a new conversation between your own client application and bot framework in Java

You can enable the communication between your bot framework and your client application using Direct Line API. When you add your client application as a site to communicate with your bot framework through azure portal, bot framework will generate secret keys. Your client application can use these generated secret keys to authenticate direct line requests issued to your bot framework. Let me explain how we can generate token to start a  conversations between your own client and bot framework. When we send a request to direct line for generating token,  if the request is successful it will send the conversation id and token that is valid to that conversation id. If client application already has a earlier used conversation Id, you can pass that id as an input to this method for generating token. If there is no conversation id, you can pass null value.  Return type of this method is a Map to retrieve generated token and conversation Id which is valid for that to...

How to traverse through a given json string

Recently, I came across a scenario that requires to traverse through the json property keys and values of a given json object. Add below maven dependency into the pom file of the project. <dependency>             <groupId>org.json</groupId>             <artifactId>json</artifactId>             <version>20180130</version> </dependency> Below three method will help to traverse through the json object void iterateJSONObject(JSONObject jsonObject) {         jsonObject.keys().forEachRemaining(key -> {             Object value = jsonObject.get(key);             System.out.println("Key: " + key);             iterateValue(value);         });     }       void iterateJSONArray(JSONAr...

How to convert Json property names of a given Json String to Title case using regular expression in Java

Image
Recently I came across a requirement to convert json property names of given Json string to title case. Let me explain it with a example. Assume you have below json string. Now you want to convert json property names to title case or to make first letter of the property name to upper case. You can write the code as below. You will get output as,

Responsible use of AI

The Sri Lanka Association for Software and Service Companies (SLASSCOM) successfully hosted ‘SLASSCOM AI ASIA Summit 2019’ for the second consecutive year on 6th of November at the Shangri-La, Colombo. While more than 400 participants took part to this event, eminent experts in AI from diverse industrial and academic backgrounds spoke about different interesting topics related to AI. Out of these interesting topics, Dr. Inga Strumke, Manager - AI and Mac hine Learning at PwC Norway, shared an important AI factor which is vital from both business and software engineering perspective. It is ‘Responsible use of AI’ What is Responsible AI? Assume you want to translate ‘She is a doctor. He is a nurse. ’ from English to Hungarian using a language translator which is using AI. You will get it as ‘Ő egy orvos. Ő egy nővér.’ . And then again, if you translate it from Hungarian to English using same translator, you will get it as ‘He is a doctor. She is a nurse.’ Even ...

How to create a Server which accepts Client Certificate in Java

When you need to create a server which is requiring client certificate, you can use below code for that. package testserver; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import java.security.KeyStore; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManagerFactory; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsExchange; import com.sun.net.httpserver.HttpsParameters; import com.sun.net.httpserver.HttpsServer; public class TestServer {     /**      * @param args the command line arguments      */     final static String Server_Password = "password";     final static String keystore = "D://NetbeansProjects/...