suki2.jpg

« making any ISO | Main| Java DB connections in the real world »

Client webservice timeout on CXF webservice on Jboss

Category CXF JBOSS webservices timeout
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(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:226)

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" />
</http-conf:conduit>

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();
httpClientPolicy.setConnectionTimeout(120000);
httpClientPolicy.setReceiveTimeout(120000);
http.setClient(httpClientPolicy);

oh, don't forget your imports!!

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

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

java.lang.ClassCastException: com.sun.xml.ws.client.sei.SEIStub
at org.apache.cxf.frontend.ClientProxy.getClient(ClientProxy.java:93)

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
Bookmark and Share

Comments

Gravatar Image1 - glad i could help Emoticon

Gravatar Image2 - Thank you very very VERY MUUUUUUUCHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Really Emoticon

Gravatar Image3 - @Nancy your welcome, glad it helped

Gravatar Image4 - Thanks for help!

Gravatar Image5 - @Anneta no prob

Gravatar Image6 - 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

Gravatar Image7 - It works this way

webClient = WebClient.create(URI);
HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
conduit.getClient().setConnectionTimeout(120000);

Gravatar Image8 - yup thank you luckly, isn't that snippet of code already in the blog at the bottom?

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Avalable for on site contract in

 

Hire Me

Directly:

Curriculum Vitae

As a member of:
ldc_badge.gif

Contact My Grubby Hide

Skype Linkin Main Me Twitter

Get LDC Tshirts

All profits go to the Children’s Cancer Association (CCA) in the US.

Social ASW Rating

Enter a URL: