Client webservice timeout on CXF webservice on Jboss

What a riveting blog title, but this one is mainly for people to find for a solution via google.

Problem: you have a JBoss server with a webservice CLIENT talking to a webservice somewhere else, and you keep getting timeouts, most likely with the following error

org.apache.cxf.phase.PhaseInterceptorChain doIntercept 
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
        at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(

If this happens after 60 second (the CXF default timeout), then it is most likely not the target server refusing you, but your client timing out (if your luckily you can get to the target server logs and confirm). Sooo lets extend the client timeout period, personally i like doing this via server configs and indeed that was my first port of call (do a google search for CXF.xml for more details), however even after i figured out what to call the file (cxf.xml, jbossws-cxf.xml, or jboss-cxf.xml) and got it in the right place (inside the WEB-INF of the project for access via POJO’s) the darn thing just ignored me, incidentally the following is the “meat” of the file which should change the timeout (in fact the “*.http-conduit” changes the timeouts on all webservice clients on that app.

<http-conf:conduit name="*.http-conduit"> 
<http-conf:client ConnectionTimeout="120000" /> 

After a prolonged swear, and discovery that i was not the only person who had had this problem on JBoss for CFX clients, I binned that and went into the code, now if your getting this problem then your all ready making a web service client call so you will already have a line like this

Service client = service.yourwebservice();

if you cant find one, and make all you “client stubs” with something like WSDL2Java or via your IDE, do a search for “extends Service”, you are now looking for a line like this

public class myfunkyservice_Service extends Service { 

when you find it, it will tell you what you should go back and look for ie

funkyservice = new myfunkyservice_Service(URL);
myfunkyservice_Service client = funkyservice.yourwebservice();

well something like that anyway, now bung the following code in after it (changing ‘myfunkyservice_Service’ to what ever you client service is called, and not forgetting that the timeout is in milliseconds)

Client cl = ClientProxy.getClient(myfunkyservice_Service);
HTTPConduit http = (HTTPConduit) cl.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

that’s the code done, it should all work swimmingly, one exception to this is if you get the error

at org.apache.cxf.frontend.ClientProxy.getClient(

What this bundle of joy means is that sun’s library is loading with a higher priority that the CFX lib, if this is on a server its time to get dirty with your config, if this is on your IDE then, go to your projects properties –> Java build path –> Order and export, and bump the CXF lib up (try it at the top)

there you go, now wasn’t that fun 🙂
Old Comments
##### Nancy(15/11/2011 20:01:02 GMT)
Thank you very very VERY MUUUUUUUCHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Really
##### Mark Myers(16/11/2011 19:58:48 GMT)
@Nancy your welcome, glad it helped
##### Mark Myers(27/11/2011 21:48:18 GMT)
@Anneta no prob
##### lucky7175(20/12/2011 06:27:43 GMT)
It works this way

webClient = WebClient.create(URI);
HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
##### lucky7175(20/12/2011 06:08:44 GMT)
I dont have control on server code and we use cxf webclient. Can u Pls. let me know how i can set only in client side
##### Mark Myers(22/12/2011 14:42:50 GMT)
yup thank you luckly, isn’t that snippet of code already in the blog at the bottom?

Leave a Reply

Your email address will not be published.