IT Certificaions

Google Cloud Platform

Tuesday, August 8, 2017

Thursday, May 25, 2017

Create java client from WSDL for Google App engine

This post will explain how to consume SOAP based web services on Google App Engine platform.

  1. Keep your wsdl files in resources/wsdl folder
  2. Make these files entry in appengine-web.xml like
  3.   <static-files>
           <include path="/**.wsdl"/>
         <include path="/**.WSDL"/>
  4.  Now update POM file for wsdl to java plugin

Now you can use maven commands mvn clean install and stubs will be generated in and packages.

Convert pfx file into jks using java

This is a post which shows how to convert pfx file into jks.

Prerequisites : Java 6+
Step 1: Use cmd with java in your classpath

keytool -importkeystore -srckeystore testKey.pfx -srcstoretype pkcs12 -srcalias <myAliasName>
 -destkeystore jksFile -deststoretype jks -deststorepass password -destalias <alias>

Java Client with certificate authentication to access SOAP Webservice

This is an example to explain  how to authenticate java stub client with certification and send request to SOAP WSDL.

public static void applyCertificateAuthentication(MyWsdlDataRequest wsdlClientRequest)
            throws Exception {

       String keyStoreLocation="resources/keys/testKey.jks";

       String password="key@12345";
        ClassLoader classLoader = this.class.getClassLoader();
        InputStream keyInputStream = classLoader.getResourceAsStream(keyStoreLocation);

        SSLContext sc = SSLContext.getInstance("SSLv3");
        KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(keyInputStream, password.toCharArray());
        factory.init(keyStore, password.toCharArray());
        sc.init(factory.getKeyManagers(), null, null);

        MyWsdlService serviceImpl = new MyWsdlService ();
       MyWsdlDataStub servicePort = serviceImpl.getPort(MyWsdlDataStub .class);               BindingProvider bp = (BindingProvider) servicePort;

((BindingProvider) servicePort).getRequestContext().put("",

 MyWsdlDataResponse response = servicePort.siSaveSocDataOut(wsdlClientRequest);


Monday, August 8, 2016

Configure MDC with SLF4j Logback file in java

This article is all about how you configure MDC logs with SLF4J and logback.

1. Maven POM dependencies: Please add maven dependencies as given below.

       <!-- Logging with SLF4J & LogBack -->

2. Configure logback.xml file

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">

<property name="DEV_HOME" value="c:/logs" />
    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">

    <appender name="FILE-THREAD" class="ch.qos.logback.classic.sift.SiftingAppender">
<appender name="FILE-${logFileName}"

<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
%d{yyyy-MM-dd HH:mm:ss} [%thread] %level %logger{35} - %msg%n



<appender name="FILE_APPENDER" class="ch.qos.logback.core.FileAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
%X{clientName}, [%thread], %-5level %logger{36} - %msg%n

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n

<appender name="FILE-ERROR"
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
%d{yyyy-MM-dd HH:mm:ss} - %msg%n

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->


<!-- Send logs to both console and file audit -->
   <!--  here com.example is my root package -->
<logger name="com.example" level="INFO" additivity="false">

<appender-ref ref="FILE-THREAD" />
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE_APPENDER" />

<root level="ERROR">
<appender-ref ref="FILE-ERROR" />


3. Use logging in java file

package com.example.servlet;


import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.slf4j.MDC;

@WebFilter( filterName = "mdcFilter", urlPatterns = { "/*" } )
public class MDCFilter implements Filter {

public void destroy() {


public void doFilter( final ServletRequest request, final ServletResponse response, final FilterChain chain )
throws IOException, ServletException {

// Get the parameter value.
final String parameter = request.getParameter( "clientName" );

// Put it in the MDC map.
MDC.put( "clientName", parameter );

try {
chain.doFilter( request, response );
} finally {
// When the control returns to the filter, clean it.
MDC.remove( "clientName" );

public void init( final FilterConfig filterConfig ) throws ServletException {



 4. You can also use slf4j logger

package com.example.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class UserController {

private static Logger logger=LoggerFactory.getLogger(UserController.class.getName());

@RequestMapping(value = "/rest/registerUser", method = RequestMethod.POST)
    public  @ResponseBody UserDTO registerUser(@RequestParam("name") String name, 
    @RequestParam("password") String password, @RequestParam("email") String email,
    @RequestParam("contactNumber") String contactNumber) {    

try {"Registering user : name :"+name);
} catch (Exception e) {

                           logger.error("Failed to register : Exception :"+e.getMessage());
        return user;

Thursday, July 14, 2016

Struts 1 with JSON response

You want to explore struts 1.X with ajax based application which returns JSON as a response, you can go following public repository.

Wednesday, July 13, 2016

Load csv file data into MySQL table

Suppose we have a device table along with following columns.

Now suppose you want to upload data from a device.csv file like given below.
"1","A1","this is test device, model-11"
"2","A2","this is test device, model-12"
"3","A3","this is test device, model-13"
"4","A4","this is test device, model-14"

Use following command to insert these values from csv file to table with casting id value from text to integer.

LOAD DATA INFILE 'D:\device.csv' INTO TABLE device 
(@id, device, device_data)