Hi,
We have developed a way for Rest calls sent using WebClient to be transparently
sent either to a real backend or to our stubbing system. We have implemented
this via an interceptor which intercepts the outgoing request and changes the
url if certain headers (to indicate stubbing should be used) are present.
The stubbing system only supports POST at the moment and basically just matches
the content of the POST body to determine the response to send back. So I am
trying to work around this by converting a GET to a POST and placing the URL
into the POST body as something to match against. Bizarre I know :-)
I have managed to change the HTTP request method ok, and can get access to the
uri string but I just can't work out how to set the message content (which will
be empty) to be the uri string.
This is what I have so far...
if (HttpMethod.GET.equalsIgnoreCase((String)
message.get(Message.HTTP_REQUEST_METHOD))) {
// turn the GET into a POST
message.put(Message.HTTP_REQUEST_METHOD, HttpMethod.POST);
// and put the URL (minus the base path) into the POST body
String uri = (String) message.get(Message.REQUEST_URI);
OutputStream os = message.getContent(OutputStream.class);
CachedOutputStream cs = new CachedOutputStream();
try {
cs.write(uri.getBytes());
message.setContent(OutputStream.class, cs);
} catch (IOException ioe) {
ioe.printStackTrace();
}
Note my interceptor runs at SETUP phase and I am using CXF 2.7.12
Any help much appreciated!
Many thanks
Mandy
Sent from my iPad