Q: How do I set a timeout when using  WSDL2Java  stubs?

A: There is a setTimeout method on the org.apache.axis.client.Stub class, which is the class all emitted stubs extend.

Here is how to set the timeout given a service named Foo:

 FooServiceLocator loc = new FooServiceLocator();
 FooService binding = loc.getFooService();
 org.apache.axis.client.Stub s = (Stub) binding; 
 s.setTimeout(1000);  // 1 second, in miliseconds 

The default timeout in Axis 1.1 and later is 60 seconds. Axis 1.0 did not have a default timeout (i.e. it defaulted to 0). This timeout value is set on the HTTP socket and is not a connection timeout, which requires implementation we do not have as of Axis 1.1.

Q: When I do setTimeout(15*10000) or more bigger,I still get the error below when I connect http url, but localhost url is ok:

java.net.ConnectException: Connection timed out: connect  
        at java.net.PlainSocketImpl.socketConnect(Native Method) 
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) 
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171) 
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158) 
        at java.net.Socket.connect(Socket.java:452) 
        at java.net.Socket.connect(Socket.java:402) 
        at sun.net.NetworkClient.doConnect(NetworkClient.java:139) 
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:402) 
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:618) 
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:306) 
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:267) 
        at sun.net.www.http.HttpClient.New(HttpClient.java:339) 
        at sun.net.www.http.HttpClient.New(HttpClient.java:320) 
        at sun.net.www.http.HttpClient.New(HttpClient.java:315) 
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:512)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:489)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:617) 
        at java.net.URL.openStream(URL.java:913)  
        at org.apache.xerces.readers.DefaultReaderFactory.createReader(DefaultReaderFactory.java:149)
        at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:491)
        at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:312) 
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1080)  
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:195) 
        at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:322)
        at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:367)
        at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:384) 
        at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:245)  
        at java.lang.Thread.run(Thread.java:534)
java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method)  
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305) 
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171) 
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158) 
        at java.net.Socket.connect(Socket.java:452) 
        at java.net.Socket.connect(Socket.java:402) 
        at sun.net.NetworkClient.doConnect(NetworkClient.java:139) 
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:402) 
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:618) 
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:306) 
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:267) 
        at sun.net.www.http.HttpClient.New(HttpClient.java:339) 
        at sun.net.www.http.HttpClient.New(HttpClient.java:320) 
        at sun.net.www.http.HttpClient.New(HttpClient.java:315) 
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:512)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:489)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:617) 
        at java.net.URL.openStream(URL.java:913)  
        at org.apache.xerces.readers.DefaultReaderFactory.createReader(DefaultReaderFactory.java:149)
        at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:491)
        at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:312)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1080)
        at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:195) 
        at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:322)  
        at org.apache.axis.utils.XMLUtils.newDocument(XMLUtils.java:367) 
        at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:384) 
        at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:245)  
        at java.lang.Thread.run(Thread.java:534) 

does there need some other setting?please tell me.Thanks.

FrontPage/Axis/JavaTimeout (last edited 2009-09-20 22:47:21 by localhost)