I am working on spring integration for calling a soap service. I am able to call a soap service using outbound gateway successfully. Now I need to call the same soap service, with same request and now I need add some parameters in http headers.Can anybody help me out in achieving this task . Thank you very much in advance.
You can achieve with request-callback injection to the <int-ws:outbound-gateway>:
public class AddHeaderWebServiceMessageCallback implements WebServiceMessageCallback {
public void doWithMessage(WebServiceMessage message) {
CommonsHttpConnection connection = (CommonsHttpConnection) context.getConnection();
PostMethod postMethod = connection.getPostMethod();
postMethod.addRequestHeader( "foo", "bar" );
}
}
Or... If you need to do that dinamically for each requestMessage you should overcome that with the custom SoapHeaderMapper. Where you can extract CommonsHttpConnection from the TransportContextHolder.getTransportContext().getConnection()
Related
I'm working on a springboot service currently and it needs to have the ability to modify the incoming response body received from various web service calls made by itself.
I googled around a lot and could find info about servlet filters, spring interceptors etc. But all of them sit between this service and its calling clients.
But I'm looking for a component which can sit between this service and the other services that it calls. The closest one I could find was spring's ClientHttpRequestInterceptor, but it doesn't seems to have the ability to modify response body.
Client apps ---> 2. My Springboot service. ---> 3. Other web services
I need to have a component between 2 and 3 here.
Can someone please shed some light on this? Thank you.
P.S: Also I know jaxrs ClientRequestFilter does the trick, but I need a solution for spring RestTemplate based service calls and not for jaxrs based.
In Spring RestTemplate allows us to add interceptors that implement ClientHttpRequestInterceptor interface .
The intercept(HttpRequest, byte[], ClientHttpRequestExecution) method of this interface will intercept the given request and return the response by giving us access to the request,
ClientHttpRequestExecution argument to do the actual execution, and pass on the request to the subsequent process chain
public class BodyInterceptor
implements ClientHttpRequestInterceptor {
#Override
public ClientHttpResponse intercept(
HttpRequest request,
byte[] body,
ClientHttpRequestExecution execution) throws IOException {
ClientHttpResponse response = execution.execute(request, body);
response.getHeaders().add("Iphone_version", "proX");
return response;
}
}
Spring AOP can help in your scenario. It can act as a component before invoking another controller or component.
I'm trying to create service bus using camel and cxf component. Cxf endpoint should receive any soap requests.
I have following snippet:
context.addRoutes(new RouteBuilder() {
override def configure(): Unit = {
from("cxf://http://localhost:7778?dataFormat=PAYLOAD&properties.mtom-enabled=true")
.process(new Processor {
override def process(exchange: Exchange): Unit = {
// do something here
}
})
}
})
context.start
But during requests I get following error:
org.apache.cxf.interceptor.Fault: The given SOAPAction queryINNFL does not match an operation
What can I do to make my endpoint receive all kind of soapaction headers?
You could try to implement CXF Interceptor and connect it to the interceptor inbound chain to the proper place in the endpoint. The individual phases and examples are described there. Your interceptor implementation could then imitate the required SoapAction value, to match the wsdl.
Can anybody provide an example for SSE ( Server sent events) using Spring Rest ? Basically i have a request and the response for it would be sent by the server in multiple chunks. I would like to have the server and client implementation in Spring REST Api without third party rest api like jersey.
There isn't any direct support for SSE in Spring currently but it looks like it will be available in 4.2 which is in RC2 right now
You can see the details here
https://jira.spring.io/browse/SPR-12212
This works via returning an SseEmitter or a ResponseBodyEmitter from the controller methods.
#RequestMapping(value="/stream", method=RequestMethod.GET)
public ResponseBodyEmitter handle() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
// Pass the emitter to another component...
return emitter;
}
// in another thread
emitter.send(foo1);
// and again
emitter.send(foo2);
// and done
emitter.complete();
You can see the Reference documentation here
http://docs.spring.io/spring/docs/4.2.0.RC2/spring-framework-reference/htmlsingle/#mvc-ann-async-http-streaming
I have created an application by following the guide on
http://spring.io/guides/gs/producing-web-service/
Executing the webservice 'getCountry' works fine but now I need to intercept the SOAP message somehow before getCountry is executed.
I created a class that implements 'SOAPHandler' but somehow I have to tell spring-boot to use this handler before passing the request to getCountry.
Any idea how to do that?
you need to implement an interceptor like:
public class YourClientInterceptor implements ClientInterceptor{
#Override
public boolean handleRequest(MessageContext messageContext)
{
//here you get your request before it is sending
messageContext.getRequest()
...
return true;
}
}
and when you create your WebServiceTemplate you do:
ClientInterceptor[] interceptors = {new YourClientInterceptor ()};
yourWebServiceTemplate.setInterceptors(interceptors);
They work similar with handler.
I have a GWT client that would like to query a RESTful service that returns text/plain. I created a proxy interface:
public interface ConnectionStatusService extends ClientProxy
{
#Get("txt")
public void getVersion(Result<String> callback);
}
But when I'm using the generated proxy class:
ConnectionStatusService service = GWT.create(ConnectionStatusService.class);
it sends a request that accepts Accept application/x-java-serialized-object+gwt according to Firebug, so the server returns HTTP 406 Not Acceptable of course.. :-( How could I make it accept plain text?
I'm using resty-gwt to create restfull web services but I'm not accessing it now from GWT client classes. They have documentation where it's documented.
Hope that helps.