Many thanks for the fast reply Sergey. I tried using the ClientRequestFilter instead and set the msg body using:
requestContext.setEntity(uri, null, null) ; When I do a getEntity() straight after all looks ok but the post body is empty when it sends to the stubbing system. I noticed a property on the message org.apache.cxf.empty.request was set to true so I set this to false but still no luck. Are there any other properties I might need to change? Not sure if it's relevant but I also use logging in/out interceptors around the call to WebClient. Many thanks Mandy Sent from a mobile device > On 12 Oct 2014, at 18:43, Sergey Beryozkin <[email protected]> wrote: > > Hi Mandy >> On 11/10/14 11:20, Mandy Warren wrote: >> 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 > > WebClient depends on the interceptor running in a Write phase and it skips > the processing is no actual request object is set, it has this code: > > MessageContentsList objs = MessageContentsList.getContentsList(outMessage); > if (objs == null || objs.size() == 0) { > return; > } > > So may be you should set it too > outMessage.setContent(List.class, Collections.singletonList(uri)); > > Or may be you should do it from a JAX-RS 2.0 ClientRequestFilter ? > > Cheers, Sergey > >> >> Any help much appreciated! >> >> Many thanks >> Mandy >> >> Sent from my iPad > >
