JAR file is file archiver which collects/groups different files and folder into a format which represents one file. The format of JAR file is an uncompressed format. Pack200 is a tool that can be used to compress jar file. Below is a simple example of how we can use Pack200 tool to compress the file…… Continue reading Compressing JAR file
Binding single http request type to multiple web resource methods in JAX-RS Application
This post explains how to bind one type of http request to multiple methods of a web resource. Sometimes we need to design a web resource in such a way that we can bind two different yet related web url to different methods. 1) Different url meaning different in their purpose 2) Related url meaning…… Continue reading Binding single http request type to multiple web resource methods in JAX-RS Application
Setter injection example with more than one argument (@Autowired)
In this post under Spring core, I explains how to instruct Spring framework to call a setter method (which take more than one argument) while creating a bean. In most of the cases, the setter methods of a class takes only one argument but if a case arises where a setter method has to take…… Continue reading Setter injection example with more than one argument (@Autowired)
JAX-RS Simple Example
This post explains with an example how to create a simple JAX-RS application. We will create a web resource with two methods, one method to handle get requests and another method to handle post requests, as shown below The resource name is name of the class itself. WebResource Code 1 package resource; 2 3 import…… Continue reading JAX-RS Simple Example
Verifying private method invocation
This post explains how to write an unit test case, to verify a Class’s private method is invoked. We invoke a Class’s private method indirectly through the help of public method exposed by the class. When writing unit test cases for public methods we want to make sure that private methods with expected arguments is…… Continue reading Verifying private method invocation
Accessing cache provider’s CacheManager implementation
This post explains how to access the cache provider’s CacheManager implementation through java cache api. In all my previous post related to Caching, I gave examples where I was using cache provider for caching functionality through the Java Cache API. The java cache api is set of specifications, which are implemented by cache providers and…… Continue reading Accessing cache provider’s CacheManager implementation
Configuring cache non-programmatically
This post explains how to externalize cache configuration to a file instead of configuring them programmatically. For our example, I will be using ehcache tool. Below is the ehcache file which describe the configuration information required to create a cache named “ready-cache”. The key and value data type is String and the entries will be…… Continue reading Configuring cache non-programmatically
Stubbing private methods
This post explains how to stub private methods of a class using PowerMock. Lets consider a class named “Class1” with the structure as shown below Classes to be tested package package3; public class Class1 { private int method1(int value1) { return value1 + 2; } public int method2(int value2) { return this.method1(value2); } } We…… Continue reading Stubbing private methods
Quartz Simple Example
Quartz schedular framework can be used to schedule jobs. This post explains how we can use it with a simple example. We need the below jars 1) c3p0-0.9.1.1.jar 2) log4j-1.2.16.jar 3) quartz-2.2.3.jar 4) quartz-jobs-2.2.3.jar 5) slf4j-api-1.7.7.jar 6) slf4j-log4j12-1.7.7.jar log4j.xml file in the classpath with the below configurations log4j.xml <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”>…… Continue reading Quartz Simple Example
Achieving data binding with object model
This post explains how to achieve mapping of json data represented by an object model to particular java object. Here object model is tree like data structure which reads and stores the entire json content in memory. The difference between this post and other posts in Binding section is that latter posts explains marshalling and…… Continue reading Achieving data binding with object model