Sunday, October 30, 2016

Inherit POJO configurations in Spring! - Reuse the common properties across classes!

How to reuse the pojo configurations of the same class hierarchy:(Homogeneous classes) 

How to solve the below example of rewriting the same properties in all the beans !!

<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="sequenceGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="initial" value="100000" /> <property name="suffix" value="A" /> <property name="prefixGenerator" ref="datePrefixGenerator" /> </bean> <bean id="sequenceGenerator1" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="initial" value="100000" /> <property name="suffix" value="A" /> <property name="prefixGenerator" ref="datePrefixGenerator" /> </bean> <bean id="datePrefixGenerator" class="com.apress.springrecipes.sequence.DatePrefixGenerator"> <property name="pattern" value="yyyyMMdd" /> </bean> </beans>

Solution:
<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="baseSequenceGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="initial" value="100000" /> <property name="suffix" value="A" /> <property name="prefixGenerator" ref="prefixGenerator" /> </bean> <bean id="sequenceGenerator" parent="baseSequenceGenerator" /> <bean id="sequenceGenerator1" parent="baseSequenceGenerator" /> </beans>

Or


How to reuse the pojo configurations of the different class hierarchy: (Heterogeneous classes)  i.e Inherit Properties from Parent POJOs with Different Classes:

For example, let's add another ReverseGenerator class that also has an initial property.
package com.apress.springrecipes.sequence;

public class ReverseGenerator 
{
    private int initial;
    public void setInitial(int initial) 
    {
           this.initial = initial;
    }
}

Now SequenceGenerator and ReverseGenerator don't extend the same base class—that is, they're not in the
same class hierarchy, but they have a property of the same name: initial. To extract this common initial property,
you need a baseGenerator parent bean with no class attribute.

<?xml version="1.0" encoding="UTF-8"?> <beans> <bean id="baseGenerator" abstract="true"> <property name="initial" value="100000" /> </bean> <bean id="baseSequenceGenerator" abstract="true" parent="baseGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="suffix" value="A" /> <property name="prefixGenerator" ref="prefixGenerator" /> </bean> <bean id="reverseGenerator" parent="baseGenerator" class="com.apress.springrecipes.sequence.ReverseGenerator" /> <bean id="sequenceGenerator" parent="baseSequenceGenerator" /> <bean id="sequenceGenerator1" parent="baseSequenceGenerator" /> <bean id="sequenceGenerator2" parent="baseSequenceGenerator" /> </beans> 



Friday, October 21, 2016

How to use the most useful software that you have!

These are the options that it supports to customize it:

1, add -p parameter that specifies the listening port
2, add the -u parameter is used to specify a user name
3, add -prolongationPeriod parameters. 

Hope you got it!

Friday, October 14, 2016

Listing files that were changed in a certain range of time

Here is the simple thing, that you can do to crack the list!

touch -t 201610110000 startTime 
touch -t 201611110000 stopTime 
find . -newer startTime \! -newer stopTime

Monday, October 3, 2016

Port forwarding in linux!

Remote Machine: ssh -Lserver-port:localhost:destination-port destination-user@destination-ip

eg:
ssh -L6190:localhost:389 admin@ldap1

Local Machine: ssh -Llocalhost-port:localhost:server-port server-user@server-ip

eg:
ssh -L6190:localhost:6190 admin@web

Cheers,

RK 

please consider the environment before printing 


Wednesday, August 31, 2016

Running AspectJ (AOP) without Spring!

  • Just make sure you have below dependencies and the plugin available in your pom.xml.
  • Build the project
  • Run your main class
  • You are done!

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.2</version>
</dependency>


<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<complianceLevel>1.7</complianceLevel>
<source>1.7</source>
<target>1.7</target>
<complianceLevel>1.7</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Saturday, August 6, 2016

Adding an ldap attribute to the local WSO2 IS servers

1.      In the directory IS/repository/data/org.wso2.carbon.directory/schema/ou=schema/cn=inetorgperson/ou=attributetypes add the ldif file with the given content and file name
       FileName: m-oid=2.16.840.1.113730.3.1.13.ldif
       Content:
                      version: 1
                      dn: m-oid=2.16.840.1.113730.3.1.13,ou=attributeTypes,cn=inetorgperson,ou=schema
                      createtimestamp: 20090818022732Z
                      m-singlevalue: TRUE
                      m-obsolete: FALSE
                      m-description: RFC2798: password policy details storage
                      m-usage: USER_APPLICATIONS
                      creatorsname: uid=admin,ou=system
                      m-collective: FALSE
                      m-oid: 2.16.840.1.113730.3.1.13
                      entrycsn: 20090818052732.318000Z#000000#000#000000
                      m-substr: caseIgnoreSubstringsMatch
                      m-nousermodification: FALSE
                      m-syntax: 1.3.6.1.4.1.1466.115.121.1.15
                      objectclass: metaAttributeType
                      objectclass: metaTop
                      objectclass: top
                      m-name: passwordPolicyDetails
                      m-equality: caseIgnoreMatch 
2.      In IS/repository/data/org.wso2.carbon.directory/schema/ou=schema/cn=inetorgperson/ou=objectclasses edit the m-oid=2.16.840.1.113730.3.2.2.ldif file and add the below line: 
                       m-may: passwordPolicy
3.      Add a claim entry in claim-config.xml
4.      Add a claim mapping in the UI

Cheers,
RK

Thursday, June 23, 2016

Error "Android N requires the IDE to be running with Java 1.8 or later" on Mac


To rectify the above problem on Mac follow the below commands!

$ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk
$ open /Applications/Android\ Studio.app


Wednesday, April 13, 2016

How to open files in new tab instead of in new window in sublime text

Use the following configuration to open the files in new tab rather than in new window.

Preference > Settings – User >

"open_files_in_new_window": false

Wednesday, March 9, 2016

Hazle cast cache usage in wso2 products

Hazle cast cache usage in wso2 products:

Imports:

import javax.cache.Cache;

import javax.cache.CacheConfiguration;

import javax.cache.CacheManager;

import javax.cache.Caching;

Code:


private void playWithCache()

{

final CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");

final String cacheName = "cacheXXX";

final Cache<String, Integer> cache = cacheManager.<String,Integer>getCache(cacheName) == null ? cacheManager.<String,Integer>createCacheBuilder(cacheName).setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.MINUTES, 10)).setStoreByValue(false).build() : cacheManager.<String,Integer>getCache(cacheName);

final intvalue = 9876;

final String key = "key-1";



logger.info("Getting cache entry from cache: "+cache.get(key));

logger.info("Inserting cache entry into cache..");

cache.put(key, value);

logger.info("Inserting cache entry into cache done.");

logger.info("Getting cache entry from cache after insertion: "+cache.get(key));

}

How to do ssh tunnel to private network

From localhost:
ssh -L6389:localhost:389 user1@ip1

From IP1:
ssh -L389:localhost:389 user1@ip2