Posts

Showing posts with the label Spring

Rest API simple Application with http mothods

We will be developing REST API using JAX-RS (Jersey) and Tomcat server and we will be implementing basic 4 methods so lets get started Here is pom.xml file: <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.dpq.webservices</groupId><artifactId>SimpleRestApiApp</artifactId><packaging>war</packaging><version>0.0.1-SNAPSHOT</version><name>SimpleRestApiApp</name><build> <finalName>SimpleRestApiApp</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1&

Rest API understanding with its Architecture

REST is an acronym for  RE presentational  S tate  T ransfer and an architectural style for  distributed hypermedia systems . 1. Principles of REST:     Uniform Interface: The following four constraints can achieve a uniform REST interface: Identification of resources  – The interface must uniquely identify each resource involved in the interaction between the client and the server. Manipulation of resources through representations  – The resources should have uniform representations in the server response. API consumers should use these representations to modify the resources state in the server. Self-descriptive messages  – Each resource representation should carry enough information to describe how to process the message. It should also provide information of the additional actions that the client can perform on the resource. Hypermedia as the engine of application state  – The client should have only the initial URI of the application. The client application should dynamically driv

Spring Batch Partitioning with Example

In Spring Batch, “Partitioning” is “multiple threads to process a range of data each”. For example, assume you have 100 records in a table, which has “primary id” assigned from 1 to 100, and you want to process the entire 100 records. Normally, the process starts from 1 to 100, a single thread example. The process is estimated to take 10 minutes to finish. Single Thread – Process from 1 to 100 In “Partitioning”, we can start 10 threads to process 10 records each (based on the range of ‘id’). Now, the process may take only 1 minute to finish. Thread 1 – Process from 1 to 10 Thread 2 – Process from 11 to 20 Thread 3 – Process from 21 to 30 …… Thread 9 – Process from 81 to 90 Thread 10 – Process from 91 to 100 To implement “Partitioning” technique, you must understand the structure of the input data to process, so that you can plan the “range of data” properly. Example: Please find git project repository which is on spring batch partitioner https://github.com/dpq1422/retail-spring-batch  

Spring Integration Routers LAB-13

Create a recipient list router: Recipient list routers are meant to disburse received messages to all of its outbound channels without regard for message header or payload content. If you will, a recipient list router simply blasts incoming messages to all the channels listed as “recipients.” In this step, you create a recipient router to route Norway ship orders to both a file adapter and a service activator that prints out information regarding the Norway ship order to the Console view. Add two new Norway message channels. There needs to be two new message channels to serve as recipients of the Norway messages. The first new channel will take messages that will ultimately be routed to the file system. The second new channel will receive messages that will ultimately be routed to the service activator. <int:channel id=”norwayFileChannel” /> <int:channel id=”norwaySAChannel” /> Change the File adapter for the Norway messages to now get its messages from the norwayFileChanne

Spring Integration Routers LAB-12

Image
Routers direct messages to an appropriate message channel typically based on what is in the payload or header of a message. Routers do not alter the message like a transformer. Routers don’t remove messages from the system like a filter can. They simply provide forks in the road of message channels in a Spring Integration (SI) application. In this lab, you explore a few commonly used SI routers. Specifically, in this lab you will: Configure and use an XPath router to route XML payload messages. Define a recipient router to send the same message to a collection of channels. Scenario – Route using XPath expression In previous filter Lab, we used XPath expressions in filters to remove or discard some XML messages from the system. In a similar fashion, as will be demonstrated in this part of the lab, an XPath router uses an XPath expression to determine which message channel receives a message containing XML in its payload. In particular, note that the application already contains an inbo

Spring Integration Messaging Channels

Channels are an integral part of any Spring Integration application. There are many channels to choose from. Understanding the basic channel types (subscribable and pollable) is essential to any Spring Integration developer. In this lab, you explore the basic channel types and see the default channel at work. Specifically, in this lab you will: Create a new Spring Integration Maven Project Define the Spring configuration file. Define a Java SE class for running/testing your Spring Integration components. Create and test a subscribable channel. Create and test a pollable channel. Create and test the default Spring Integration channel – the direct channel

Spring Integration Adapters

Adapters are endpoints that connect a message channel to an external system or technology. Adapters take content from outside of SI and bring it in as messages into SI channels or take SI messages and deposit their content to an external system. Specifically, in this lab you will: Create and test an inbound file adap Create and test an outbound file adapter.

Spring Integration Filters

Filters allow, on the basis of a message’s content or metadata (in the message header), a message to pass from one channel to the next or reject and discard the message from the system – that is, not allowing the rejected message into the next channel.  Not all messages are of interest. That is, there is often a need to filter out some messages that enter a channel. Applications may only want to get messages formatted in a certain way (XML or JSON). Applications may only be interested in certain types of data (new sales messages but not messages about shipments). Other application may be interested in messages with certain message headers (for example when a message was created – only wanting to look at messages created after 5pm). In this lab, you explore Spring Integration (SI) filters to examine messages in a channel and accept those of interest and discard the others. Specifically, in this lab you will: Implement the SI MessageSelector interface and configure an SI filter. Explore

Spring Integration Transformer (Transform XML Messages to Java Objects) :Lab11

XML is popular way to deliver data. However, Java applications prefer to work with the data in object form. A built-in SI transformer provides the ability to convert an XML payload message into a message containing a Java object holding the data of the XML message. This process is called unmarshalling transformation (an opposite process – going from Java object to XML payload also exists and that is called marshalling). Under the covers, the unmarshalling transformer uses JAXB technology to perform the XML to object work. In this portion of the lab, you explore the use of a SI unmarshalling transformer. We will use JAXB here to marshalling and un-marshalling.

Spring Integration Transformer (Custom Transformer and Annotations) :Lab10

As with filters and many other SI components, you can create your own custom transformer. When the transformation is particularly complex or when you need to transform to / from a type that Spring does not know about, you will find custom transformation the route to take. In this next step, you create a custom transformer – one that transforms the string payload of the source message to a pig Latin translation of the string in the target message. In this step, you also see the use of annotations to configure your transformer. SI (and all of Spring) allows the use of annotations in your Java code to simplify the configuration of components and reduce the amount of XML associated to your application. While annotations were not used in the prior labs (like the filter lab), you will find that SI comes with a number of annotations that can be used in place of XML for the configuration of just about any SI component. Examine and annotate the Transformer class. A class containing the Pig Lati

Spring Integration Transformations

No, Spring does not have Autobots, but the concept – turn something from one thing to another thing – is provided for in Spring Integration. Spring Integration (SI) transformers turn one type of message into another. In the world of integration, data providers and data consumers don’t always speak the same language. So transformers provide SI applications the means to convert messages between formats to facilitate non-homogeneous message exchange. For example, a producer may provide information in XML format. It is the data your application needs, but it would like that data in JSON form. A SI transformer can perform that message conversion. In this lab, you explore several types of SI transformers – some provided by SI out of the box. As you have learned with other SI components, you can also create your own custom transformer. Specifically, in this lab you will: Configure and use a message payload transformer. Define a custom transformer. Explore the use of annotations to reduce SI c

Spring Integration Transformation (Transform String Messages) :Lab-9

Scenario – Transform String Messages In the first part of this lab, you some simple string message to string message transformers. That is, these transformers take a message with string payload from a channel (called the source message in SI), change the string payload of a message, and put a message with the altered string into another channel (called the target message in SI). These simple examples will help you understand the basic configuration of a transformer and allow you to see how to create your own custom transformer.

Spring Integration Filters (Validation Filter) :Lab-8

SI also comes with a ready-made validating filter. When dealing with XML messages that are supposed to conform to an XML schema, it is often helpful to weed out XML messages that do not conform to the schema. Using SI’s built-in validating filter, all you have to do is specify the location of the appropriate schema (.xsd) file and XML messages are filtered out of a channel when they do not align with the schema definition. Add a validating filter. By this point in the tutorials, you have started to work enough with SI applications and SI components to start to get a feel for how they are configured and how the framework works. So it is time to put some of those skills to the test. Replace the XPath filter with a validating filter to accept only those XML shiporder messages that comply with the schema you saw in step 8.1. The basic template is shown below. You need to supply the in and out message channels along with the location of the schema file it is to use to do the filtering. spri

Spring Integration Filters (XML Messages with XPath) :Lab-7

XML is popular in many messaging systems to include Spring Integration. XML describes the data while also providing the data. When dealing with many messages, it can be inconvenient to convert the XML messages to objects or even strings and parse the data for relevant messages. Spring Integration already comes with a built-in XPath filter that allows you to define a filter with an XPath expression to select only messages of interest. You will learn more about transforms in an upcoming tutorial. There are many types of transformer message endpoints. Spring provides one called a file-to-string transformer. This transformer turns a file message (that is a SI message with a file as its payload) into a string message (a SI message with a string as its payload). The string that fills the resulting message is from the contents of the file. Why is this important? In order for an XPath filter to accept or reject the XML in a message, it must first be able to access the XML contents rather than

Spring Integration Filters (Message Selectors) :Lab-6

Filters allow, on the basis of a message’s content or metadata (in the message header), a message to pass from one channel to the next or reject and discard the message from the system – that is, not allowing the rejected message into the next channel.  Not all messages are of interest. That is, there is often a need to filter out some messages that enter a channel. Applications may only want to get messages formatted in a certain way (XML or JSON). Applications may only be interested in certain types of data (new sales messages but not messages about shipments). Other application may be interested in messages with certain message headers (for example when a message was created – only wanting to look at messages created after 5pm). In this lab, you explore Spring Integration (SI) filters to examine messages in a channel and accept those of interest and discard the others. Specifically, in this lab you will: Implement the SI MessageSelector interface and configure an SI filter. Explore

Spring Integration file-input-output-channel-adaptor :Lab-5

We will Create and test an inbound file adapter. Create and test an outbound file adapter\ Here we will only be using  file-inbound-channel-adapter and file-inbound-outbound-channel-adapter   channels in place of  std-in-channel-adapder and stdout-channel-adapter  which we have used in previous labs(Channel labs) spring-integration-file-outbound-channel-adapter.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-file="http://www.springframework.org/schema/integration/file" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int-stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://ww

Spring Integration Labs

Here we will try to understand Spring Integration(SI) using examples and will understand and cover each and every component in detail.

Spring Integration Tutorials

Spring Integration is an open source framework for enterprise application integration. It is a lightweight framework that builds upon the core Spring framework. It is designed to enable the development of integration solutions typical of event-driven architectures and messaging-centric architectures.

Spring Integration file-outbound-channel-adaptor :Lab-4

We will Create and test an inbound file adapter. Create and test an outbound file adapter Before we start we already explore adapters. we have already used adapters in the first lab. You used Standard Input and Standard Output adapters to bring String data into the message channel and print it to the Console view Here we will only be using file-outbound-channel-adapter channel in place of stdout-channel-adapter which we have used in previous labs(Channel labs) spring-integration-file-outbound-channel-adapter.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-file="http://www.springframework.org/schema/integration/file" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int-stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation=" http://www.spr

Spring Integration Channels-Direct channel :Lab-3

The only difference b/w Pollable and Direct channel is , There will not be any queue size limit in Direct channel <int:channel id=”messageChannel” /> Everything else will remain same as with pollable channel. spring-integration-channels.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:int="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int-stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.x