Tuesday 3 August 2021

React - npm : self signed certificate in certificate chain issue

 When I try to install react-router using "npm install react-router-dom"

I got below mentioned error message

PS C:\PracticeApps\React\my-react-app> npm install react-router-dom

npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning SELF_SIGNED_CERT_IN_CHAIN: request to https://registry.npmjs.org/react-router-dom failed, reason: self signed certificate in certificate chain

npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.

npm ERR! code SELF_SIGNED_CERT_IN_CHAIN

npm ERR! errno SELF_SIGNED_CERT_IN_CHAIN

npm ERR! request to https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.2.0.tgz failed, reason: self signed certificate in certificate chain  


npm ERR! A complete log of this run can be found in:

npm ERR!     C:\Users\KMATADA\AppData\Roaming\npm-cache\_logs\2021-08-03T14_08_06_664Z-debug.log


Solution : Try to run below commands

1.  npm install npm -g --ca=""


2. npm config set strict-ssl false   ( not recommended - ignoring ssl error is bad idea)



Reference Link

https://stackoverflow.com/questions/9626990/receiving-error-error-ssl-error-self-signed-cert-in-chain-while-using-npm



Thursday 8 July 2021

Configure/ Enable Swagger API for Spring Boot 2 (2.5.2)

 Enabling Swagger API documentation in Spring Boot 2.5.2 is pretty simple now.

We just need to few dependency and we are good to go

For Spring Boot Applications, If you are migrating to 2.5.2 version then perform the following operations

1. Remove library inclusions of earlier releases. Specifically remove springfox-swagger2 and springfox-swagger-ui inclusions.

2. Remove the @EnableSwagger2 annotations

3. Add the springfox-boot-starter as shown below

4. No need to external config class to configure docket-api. It is handled automatically.


Following is the dependency we have to add in our pom.xml (for maven project)


That's it!!!

and swagger-ui location has moved from 
http://host/context-path/swagger-ui.html 
to 
http://host/context-path/swagger-ui/index.html 
OR http://host/context-path/swagger-ui/

as shown below




The complete code can be found in my github

Friday 25 June 2021

PSQLException: ERROR: UNION types text and boolean cannot be matched

Recently I have faced the issue mentioned below

Caused by: org.postgresql.util.PSQLException: ERROR: UNION types text and boolean cannot be matched

Detailed stack trace :

org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)

at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)

at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)

at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)

at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)

at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)

at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106)

at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)

at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)

at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:677)

at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:616)

... 81 common frames omitted


Use case : In my Repository, i have union of 3 queries and i have introduced new boolean attribute and i started getting this error

Important thing to note when using union : order of attributes or column should be same in all the individual queries.

Example Query which was giving above error 

select name,id isValid from ((select t1.name as name ,t1.id as id ,t1.isValid as isValid from table t1) union (select t2.name as name,t2.id as id,' ' as isValid  from table t2) union(select t3.name as name,t3.id,t3.isValid as isValid from table t3) ) table t;

Even though order is same for all the 3 querues, mistke in the above query is ' ' as isValid from table 2

I was assigning text type value to boolean attribute hence i was getting the exception


 correct way is ( pass default value in my case FALSE)

select name,id isValid from ((select t1.name as name ,t1.id as id ,t1.isValid as isValid from table t1) union (select t2.name as name,t2.id as id, FALSE as isValid  from table t2) union(select t3.name as name,t3.id,t3.isValid as isValid from table t3) ) table t;


Hope it helps :)

Saturday 5 June 2021

Transaction Propagation in Spring, Spring Boot

What is Transaction Propagation ?

Propagation defines our business logic's boundary. Spring manages to start and pause a transaction based on our propagation setting.

In Spring Boot, we enable the transaction propagation using @Transactional annotation.

@Transactional : It Describes a transaction attribute on an individual method or on a class. 

We can set propagation, isolation, timeout, read-only and rollback conditions for our transaction using this annotation.

If annotation is applied at class level, then spring consider it for all the public methods, but if we applied at private or protected method then it ignores without an error.

Ex : 

  @Transactional(propagation = Propagation.REQUIRES_NEW)

  public void deleteExistingData() {
  }

Following are the settings for propagation

1.REQUIRED -  Default. Support a current transaction, create a new one if none exists.

2.SUPPORTS - Support a current transaction, execute non-transactionally if none exists.

3.MANDATORY - Support a current transaction, throw an exception if none exists. 

throw IllegalTransactionStateException

4.REQUIRES_NEW - Creates a new transaction, and suspend the current transaction if one exists.

5.NOT_SUPPORTED - Execute non transitionally, suspend the current transaction if one exists.

6.NEVER - Execute non-transitionally, throw an exception if a transaction exists.

7.NESTED - Execute within a nested transaction if a current transaction exists.

Thursday 4 March 2021

Kubernetes - Getting started with - Introduction, Pods

Kubernetes Building Blocks


How communication happens within Kubernetes






Running a Pod (2 ways)
1) kubectl run command
2) kubectl create/apply command with a yaml file

The kubectl get command can be used to pods information and many other kubernetes objects
For ex : kubectl get pod lists all pods
             kubectl get all  lists all resources

Expose a Pod port

By default pods and container are only accessible within kubernetes cluster
To use expose container port externally we can use kubectl port-forward

Ex : kubectl port-forward [name of the pod ] 8080:80  where 8080 is external port and 80 is internal port

Delete Pod

Running Pod will cause deployment to be created
To delete pod use kubectl delete pod or find a deployment and run kubectl delete deployment
kubectl delete  pod [name of pod] will cause pod to be recreated
kubectl delete deployment [name of the deployment] -: delete deployment that manages the pod

To delete a pod which is created using yaml file then we can use below mentioned command
kubectl delete -f file.pod.yml



Sample yaml file for pod creation (Ex : nginx)


kubectl create -f file.pod.yml  will results in error if pod already exists

So alternative way to create or apply changes to a pod is to use kubectl apply -f file.pod.yml

Use --save-config when you want to use kubectl apply in the feature (it saves current properties in resource's annotations)

kubectl apply -f file.pod.yml  --save-config





Pod Health
Kubernetes relies on Probes to determine the health of the pod container

A probe is a diagnostic performed periodically by kubelet on a container




Readiness Probe ; when should a container start receiving traffic?
Liveliness Probe : when should a container restart ?

Reference : Mr.Dan Wahlin  course

Kubernetes - Getting started with - ReplicaSet ,Deployments

ReplicaSet : It is a declarative way to manage the pods.

Deployment : it is a declarative way to manage the pods using ReplicaSet.






How Does Spring Boot Work?






Spring MVC Integration with SpringBoot(Internal mechanism steps-)







Useful Links related to Spring

Spring Web Application Design

Spring Performance


Enable Config Server (Centralized configuration)