DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Spring Integration - Transforming a Header Object to a Payload

Spring Integration - Transforming a Header Object to a Payload

Matt Vickery user avatar by
Matt Vickery
·
May. 06, 12 · Interview
Like (0)
Save
Tweet
Share
16.72K Views

Join the DZone community and get the full member experience.

Join For Free
Moving objects from the Spring Integration header can be done using several mechanisms. Firstly, a transformer construct can be used:

<int:chain input-channel="request-message-retrieval-channel">
  <int:transformer expression="headers.get(T(com.l8mdv.sample.HeaderManagementGateway)

      .REQUEST_PAYLOAD_HEADER_KEY)"/>
</int:chain>

Secondly, the same action can be performed using a Service Activator:

<int:chain input-channel="request-message-retrieval-channel">
  <int:service-activator expression="headers.get(T(com.l8mdv.sample.HeaderManagementGateway)

       .REQUEST_PAYLOAD_HEADER_KEY)"/>
</int:chain>

Here's a claim-check retrieval - notice the configuration option that triggers the Spring Integration framework to remove the object from the message store once it has been retrieved. If a message requires access several times in a flow, the last claim-check-out can be configured in this way in order to clean-up.
 
<int:chain input-channel="claim-check-out-channel">
  <int:transformer
     expression="headers.get('#{T(com.l8mdv.sample.ClaimCheckGateway).CLAIM_CHECK_ID}')"/>

  <int:claim-check-out message-store="simpleMessageStore" 

                       remove-message="true"/>
</int:chain>

Several interesting points arise:

  1. As can be seen here, it's advisable to reference constants for header key values rather than have the header name appearing as literals in several places throughout the code and configuration. On first sight the SpEL expression language may seem hard to fathom but it's worth investing the effort in order to understand it.
  2. Don't forget that when header objects are moved back into Spring Integration payloads, the object remains in the Spring Integration message header. It may be worth clearing the header value away as part of transformation from the header back to the payload in order to maintain a cleaner and clearer Spring Integration message.
  3. The intent should be clear from the configuration, what looks better a Service Activator expression or a Transformer? In my view the transformer conveys a slightly more accurate intent.
  4. Consider using a claim-check integration pattern instead of loading the header. The Spring Integration claim-check uses a referenced message store (and provides a default implementation) that can be house-cleaned automatically by the framework.
Spring Integration Integration Spring Framework Object (computer science) Payload (computing)

Published at DZone with permission of Matt Vickery, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Use AWS Controllers for Kubernetes To Deploy a Serverless Data Processing Solution With SQS, Lambda, and DynamoDB
  • Java Concurrency: LockSupport
  • 10 Things to Know When Using SHACL With GraphDB
  • 4 Best dApp Frameworks for First-Time Ethereum Developers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: