Book Image

Spring Integration Essentials

By : CHANDAN K PANDEY
Book Image

Spring Integration Essentials

By: CHANDAN K PANDEY

Overview of this book

Table of Contents (18 chapters)
Spring Integration Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Beyond default transformers


Spring does not restrict us to use the transformer provided by the framework, we can define our own transformer and it's pretty straightforward. All we need to do is to define a Java class, which takes a particular input type, coverts it to an expected format and puts it onto the output channel. Let's take an example where we want to convert our feed in a format that can be written to DB; we can define a class, which takes a Message payload of type com.sun.syndication.feed.synd.SyndEntry and converts it to com.cpandey.siexample.pojo.SoFeed, which is a JPA entity:

import com.cpandey.siexample.pojo.SoFeed;
import com.sun.syndication.feed.synd.SyndEntry;
public class SoFeedDbTransformer {
  publicSoFeedtransformFeed(Message<SyndEntry> message){
    SyndEntry entry = message.getPayload();
    SoFeed soFeed=new SoFeed();
    soFeed.setTitle(entry.getTitle());
    soFeed.setDescription(entry.getDescription().getValue());
    soFeed.setCategories(entry.getCategories...