1 Şubat 2011 Salı

JAX-WS exception handling

In JAX-WS you can set connection timeout and read timeout several ways. I like the most common use one from System.properties or application server settings.

For example in tomcat you can set connection timeout and read timeout from env.bat/sh

"-Dsun.net.client.defaultConnectTimeout=100 -Dsun.net.client.defaultReadTimeout=10000" the problem is handling timeout exception from client side. You must throws IOException from your methot which call the webservice port.

Example

normally your client will be

private static String helloService() {
tr.murat.NewWebServiceService service = new tr.murat.NewWebServiceService();
tr.murat.NewWebService port = service.getNewWebServicePort();
return port.helloService();
}

when you add throws IOException you can handle the errors.

private static String helloService() throws IOException {
tr.murat.NewWebServiceService service = new tr.murat.NewWebServiceService();
tr.murat.NewWebService port = service.getNewWebServicePort();
return port.helloService();
}

Hiç yorum yok:

Yorum Gönder