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

1

6

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.

Burack answered 28/1, 2015 at 2:58 Comment(1)
I think the answer in #2149415 should help you. Btw: Why not downloading the wsdl to local filesystem?Squirmy
S
2

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.

Scapegrace answered 8/2, 2015 at 16:26 Comment(1)
Sorry but im asking about how to timeout request when reading wsdl file since that one run before you can get port.Burack

© 2022 - 2024 — McMap. All rights reserved.