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
Related
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
I'm implementing rate limit filter in JAX-RS application (Websphere Liberty).
Main functionality will be in request filter (implementing ContainerRequestFilter interface), so I can deny request before it reaches endpoint.
However, I would also like to add response headers at the same time (e.g. X-RateLimit-Limit) in any case.
I would like to avoid writing separate ContainerResponseFilter for this purpose because performance reasons. I have all counters loaded already in Request filter.
Is there a clean way to include response headers in request filter for inclusion down the chain?
Solved by passing data in requestContext from request to response filter.
I'm trying to use apollo-android library to communicate with graphql server. The problem is that backend uses headers to authenticate requests and I found no ways to add them. Also in auth request the token is sent in headers and I found no ways to read it from the response.
People advise to set auth headers via interceptors in OkHttpClient but this approach is not applicable in my situation because client have to send different sets of headers in different requests.
So, is there any workaround in this situation? Should I use simple rest client like Retrofit or maybe create new ApolloClient and OkHttpClient instances on each new request with desired set of headers? Or maybe there is another workarounds?
People advise to set auth headers via interceptors in OkHttpClient but this approach is not applicable in my situation because client have to send different sets of headers in different requests.
Have setter methods and fields on your interceptors that accept the varying headers. Call those setter methods prior to making an ApolloClient request that needs the headers.
Or, teach the interceptor how to apply different headers for different requests based on the request characteristics visible to the interceptor (e.g., URL).
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.
I have a use case that required all calls to NewWebService are routed to OldWebService, if the SOAP request does not validate against NewWebService's XSD and WSDL. NewWebService is located on ServerA and OldWebService is on ServerB.
Abstractly, I know I need some mechanism that will allow me to take a SOAP request that hits NewWebService, send it to OldWebService, then return the SOAP result back to the client. My limited experience with spring-ws is making it difficult to decide how to accomplish that.
My first thought was to build a SOAP client into the NewWebService that calls the OldWebService whenever the payload cannot be validated. Is this the best solution, or is there a better way to allow the NewWebService to act as a pass-through for certain requests?
My solution was to write a custom SoapRequestFilter that implements a javax.servlet.Filter and a new class that extends HttpServletRequestWrapper. Since HttpServletRequestWrapper implements the HttpServletRequest interface, extending the wrapper allows you to copy the HttpRequest and act on the stream without consuming the object and causing issues downstream.
Once I had the filter and wrapper, I was able to parse the endpoint and payload from the HttpRequest. If the request needed to be redirected, I created a new HttpUrlConnection to the old SOAP WebService and set the InputStream from that response to the OutputStream of the HttpResponse.
I think Apache Camel can help you in an efficient way.
You can take a look at its proxy example, it's simple and easy to fulfill your requirement.
http://camel.apache.org/cxf-proxy-example.html