Store raw SOAP request as a message header in Spring Integration - spring-integration

We receive a SOAP message with a int-ws:inbound-gateway and we need to store the raw soap message as a message header or similar to be able to register it in a more advanced step of the integration flow.
How we can do it, it's possible to put an interceptor or similar to do it before the raw message is deserialized to JAXB objects?

You need just to inject an extension of the DefaultSoapHeaderMapper and override its extractUserDefinedHeaders(SoapMessage). There you can do whatever you need with that SoapMessage and even save it into the custom header.

Related

How to retain the initial message payload through the flow in spring integration

I would like to know if there is any way to retain the initial message payload or part of it along the way in the spring integration channels.
Let's say you have an inbound adapter that pulls some information from a system. This message is passed to another endpoint, which transforms it and most likely you will end loosing some data from it. At some point, you want to use some data from the initial message payload for a router.
Is there any global variable you can hold or a pattern?
Is it like carrying the message payload all the way?
is it like adding the needed data in the message header all the way?
Any idea on this, it will be appreciated.
Thanks.
Yes, typically, the easiest solution is to copy the payload to a header using a header enricher.

How to send custom header from spring-cloud-stream (aws kinesis binder) to "legacy" spring integration consumer

I have two applications - the first produces messages using spring-cloud-stream/function with the AWS Kinesis Binder, the second is an application that builds off of spring integration to consume messages. Communicating between the two is not a problem - I can send a message from "stream" and handle it easily in "integration".
When I want to send a custom header, then there is an issue. The header arrives at the consumer as an embedded header using the "New" format (Has an 0xff at the beginning, etc.) - See AbstractMessageChannelBinder#serializeAndEmbedHeadersIfApplicable in spring-cloud-stream.
However, the KinesisMessageDrivenChannelAdapter (spring-integration-aws) does not seem to understand the "new" embedded header form. It uses EmbeddedJsonHeadersMessageMapper (See #toMessage) which cannot "decode" the message. It throws a com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'ΓΏ': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') because of the additional information included in the embedded header (0xff and so on).
I need to send the header across the wire (the header is used to route on the other side), so it's not an option to "turn off" headers on the producer. I don't see a way to use the "old" embedded headers.
I'd like to use spring-cloud-stream/function on the producer side - it's awesome. I wish I could redo the consumer, but...
I could write my own embedded header mapper that understands the new format (use EmbeddedHeaderUtils), and wire it into the KinesisMessageDrivenChannelAdapter.
Given the close relationship between spring-cloud-stream and spring-integration, I must be doing something wrong. Does Spring Integration have an OutboundMessageMapper that understands the new embedded form?
Or is there a way to coerce spring cloud stream to use a different embedding strategy?
I could use Spring Integration on the producer side. (sad face).
Any thoughts? Thanks in advance.
understands the new format
It's not a "new" format, it's a format that Spring Cloud Stream created, originally for Kafka, which only added header support in 0.11.
I could write my own embedded header mapper that understands the new format (use EmbeddedHeaderUtils), and wire it into the KinesisMessageDrivenChannelAdapter.
I suggest you do that, and consider contributing it to the core Spring Integration Project alongside the EmbeddedJsonHeadersMessageMapper so that it can be used with all technologies that don't support headers natively.

Spring Integration HTTP messageDispatcher for JSON Payload

I am trying to instruct DispatcherServlet to delegate to MessageDispatcher using WebServiceMessageReceiverHandlerAdapter instead of delegating to Controllers.
But the request payload is of JSON . Do we have default messageDispatcher for JSON similar to org.springframework.ws.soap.server.SoapMessageDispatcher for XML?
The concern isn't clear. If we talk about SOAP, then it definitely should be Spring WS, but when the story is about JSON, then it exactly about Spring REST support in Spring MVC. Why would one try to overcomplicate with JSON SOAP when you simply can use REST service.
On the other hand there is nothing about Spring Integration in your question. Please, be specific when you select tags for the question here.

Craftercms: Setting custom headers in email when using EmailFactoryImpl

I am using the Crafter class EmailFactoryImpl to send emails.
I need to be able to send a custom header to the email server. This header (X-SES-CONFIGURATION-SET) is needed in the email server we use: AWS.
Taking a look at EmailFactoryImpl API, the MimeMessage is being created inside the class and there is no way to specify custom headers via parameters.
Is there any work around for this?
Right now at this time you can't. EmailFactory is more of an utility class to easily and quickly create and send emails, but it doesn't allow for heavy customization like adding a header. In this case you're better just using the MimeMessage class directly or Spring's MimeMessageHelper.

Apigee Java Call Out Response

In a standalone java code, using Apache HTTPClient libs, implementing the NTLM Authentication with SharePoint Server and accessing its Web Service and receiving the huge XML content as response. Now this final output is in String format. Created the Java Call Out Policy and uploaded all the jars.
I need some help here,
How to pass the java's final output response to Apigee's response.
My requirement is: If I hit the Apigee API Proxy then I need to receive the Java's output(String) as Apigee's response.
Which policy is more appropriate to handle this response.
Appreciate your help! Thanks in Advance.
You can use the javacallout policy to author custom java code. Here is a related post in SO: Working With JAVA Callout in apigee?
You can try
message.setContent(string) to create the content, and
messageContext.setResponseMessage(Message)
in java code to directly write to output.

Resources