Posts

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());      ...

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 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.0.13</version> </dependency> 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">         <resetJUL>true</resetJUL>     </con...

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. https://github.com/youdhveer/struts1

Load csv file data into MySQL table

Suppose we have a device table along with following columns. id(integer),device(varchar),device_data(varchar). Now suppose you want to upload data from a device.csv file like given below. --------------------------------------------------- "id","device","device_data" "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  FIELDS TERMINATED BY  ','  ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (@id, device, device_data) SET id= CONVERT( @id, UNSIGNED...

MS SQL Server : How to remove duplicate text in a csv String in table

Here is the function which will return string after removing duplicate text from a csv cell value. create function dbo.RemoveDuplicateTextInCSVString(@SOURCE_STR varchar(50)) returns varchar(50) as begin     declare @TEMP_STR varchar(50)   declare @WORD_STR varchar(50)   set @TEMP_STR = ','   while len(@SOURCE_STR) > 0 begin print '--------------------' set @WORD_STR = left(@SOURCE_STR, charindex(',', @SOURCE_STR+',')-1)+',' print '@WORD_STR :'+ @WORD_STR if charindex(','+@WORD_STR, @TEMP_STR) = 0 begin set @TEMP_STR = @TEMP_STR + @WORD_STR print '@TEMP_STR : '+@TEMP_STR end else print 'found duplicate, remove this..' set @SOURCE_STR = stuff(@SOURCE_STR, 1, charindex(',', @SOURCE_STR+','), '') print '@SOURCE_STR '+@SOURCE_STR   end   return @SOURCE_STR end

Collection holds value as a refernce in java

Value as a Reference example : Here we are fecthing a list from a collection and updating this which leads to automatic update of Map because  numList is directly referring to   testmap. ----------------------------------- public class ValueAsReference{ enum EvenOdd{ EVEN,ODD } public static void main(String ... arg){ Map<String,List<String>> testmap=new HashMap<String, List<String>>(); for(int i=0;i<20;i++){ String key=""; if(i%2 ==0){ key=""+EvenOdd.EVEN; }else{ key=""+EvenOdd.ODD; } List<String> numList=testmap.get(key); if(numList==null){ numList=new ArrayList<String>(); numList.add("i="+i); testmap.put(key, numList); }else{ numList.add("i="+i); } } for(String key : testmap.keySet()){ System.out.println("key : "+key); System.out.println(testmap.get(key)); } ...