Sunday, July 15, 2018

How can I listen for keypress event on the whole page in AngularJS 2 – 6

Add following line on @component decorator class
host: {‘(document:keypress)’: ‘handleKeyboardEvent($event)’}
and implement handleKeyboardEvent(event:KeyboardEvent)
styleUrls: [‘./add-component.component.css’],
// tslint:disable-next-line:use-host-property-decorator
host: {‘(document:keypress)’:’handleKeyboardEvent($event)’}
handleKeyboardEvent(event: KeyboardEvent) {
if (event.keyCode===13)
console.log(“Enter key pressed 13”);
} else if (event.keyCode === 40)
} else if (event.keyCode === 38)

How to disable browser back button in AngularJS 2 to 6

Use location.onPopState to the same in AppComponent
import { PlatformLocation } from ‘@angular/common’;
constructor(location: PlatformLocation, private router: Router) {
location.onPopState(() => {
console.log(‘pressed back in add!!!!!’);

Tuesday, June 05, 2018

How to do JUnit for Servlet class

Mockito class can be used to do JUnit for your servlet
Lets say we have following below given servlet in our code
package com.siddhu;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1031422249396784970L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.print("Hello World from Servlet");
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
doGet(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
// TODO Auto-generated method stub
And we want to do Junit for this servlet follow below given steps
1- If you project is MAVEN add follwing line in your POM.xml
2- If your project is normale dynamic project please add above jar to your project build path
3- Create a new class in the same package for doing JUnit
package com.siddhu;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.mockito.Mockito;
public class TestHelloWorldServlet extends Mockito{
public void testServlet() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
//Way to set parameter in servlet
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
new HelloWorldServlet().doPost(request, response);
//verify(request, atLeast(1)).getParameter("username"); // Checking the value if username as same from calling servlets
writer.flush(); // it may not have been flushed yet...
assertTrue(stringWriter.toString().contains("Hello World from Servlet"));
3- If you are using Eclipse run the above class as right click --> run as --> Junit Test and you will find below screen

Wednesday, May 16, 2018

Creating new Project in AngularJS6

1- Create new angularJS2 project using Eclipse Plugin i.e. AddSubDivMultiProjectAngularJS6
2- Use Terminal Prospective and run following command inside it ng serve
i.e. cd c:\ng serve\AddSubDivMultiProjectAngularJS6
3- Refresh the project in Eclipse
4- Run following command on terminal
/c/eclipse_workspace_angularjs2/AddSubDivMultiProjectAngularJS6 (master)
$ ng serve
** Angular Live Development Server is listening on localhost: 4200, open your browser on http://localhost:4200/ **
Date: 2018-05-16T10:07:23.618Z
Hash: 7aa519b4302c2dcafe34
Time: 16419ms
chunk {main} main.js, (main) 446 kB [initial] [rendered]
chunk {polyfills} polyfills.js, (polyfills) 415 kB [initial] [rendered]
chunk {runtime} runtime.js, (runtime) 5.4 kB [entry] [rendered]
chunk {styles} styles.js, (styles) 149 kB [initial] [rendered]
chunk {vendor} vendor.js, (vendor) 5.14 MB [initial] [rendered]
i ?wdm?: Compiled successfully.
i ?wdm?: Compiling...
Date: 2018-05-16T10:09:11.742Z - Hash: a4781c06eea8b6e93b0c - Time: 1178ms
4 unchanged chunks
chunk {main} main.js, (main) 446 kB [initial] [rendered]
i ?wdm?: Compiled successfully.
- If during execution if you are gettin errors like TS2307: Cannot find module 'rxjs-compat/Observable'.
Make sure to run
/c/eclipse_workspace_angularjs2/AddSubDivMultiProjectAngularJS6 (master)
$ npm install rxjs-compat --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ rxjs-compat@6.1.0
added 1 package in 30.978s

- If getting below error
ERROR in src/app/app.module.ts(13,31): error TS2307: Cannot find module 'primeng/primeng'.
src/app/app.module.ts(14,28): error TS2307: Cannot find module 'primeng/primeng'.
Execute :-
/c/eclipse_workspace_angularjs2/AddSubDivMultiProjectAngularJS6 (master)
$ npm install primeng --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ primeng@5.2.6
added 1 package in 50.168s


Thursday, March 22, 2018

How to configure Local Email server hMailServer and Thunderbird

1- First installed the hMailServer from the follwing url.
2- Installed ThunderBird from below given location
3- Configure hMailserver and Thunderbird Email agent as given below



Saturday, March 17, 2018

Deploying the war file in tomcat using Bamboo

Please refer to this link before moving


Check out code from Bitbucket-Build Maven, Stop Tomcat, Re-Deploy new war files Using Bamboo

Please refer to the above the link to first configure project, plan and creating task to create deployable war file using Bombat for Bitbucket repository.


Bamboo with BitBucket Maven Project

Step 1:- Create Bamboo project


Step 2:- Create Plan


Step3:- Configure Task in the above created Plan.


If you see in above image it shown one task already created and that is checking out of the code in repository
Lets create a new Task that will execute the Maven Build i.e. build.xml from our Maven project kept at BitBucket using bamboo tool.
Click on "Add task" button and as we are using Maven 3 we will configure the same in the Bamboo.
cick on save and create button.
Step4:- Execute the task and see the build is prepared.


Step 5:- Check if our war is created properly at given locations.

Please note while using Bamboo version of 6.4.0 we were facing issue with Test Connection button and it was throwing error "git credentials storage exception". So we had taken lower version 6.3.2 and it work like charm.