12

I've trouble setting jax-ws timeout. My code is:

@WebServiceClient(name = "VoipDBJDBCService", targetNamespace = "http://db.server.voipmeter.jextreme.eu/", wsdlLocation = "http://trace0.nyc.blinkmind.com:8080/voipdb?wsdl")
public class VoipDBJDBCService extends Service {
    public VoipDBJDBCService(URL wsdlLocation) {
        super(wsdlLocation, new QName("http://db.server.voipmeter.jextreme.eu/", "VoipDBJDBCService"));
    }

    @WebEndpoint(name = "VoipDBJDBCPort")
    public VoipDB getVoipDBJDBCPort() {
        return super.getPort(new QName("http://db.server.voipmeter.jextreme.eu/", "VoipDBJDBCPort"), VoipDB.class);
    }
}

And the usage:

VoipDB db = new VoipDBJDBCService(new URL(url)).getVoipDBJDBCPort();

How do i Hook in timeouts ? I've found "solution" here: https://jax-ws.dev.java.net/guide/HTTP_Timeouts.html but I don't know where I shall hook it in. How to obtain proxy ? When I call getPort client tries to connect and then hangs forever if server is not responding.

UPDATE: This code is invoked from within applets init() method if that makes any difference.

Lukasz
  • 3,135
  • 4
  • 20
  • 24

5 Answers5

7

With Metro/Glassfish...

//1 minute for connection
((BindingProvider) wsPort).getRequestContext().put("com.sun.xml.ws.connect.timeout", 1 * 60 * 1000); 

//3 minutos for request
((BindingProvider) wsPort).getRequestContext().put("com.sun.xml.ws.request.timeout", 3 * 60 * 1000); 
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
Wanderson Santos
  • 2,917
  • 1
  • 26
  • 16
  • 2
    Actually that is what said in 1st answer (and in the question itself) Also maybe it makes sense to `import com.sun.xml.ws.developer.JAXWSProperties` and use `JAXWSProperties.CONNECT_TIMEOUT` and `JAXWSProperties.REQUEST_TIMEOUT` if someone is not afraid to couple with Sun internals. – dma_k Sep 29 '10 at 08:03
  • How do I get wsPort instance? – mvmn Feb 07 '12 at 22:06
1

If you are using a Sun JRE, you can set the following system properties for default network connect and read timeouts (in milliseconds). I haven't tried these with the JAX-WS client, but they ought work there as well:

sun.net.client.defaultConnectTimeout
sun.net.client.defaultReadTimeout

Addition: I missed your last part of the question where you said that you are doing this in an applet. If the applet is running with default permissions, you are probably not allowed to set the system properties.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
jarnbjo
  • 33,923
  • 7
  • 70
  • 94
  • Applet is signed. This is hard to reproduce. Because client hangs when server hangs (not when is down). – Lukasz Jul 01 '10 at 12:15
  • 1
    You can simulate a hanging TCP server with this server code: ServerSocket serverSocket = new ServerSocket(PORT); while (true) { serverSocket.accept(); } Just accept, but never read or write anything on the "dummy server" side. – auramo Aug 12 '10 at 11:29
1
ProxyWs proxy = (ProxyWs) factory.create();
Client client = ClientProxy.getClient(proxy);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);
http.setClient(httpClientPolicy);

This worked for me.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
0

You can cast your VoipDB object to BindingProvider. So in the example in the link you've given just replace proxy by db and you're good to go.

musiKk
  • 14,751
  • 4
  • 55
  • 82
  • 1
    This actually doesn't work because client hangs on the line where getPort is called. – Lukasz Jun 28 '10 at 09:26
  • Well, that's all you can do with the method provided in the link. jax-ws downloads the WSDL of the service to create the proxy. Most likely this is what causes trouble for you. The only thing I could think of right now is to download a local copy of the WSDL and use that but of course this is not really elegant... – musiKk Jun 28 '10 at 09:49
0

Here is one example

public void testConfigureTimeout() throws Exception
{
   //Set timeout until a connection is established
   ((BindingProvider)port).getRequestContext()
   .put("javax.xml.ws.client.connectionTimeout", "6000");

   //Set timeout until the response is received
   ((BindingProvider) port).getRequestContext()
   .put("javax.xml.ws.client.receiveTimeout", "1000");

    port.echo("testTimeout");
}
WitVault
  • 23,445
  • 19
  • 103
  • 133