Skip to main content

Posts

Showing posts from 2020

Weblogic - JavaEE 6 migration to JavaEE 7

Weblogic migration to 12.2.x There are significant changes done between JEE 6 and JEE 7. Weblogic 12.2.x uses JEE 7 and applications need to migrate the weblogic related configurations along with JEE API version.In JEE7 many ejb and weblogic related schemas has been changed which I have listed down here. Required schema declaration for all related configurations are as given below.weblogic-ejb-jar.xml <weblogic-ejb-jar xmlns="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.7/weblogic-ejb-jar.xsd"> ejb-jar.xml<ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd" version="…

Adding/ Editing Health checks to deployments in OpenShift

What are health checks in OpenShift Health checks are required to ensure that application is resilient so application can be restarted without manual action. Such health checks can be configured using probes in openshift. Kubernetes provides two type of probes, readiness probe and liveness probe.
Liveness probe Liveness probe checks that application is running and handles those situations when there is any issue with application.
Readiness probe Readiness probe check whether application is ready to handle the traffic.

Another benefit of having these health checks is that you can restart or deploy application with zero downtime when you are having minimum 2 pods running for your application. In this case it will not bring all the pods down.
Supported health check types You can configure the health check of below type for both of the above probes.

HTTP Health Check It will call a web URL and if it returns the HTTP status code between 200 and 399 then it will consider as success otherwis…

Allowing Cross domain POST request with JSON or XML content type in Java

Cross domain POST Request Cross domain POST requests supports only below content types and other content type are not allowed by default.

application/x-www-form-urlencodedmultipart/form-datatext/plain
So, if we try to make an ajax request to such POST URLs with XML or JSON content type, it will not be able to make request and give CORS error.
Allowing Cross domain POST request with JSON or XML Content-Type We have our service implemented in Java and we will use Servlet Filter & request wrapper to build our solution.
Please see my below POST to see how to implement CORS using java servlets which works well with GET methods or allowed content types with POST method.
https://www.thetechnojournals.com/2020/03/cors-implementation-using-java-filter.html

In this POST I will explain only additional things required for our problem with POST request, so I request you to go through the above link first.
Request wrapper to change/ override the content-type to JSON or XML Since, POST request is…

Microservices with Spring Boot - complete tutorial

In this tutorial we are going to learn how to develop microservices using spring boot with examples. Main focus of this tutorial is on learning by doing hands-on. Before hands-on we will first understand what is microservices and related terminologies like DDD, 12-Factors App, Dev Ops.
What is a Microservice In simple terms microservice is a piece of software which has a single responsibility and can be developed, tested & deployed independently. In microservices we focus on developing independent and single fully functioning modules.
Opposite to microservice, with monolithic application it focuses on all the functionality or modules in a single application. So when any changes required to monolithic application it has to deploy and test the complete application while with microservice it has to develop and deploy only affected component which is a small service. It saves lot of development and deployment time in a large application.
It's basically an architectural style whic…

Microservices - Spring cloud API gateway along with registry server

Here we will learn, how to create API gateway using Spring cloud API. We will also register it with discovery/ registry server. Also will see how to access microservice using registry server through API gateway.
What is API gateway As its name implies, API gateway is the single entry-point to an application or system. It can handle a request and invoke the appropriate service registered with it. It provides many features like protocol translation, filtering, security, interceptors etc. Using API gateway we can invoke any microservice whether its direct invocation or using some registry/ discovery server to invoke registered services using their ID.
Creating API gateway In our example we will create an API gateway which will register itself with Eureka discovery server and will invoke the microservice available in discovery server using its registered service ID.
API gateway can be implemented two ways, one is using Zuul proxy and second is using spring cloud API gateway. Difference b…

Microservices - Service Registration/ discovery using Spring boot and Eureka

In this tutorial we will learn how to create registry/ discovery server using Eureka and Spring boot. We will register our Rest microservice with this registry server which can be discovered by client by connecting to registry server.
What is registry/ discovery server We can assume registry or discovery server as a central place where we can find all our microservices using their registered IDs with discovery server. Microservices register themselves in registry server and client applications access them using a single registry or discovery server. It is similar to a phone directory but provides many other useful features.
If we don't user registry server then we need host name and endpoint details to access a service. In today's era most of the services are deployed in cloud and using cloud features like auto-scaling where network addresses are updated dynamically and we can't use a simple network address for that. Now when we use registry server, then such microservice…

Mock unit testing with Mockito and Spring (Ejb and Rest service)

In this tutorial we are going to learn about mock unit testing. We are using here Mockito with Spring to write unit tests. We will also see how to mock an EJB session bean inside mocked service without constructor/setters injection.
What is mocking Mocking is a technique to replace the actual implementation with some dummy or provided code chunk during unit testing. For example if we need to unit test some service which persist data to database then we can mock that persist method to add it to some in-memory collection. Also we can mock data retrieval to get the data from same collection or so. Mockito provide various class and features to implement the mocking seamlessly.
Maven dependency We are using Spring (XML base configuration) and mockito for mock testing. Below dependencies are required.
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.9.RELEASE</version>…

CORS implementation using Java Filter

What is CORS CORS is cross origin resource sharing which allows or block the cross domain calls from a web application between different domains. By default you are able to make Ajax calls to other domain. To enable it that provider also need to add certain headers to allow the requester domain.
CORS Headers Below are the required headers to implement the CORS.
Access-Control-Allow-Origin In this header we specify the domain from which we want to allow the access, for example: example.com. Access-Control-Allow-Credentials This header specifies if it can pass authorization details in cross domain request. for example: true/false. Access-Control-Max-Age We can use this header to specify how long we want to cache the preflight request details like allowed methods, allowed headers etc. We can specify value in seconds and we can cache them for a long time as such details are not change frequently. Access-Control-Allow-Methods Here we specify the methods we want to allow for request, for ex…

Spring boot retry tutorial

Spring Retry API Spring provides spring-retry API for running business logic with retry options and recovery method or operations. In this tutorial we will learn the usage of all these with example. We are using Spring boot application here for our example code.
Maven dependencies To use spring retry we need below dependencies.
spring-retry This API provides many annotations which we can use in a declarative manner to implement the same.
<dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> <version>1.2.5.RELEASE</version> </dependency> spring-boot-starter-aop Spring AOP is also required for retry implementation.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> Retry implementation To implement retry w…

XML Validation using XSD schema

We are going to validate XML using XSD schema in Java. We will create XML Schema using XSD and then use same schema to create the XML file. Then we will write our code to validate this XML against same schema.
XSD Schema creation Below is our schema where we are defining the Schema for XML elements. In this schema we creating two elements, one for request and another for response. We are publishing this schema using targetNamespace which we will use during XML creation.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://services.ttj.com/hello-service" targetNamespace="http://services.ttj.com/hello-service" elementFormDefault="qualified"> <xs:element name="sayHelloRequest"> <xs:complexType> <xs:sequence> <xs:element name="userName" type="xs:string"/> </xs:sequence> </xs:compl…

Setting up ReactJS for development and deployment

In this tutorial we will learn how to create a react application.
Softwares required for ReactJS We need to install below softwares for react development.
Visual studio code This software is free and can be downloaded from https://code.visualstudio.com/download.
Once downloaded, extract the zip  and place the binary under "Applications" and allow app access from System Preferences -> Security & privacy.
Node.JS and NPM Node.JS provides a java script enabled environment to run on a web server. It eases our development for UI based applications. NPM is a package manager which installs along with Node.jS and helpful in installing packages and libraries.
Install Node.JS and NPM using brew.
brew install node Check version of Node and NPM using below command.
node -v npm -v Create React application To create react application we will first install the required package and latter will use it to create our ReactJS application.
Install create-react-app package Execute below co…

Soap over JMS with Spring boot, CXF and Active MQ

Soap over JMS comes with several benefits like, asynchronous processing, one time delivery, assured delivery. This paradigm is mainly used internally in an organization (service providers and clients).
In this tutorial we are going to use Spring boot and Apache CXF to develop a Soap service and then use Active MQ to make it work as "Soap Over JMS".
Creating Soap service using Spring boot and Apache CXF It is very easy to develop a Soap service with Spring boot. We will follow contract first approach to develop the service. We will create a XML schema & use jaxb2 plugin to generate necessary schema classes and then implement the service using them. Please refer below post where it explains in detail, how to develop a Soap service using Spring boot and CXF.
https://www.thetechnojournals.com/2020/01/soap-services-with-spring-boot-and.html
Implementing Soap over JMS To implement the Soap over JMS we need to integrate JMS with soap service where our service listens to a reque…

SOAP service development using Spring boot and Apache CXF

In this tutorial we are going to learn how to develop a SOAP web service using Spring boot and Apache CXF. We will follow the contract first approach to develop our service where we will use jaxb2 maven plugin to generate the java classes which we will use for service implementation.
Why contract first With contract first our primary focus stays with the contract of service to be implemented. Also it is useful to match the input/output with business requirement. We can share the contract with other business units/ customers or users, so it helps them to start early without waiting for the complete implementation. Once our contract is ready we can generate the Java classes using jaxb plugin which generates the java objects using the schema for SOAP contract and we need to focus only on service implementation.
SOAP service development (Hello service) This service will have one operation where user can send their name and in response they will get a hello message with the passed name.
H…