Showing posts with label Java-Development. Show all posts
Showing posts with label Java-Development. Show all posts

Saturday, 26 August 2017

SAP JCo Server Example

Introduction


When writing my first JCo server for I found it very cumbersome to find guiding code snippets and as well as a self-contains, fully working example. Thus I would like to put such an example here.

Sunday, 2 July 2017

Singleton bypass Trap – ABAP and Java

Recently I meet with an issue using Spring which finally turns out that my bean is initialized multiple times although it is expected to be a singleton. As a result I look into the possible scenario that might bypass the expected singleton behavior.

This blog introduces two possible scenarios which will cause your singleton design fail to work as expected.

Thursday, 15 June 2017

An small example to learn Garbage collection in Java and in ABAP

Both Java and ABAP can support automatic garbage collection. As an application developer the GC process are completely transparent for us and in our application code most of the time we should never call the GC API provided by Java or ABAP. Nevertheless it helps us to write more robust code with comparatively lower memory consumption if we have some basic understanding about the trigger point of Garbage collection.

Saturday, 10 June 2017

ADBC and JDBC

Recently during my self study on PostgreSQL I made some practice to connect PostgreSQL in Java programming using Java Database Connectivity – JDBC. In fact I found out that there are lots of commonality between these two technologies.

There is a demo program demo_adbc_query mentioned in SAP help to demonstrate the use of ADBC.

Friday, 2 June 2017

Build an Cross Site Scripting example in Java and ABAP

In this blog, I just show how to build a simple XSS example in Java and then try to implement the same in ABAP as well.

I have a github repository where a simple Java Servlet is developed.

Simply clone it locally and run as Server via url: http://localhost:8080/jerrytest, and it will print out the user gent field of the current http request.

Wednesday, 24 May 2017

ABAP ICF handler and Java Servlet

This blog will not introduce how an ICF handler class in ABAP or a Servlet in Java are developed, but focus the way those instances of handler class or Servlet are spawned by Web Server.
Let’s first study the Servlet spawn behavior in Java.

Servlet in Java


According to Servlet specification, http request against a given url will be served by the same single instance of servlet.

For example, I have developed a simple Servlet which just returns “Hello world” as response. I map it with url starting with “/Hello”.

Tuesday, 9 May 2017

Cross domain request in ABAP and Java with two workaround

Cross Domain Request in ABAP


Create a new ICF node in tcode SICF, implement the following source code in its handler class.

SAP ABAP Guide, SAP ABAP Tutorials, SAP ABAP Certifications

Wednesday, 26 April 2017

Tag(Marker) Interface in ABAP and Java

“Specific predefined global interface. By integrating the tag interface, classes or other interfaces stand out against the ABAP runtime environment. A tag interface generally does not contain its own interface components, but instead assigns a particular task to the integrating classes or interfaces and changes the way they are handled by the ABAP Compiler.“
And in fact this is not a specific concept of ABAP, but exists in many other language as well.

ABAP tag interface


One of the most famous tag interface in ABAP is if_serializable_object.

Sunday, 23 April 2017

Various Proxy Design Pattern implementation variants in Java, ABAP and JavaScript

This blog gives an introduction about various proxy design pattern implementation variant in Java and ABAP.

Below paragraph is quoted directly from Wikipedia:

“A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Use of the proxy can simply be forwarding to the real object, or can provide additional logic. In the proxy extra functionality can be provided, for example caching when operations on the real object are resource intensive, or checking preconditions before operations on the real object are invoked. For the client, usage of a proxy object is similar to using the real object, because both implement the same interface.“

Friday, 21 April 2017

Covariance in Java and simulation in ABAP

I am the trainer of one standard course “Programming Language Concept” within SAP and there is a set of concept Covariance and Contravariance, which has only built-in support by a subset of programming language like Java. For those ABAPers who don’t have chance to touch this concept in their daily work, I have built a small example to simulate how the concept works in ABAP as well for ease of understanding. The example explained in this example is just a prototype purely for training and education purpose.

Wednesday, 19 April 2017

Create dynamic proxy persistently in Java and ABAP

In my blog Implement CGLIB in ABAP I demonstrate how to create dynamical proxy class via CGLIB in Java and ABAP. The generated proxy class is actually a subclass which inherits the base class. Such class created by CGLIB is transient, which means the life time of generated class is only within the current session where it is created, which will not be persisted.

In this blog I will show how to create a globally persistent proxy class dynamically in Java and ABAP.

Tuesday, 18 April 2017

Simulate Mockito in ABAP

What is Mockito?

Mockito is a mocking framework, JAVA-based library that is used for effective unit testing of JAVA applications. In our unit test there are usually some dependency on other external service implementation for example network or database service. Usually in order to isolate our test code from these dependencies we have to create mock class against them. Mockito in Java can create transient mock class ( which is only available in current test session ) for us in a very easy way. See one example below:

Monday, 17 April 2017

Implement CGLIB in ABAP

What is CGLIB?

A Byte Code Generation Library which is high level API to generate and transform Java byte code. It is used in various scenarios such as AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

See one example in unit test.

In line 17, a new dynamic proxy class is generated as mock.
In line 19, we tell the proxy, “if get(0) is called on this mock class, then return mocked data “hello, world”.

Friday, 14 April 2017

Integer in ABAP, Java and JavaScript

When I first begin to program with ABAP I get confused with different kinds of integer type available for ABAP developers: i, int1, int2, int4, and int8.
According to ABAP help, predefined data types consists of two types:

1. predefined ABAP types: b, c, d, decfloat16, decfloat34, f, i, int8, n, p, s, string, t, x, and xstring.
2. predefined dictionary types: INT1, INT2, INT4, INT8,DEC,DF16_DEC,DF16_RAW,DF34_DEC,DF34_RAW and FLTP.