JAVA Development

Image upload & retrieve through Spring RESTful Web Service in SAP Cloud Platform

1. Introduction  This blog is about the image upload and retrieval approach in SAP cloud platform through Spring based restful services, The image can be profile pics or some some thumbnail, which end users or client need to store in database along with the user information. So, instead of storing in UI application as folder structure or by any other mechanism, using this way we can store the images in …

Read More »

Generate spring boot AngularJS Applications using J-Hipster

Technology: JHipster is the source code generation tool for Java based applications using spring and Spring Integration frameworks and AngularJS. It also provides the way easier way to develop new features, deploy the applications on various application server and also on Service Registry like Eureka Server for service discovery. It majorly used for developing Micro-services using Spring Boot and angularJS. It provides the high performance, failure tolerance, cluster based applications …

Read More »

How to validate/ get report Read / Unread status + BUSINESS OBJECTS Java SDK

How to validate/ get Document Read / Unread status + BUSINESS OBJECTS Java SDK As a user, we schedule reports and keep it there in our inbox for a while and even sometime there is no business need after schedule, we don’t even open those reports. Another way, there may be recurring schedule jobs running which sends report to user inbox but user do not open if there is no …

Read More »

How to debug jdk source code via eclipse

I met an issue when I wanted to debug jdk source code that eclipse can’t resolve the value of the arguments in functions and it’s not able to see the arguments’ name, however the arguments values are readable in variables view: Why is this? In fact, when compile the java source code in eclipse of rt.jar, oracle chose to remove the debug information so that we can’t debug directly for …

Read More »

ArrayList in multi-thread context

We all know the concept that ArrayList is not “thread-safe”, but why? Test via the following code: package thread; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; class MyThread implements Runnable{ private List<Integer> myList; private Object host; public MyThread(List<Integer> list){ this.myList = list; } private void updateList(int i){ myList.add(i); } @Override public void run() { for( int i = 0; i < 10;i++){ updateList(i); } System.out.println("end: " + myList.size()); } …

Read More »

Inspect running Java process via jmap and jhat

Suppose you have a running Java process and you would like to inspect its running status, for example how many object instance are created or memory consumption status, you can use some standard tool provided by JDK. This blog is written based on JDK 1.8. The sample code I am using to simulate a endless running process: package jmap; class Tool{ private int count = 0; public void Run() throws …

Read More »

How does annotation @Cacheable work

In order to avoid unnecessary query on database it is a common pattern to define a cache in application layer to cache the query result from database. See one example below. Here the application cache is maintained in a custom class CacheContext. public class AccountService1 { private final Logger logger = LoggerFactory.getLogger(AccountService1.class); private CacheContext<Account> accountCacheContext; public Account getAccountByName(String accountName) { Account result = accountCacheContext.get(accountName); if (result != null) { logger.info("get …

Read More »

Use @Rule to define custom rules for your test method

Suppose you need to repeatedly execute some test method in your unit test case, for example, you would like to test getPrice based on the first set of test data 5 times in test method test1() while for the second set of test data, only one time should be executed. The below class RepeatDemoOne is a bad example, where this special LOOP operation is mixed with test method implementation. Ideally …

Read More »

Manage your test case with @SuiteClasses

Suppose I have four test cases in my project, the total methods to be tested: 7 Based on the blog Run only given sets of your unit test via @Category, it is possible to organize test methods within THE SAME CLASS to different categories via @Category, that is, the granularity to control which test methods should be executed is method level. There is another annotation @SuiteClasses which can allows us …

Read More »

Run only given sets of your unit test via @Category

Suppose you have a large number of unit test cases and you don’t want them to be executed all at the same time during Maven build. You can simply achieve it via annotation @Category. 1. Create empty class FastTests and SlowTests. 2. In your test case class, categorize your test method using @Category annotation: 3. Append the following code to your pom.xml: <profiles> <profile> <id>SlowTests</id> <properties> <testcase.groups>com.sap.SlowTests</testcase.groups> </properties> </profile> <profile> …

Read More »