Java

Swagger Tutorials & Notes

Java
What is the URL to open Swagger UI ? https://localhost:8080/ngdeveloper/api/swagger-ui.html What is the URL to view the list of API's as JSON in Swagger ? https://localhost:8080/ngdeveloper/api/v2/api-docs How to disable Swagger related URL's in Spring Security ? In your WebSecurityConfig class make sure to skip the below endpoints/urls, @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/actuator/**", "/v2/api-docs", "/webjars/**", "/swagger-resources/**","/swagger-ui.html"); } In very few case it still throws the exceptions then try "**/swagger-resources/**" instead of "/swagger-resources/**" How to disable Swagger UI in Production ? Swagger UI can be enabled or disabled based on the profile. Make sure you have s...

Java Interesting Problems

Java
How to print Fibonacci Series Till 1000 ? import java.math.BigInteger; public class FibonacciSeries { public static void main(String[] args) { int input = 100; BigInteger n1=BigInteger.valueOf(0),n2=BigInteger.valueOf(1),n3=BigInteger.valueOf(0); for(int i=2;i<=input;i++) { n3=n3.add(n1).add(n2); System.out.println(n3); n1=n2; n2=n3; } } } Learning from the above program: You can not use int/Integer and also long/Long to store the value. Because maximum value of int(2147483647) and long(9223372036854775807). Both these values would be reached even before the first 100 fibonacci series values.So BigInteger is one and only option for us to print the value of fibonacci series more than 100.BigInteger size is int[] of 2147483647 [Integer.MAX_VALUE), so...

How to save & load Jenkins docker images in two hosts

Java
This posts help you with step by step instructions to move jenkins images from one hosts to another hosts. I have personally used the below method and worked great for me. I have another method mentioned here. But that gave me lot of errors and also the jenkins_home contents like custom shell scripts/job details etc were missed. But still I have posted because this can work for other docker containers. Step 1: Save Jenkins Image in Machine 1 docker save jenkins > jenkins_bkup.tar Step 2: Move the .tar file to Machine 2 from Machine 1 sudo scp -o StrictHostKeyChecking=no -i "my-docker-pair.pem" /home/ec2-user/jenkins_bkup.tar ec2-user@AWS_MACHINE_HOST:/home/ec2-user/jenkins_bkup.tar Step 3: Docker Load in Host 2/Machine 2 cat jenkins_bkup.tar | docker load Ste...

AWS Notes

Java
How to copy some files from your aws machine to your local desktop ? Download Mobaxterm community edition, open new session then go to desktop, scp -i "my-docker-keypair.pem" ec2-user@AWS_HOST_NAME:/home/ec2-user/ngjenkins.tar / my-docker-keypair.pem is the keypair file which you can download from aws console. ngjenkins.tar is my tar file which I need to copy from AWS machine to local desktop. I am running this command from desktop and I need the file to be downloaded to desktop only, so gave just ("/") in the copy command. How to copy files from your local machine to AWS Machine ? scp -i "my-docker-keypair.pem" /ngjenkins.tar ec2-user@AWS_HOST_NAME_PUBLICH:/home/ec2-user/ngjenkins.tar

How to Implement JWT Token Based Authentication in Spring Boot Microservices

Java, Spring Boot, Tools
JWT (JSON Web Token) tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties. It is highly recommended and used authentication method for REST API & Webservices. Today we are going to see how to implement JWT token based authentication in spring boot microservices to securely communicate and transfer the data's between the client(any client applications, angular/react/vue in modern application world) and server side applications. Though process for Token Based Authentication Spring security is needed for JWT token based authentication Ensure the signup / login REST API accesses are allowed in spring security (or disable these two API's) During signup, save the captured user details in the user table then generate and res

Fix for AWS SSH Connection Hangs ?

Java
Fix for AWS SSH Connection Hangs ? You could have not added the SSH TCP connection to your ec2 instance, thay may be creating this issue aws SSH connection Hangs issue. Follow the simple 3 steps to get away from this, 1. Login to AWS EC2 Console and click on Security Groups (available in the left sidebar). 2. Select your EC2 instance's security group then click on the Inbound tab. 3. Now add the SSH Rule like this to resolve this issue,
GIT Bash frequently used commands- Cheat sheet

GIT Bash frequently used commands- Cheat sheet

Java
Below are some of the common git bash commands, the most frequently used ones are in italic fonts Scratch- create a new local repository - $ git init {project_name} Download from existing repo - $ git clone my_appliction_url List new or modified files not committed - $ git status show the changes to files not staged/committed - $ git diff Show all the staged and unstaged file changes - $ git diff HEAD Show the changes between two commit ids - $ git commit1 commit2 List the change dates and authors for a file - $ git blame {file} Show the file changes for a commit id and file - $ sit show [commitId]:[file] Show full change history - $ git log Show the change history for file including diffs - $ git log -p [file] List all local branches - $ git branch list all branches,local and ...

File upload (with meta data) in Angular 6 & Spring Boot 2

Angular, Java
File upload (with meta data) in Angular 6 & Spring Boot 2 In Angular side create the component and typescript file similar to this, Part 1: Angular Side Development Angular Template(Html) file: [html] <div class="row justify-content-center"> <label class="ct-input-file">My File Label Here <input type="file" (change)="onFileChange($event)"> <i class="icon-upload"></i> </label> </div> [/html] Note: class="icon-upload" gives upload icon, if you don't want then you can remove it for older way of file upload button. Angular Component(ts) file: FileUploadService is service class to deal api request and responses. MetaDataBean is bean class to send to your api along with the file. Please also read the inline comments...
Flowable Notes for Beginners

Flowable Notes for Beginners

Java
Flowable Notes for Beginners 1. Flowable is a set of process and tasks inside it. Example snippet (as per bpmn20.xml): Below snippet is only for understanding on how the process and tasks will be created in flowable for any bpmn process. Explanation: couponupload is process id/key created to upload the coupons for a particular shop. This process will have set of tasks in order to complete the whole process, here totally 2 process, one is store already partnered or not and whether the category already available or not. [xml] <process id="couponupload" name="Coupon Upload BPMN Process" isExecutable="true"> <userTask id="store-already-partnered" name="Check whether the store is already partnered or not" flowable:assignee="${ storeName }" flowable:candidateGroup...

Developers Repeated Mistakes

Articles, Errors and solutions, Hibernate, Java
In this post we are going to discuss about the repeated mistakes of developers during design/implementation/planning etc. This is just a sudden thought process, so this post will grow on my day to day experience and research wise only. Feel free to comment your repeated mistakes to add it to this master list. In Hibernate/Databases: While creating/planning a column for description, we forget to define the length of values it can hold or even forget to think such scenarios. So always think about the value length for each and every column to design a proper optimistic design approaches: Bad: Here it can hold only till the default size of 255 length, where as, this field may get the value of length more than 255 as well, in that case this fails and all these type of issues can ...