Sending Message Headers with Spring AMQP outbound gateway - java

I have used Spring Amqp Outbound Gateway integration to send request to a third party web service. Below shown is my gateway interface.
public interface AccountManagerGateway {
public RetrieveAccountResponse retrieveAccount(RetrieveAccountRequest request);
}
I need to know how to send custom Message Headers with the gateway call.
Ex:- "AccountID" in the header
I did some google searches but couldn't find a solution. May be I'm doing the search in a wrong context or a wrong direction. I'm expecting your kind support on this.
Please let me know if you need more info. I didn't post my integration-context xml in here because then the post will get lengthy.
Thanks.

See the documentation about gateways.
For example:
public RetrieveAccountResponse retrieveAccount(RetrieveAccountRequest request,
#Header("AccountId") String accountId);
By default, user-defined headers are not sent over AMQP so you need to configure the mapped-request-headers on the outbound gateway; something like
mapped-request-headers="STANDARD_REQUEST_HEADERS,AccountId"
Again, refer to the documentation.

Related

How to change routes url based on request body in spring cloud

I want to route requests based on some values in requestBody in spring cloud, for example:
if value of firstField in requestBody is chagre, I want to route this request to /chagre api
else if value of firstField in requestBody is package, I want to route this request to /package api
Any help would be appreciated.
Best practice is not to route according to request body, but use different attributes of the HTTP request instead. Spring Cloud Gateway includes many built-in route predicate factories based on those attributes.
The problem is request body can be read only once. moreover you need to know the object class it contains in order to properly read it.
In order to construct a solution to your question, we can use Spring Cloud Gateway ModifyRequestBody to rewrite the request body after you read it and before it send to the downstream.
Read more about ModifyRequestBody

How to set filter header in Undertow without Wildfly

I'm just started with Undertow.
I would like to add the header filter that only allows the request with RequestProperty like below code.
con.setRequestProperty("X-Client-Token", TOKEN);
con.setRequestProperty("X-Client-Secret", SECRET);
I have been written the method to check the header after receiving the request by using HttpServerExchange exchange after implement io.undertow.server.HttpHandler. But I need to use this method for each request after receiving.
So. It's there any other way to check and filter the header parameters in undertow without using Wildfly server. And how to do it.
Thank you.

spring http outbound gateway customization

My requirement is to call siebel soap webservice, In the process handle request and response on a same method call, so that I can add token to the request header from the apache common pool and once get the response with token, grab the token from response and send it to pool. Here I have mechanism to verify old token too,
I need request token and response token on same class.
Future planning to add retry mechanism.
Currently I am using SI Http outbound gateway.
Any thoughts, appreciate it.
Thanks
So, what you need is named pre- and post-process. Not sure why you don't use Spring Integration WS support for calling that Siegel service, but even with the HTTP you can get a gain via Interceptor abstraction.
What I mean that you can inject RestTemplate into HTTP Outbound Gateway supplied with the ClientHttpRequestInterceptor implementation to provide a desired logic.
If you'd use WS Outbound Gateway, you could do that in the similar ClientInterceptor abstraction.
Of course, you can achieve that via HeaderMapper implementation, but that has different responsibility...
I found the way to achieve this,
Created a class to extends HttpRequestExecutingMessageHandler than overrided handleRequestMessage()
http://docs.spring.io/spring-integration/reference/html/http.html#http-outbound

Logging request and response json payloads with Hystrix Feign

I am using Hystrix Feign with Spring Encoder.
I want to log exact request (Json) payload that goes out with each request
and also the response.
How can I do that?
When you define your feign configuration, you have to set the feign logger level, according to the feign logger class, you have 4 possible values, so probably you want to use Logger.Level.FULL.
Hope this help you.

HTTPS to file in Apache Camel

I need to access a HTTPS Resource which is using Basic Authentication and It is a GET Resource. I have written a code in java using URIBuilder and adding the username, password etc as Headers to the URIBuilder and using Apache HTTPClient to access the resource and it is working well.
Now my requirement is to implement the same functionality using Apache Camel, Well I tried using Camel HTTP component and by using Java DSL.
The problem is I am just able to provide the URI. But how can I add various Headers to this URI ?.
I suggest you use the http4 component as a way to consume this secure resource. From reading the docs of the component you can see it's possible to set the query parameters, path and even uri at runtime.
In answer to your specific question, the headers on the exchange at the point it reaches the .to() will be sent as headers in the HTTP request so you may want to define a header filter strategy. It has support for http basic auth and you can set your credentials via the authUsername and authPassword headers. You may need to provide a custom HttpContext because you're authenticating via https as it suggests at the bottom of the docs. For example:
from("direct:in")
.process(new Processor() {
public void process(Exchange exchange) {
//These headers you set here will get sent with the http request in the to() after this processor
exchange.getIn().setHeader("authUsername", "username");
exchange.getIn().setHeader("authPassword", "password");
}
})
.to("https4://uri.com);
Use the simple language to add headers if you are using blueprint or the java dsl if its pure java. Simple example:
from("direct:start")
.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.POST))
.to("http4://www.google.com")
.to("mock:results");

Categories

Resources