Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jax-ws set connection timeout for reading wsdl and sending request

Our application need to send some request to SOAP service. We use wsimport command to generate class for our client. But sometime when service down or some network problem, our request hang until timeout and that is rather too long. We want to control timeout value so we try serveral method.

For calling service method, after reading from other post, we set something like this:

((BindingProvider) port).getRequestContext().put("sun.net.client.defaultReadTimeout", 3000);
((BindingProvider) port).getRequestContext().put("sun.net.client.defaultConnectTimeout", 10000);

But before that,we have to call get port which will read wsdl file. We try to create URL like this:

url = new URL(null, "http://theirsite/WS?WSDL", new URLStreamHandler() {

    @Override
    protected URLConnection openConnection(URL url) throws IOException {
        logger.info("URLStreamHandler got call!");
        URL clone_url = new URL(url.toString());
        HttpURLConnection clone_connection
                = (HttpURLConnection) clone_url.openConnection();
        clone_connection.setConnectTimeout(5000);
        clone_connection.setReadTimeout(3000);
        return (clone_connection);
    }
});

And then we use this url as parameter when create Service object. But our URLStreamHandler never got call.

We even try to set system property like this:

System.setProperty("sun.net.client.defaultReadTimeout", "" + 3000);
System.setProperty("sun.net.client.defaultConnectTimeout", "" + 5000);

But so far nothing work for us.

So any1 can help me with this case? Or is there a better approach ? Need to mention that we don't want to read wsdl file from local.

like image 318
mameo Avatar asked Jan 28 '15 02:01

mameo


People also ask

What is connection request timeout?

request timeout — a time period required to process an HTTP call: from sending a request to receiving a response. connection timeout — a time period in which a client should establish a connection with a server. socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.


1 Answers

Maybe the properties you are using are not the right ones.

Try these ones:

((javax.xml.ws.BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.connect.timeout",
        Integer.valueOf(timeout));
((javax.xml.ws.BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.request.timeout",
        Integer.valueOf(timeout));

Also, take care, there is a difference between com.sun.xml.ws.request.timeout and com.sun.xml.internal.ws.request.timeout. You should use internal when you are working with JDK JAX-WS implementation.

like image 142
jddsantaella Avatar answered Oct 13 '22 09:10

jddsantaella