How to test JAX-WS connection timeout

3.5k views Asked by At

I`m trying to test connection timeout property for jaxws client which is deployed on IBM Websphere Application Server 8.5. I set timeout properties the following way:

((BindingProvider) port).getRequestContext().
           put(com.ibm.wsspi.webservices.Constants.RESPONSE_TIMEOUT_PROPERTY, "30");
((BindingProvider) port).getRequestContext().
           put(com.ibm.wsspi.webservices.Constants.CONNECTION_TIMEOUT_PROPERTY, "15";

RESPONSE_TIMEOUT_PROPERTY works fine.

But I have no idea how to test CONNECTION_TIMEOUT_PROPERTY. If webservice is not available during creating an instance of Service I get the following exception:

javax.xml.ws.WebServiceException: The following WSDL exception occurred: 
            WSDLException: faultCode=WSDL4JWrapper : : javax.wsdl.WSDLException: 
            WSDLException: faultCode=WSDL4JWrapper : :
            java.net.ConnectException: Connection refused: connect

If webservice is not available during creating port(invoking getPort(...) method) I get the following exception:

javax.xml.ws.WebServiceException: 
            java.net.ConnectException: HTTP ( 404 ) Not Found address :
            http://myhost:myport/WsServer/helloService

Exceptions are thrown immediately. I suppose I do something wrong. Any pointers would be helpful.

1

There are 1 answers

2
Sarah Phillips On

There needs to be a socket open on the server to accept the connection.

Try something like the following

public static void main(String[] args) {
    int port = Integer.parseInt(args[0]);
    try (ServerSocket serviceStub = new ServerSocket(port)) {
            while (true) {
                serviceStub.accept();
                System.out.println("Something connected");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
}

Run this on the server (with whatever port you need). It will accept a connection but will never do anything which ought to simulate your timeout.

Generally, anything that listens on a port and does nothing should fit the bill.