title: Axis2 Web Service client fails AxisFault: Address already in use: NET_Bind
body: <p>I am developping a web service using Axis 2 and tomcat maven plugin (launched with Eclipse embedded Maven). 
  For testing purpose, I developped a web service client using AXIOM.</p>
  
  <p><strong>When I run the client on my system (Windows 7 Pro), I got various behavior, most of them failures :</strong></p>
  
  <pre><code>org.apache.axis2.AxisFault: Address already in use: NET_Bind
      at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
      at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
      at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
      at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
      at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
      at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
      at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
      at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
      at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
      at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
      at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
      at com.nm.bdl.Launcher.main(Launcher.java:82)
  Caused by: java.net.BindException: Address already in use: NET_Bind
      at java.net.PlainSocketImpl.socketBind(Native Method)
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
      at java.net.Socket.bind(Socket.java:582)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:615)
      at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:139)
      at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
      at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
      at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
      at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
      at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
      at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
      at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
      at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
      ... 10 more
  </code></pre>
  
  <p>A very few cases, the client program succeeds reaching the web service.</p>
  
  <p>The web service and the client programs are working fine, I tested both on others computers (still Windows 7 Pro). It also works when I run the web service client from another computer with success.</p>
  
  <p>Here is the definition of tomcat plugin in the pom.xml :</p>
  
  <pre><code>  &lt;plugin&gt;
      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
      &lt;artifactId&gt;tomcat-maven-plugin&lt;/artifactId&gt;        
      &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;jaxen&lt;/groupId&gt;
            &lt;artifactId&gt;jaxen&lt;/artifactId&gt;
            &lt;version&gt;full&lt;/version&gt;
        &lt;/dependency&gt;
      &lt;/dependencies&gt;       
      &lt;configuration&gt;         
        &lt;server&gt;tomcat-development-server&lt;/server&gt;
          &lt;port&gt;9966&lt;/port&gt;
          &lt;path&gt;/&lt;/path&gt;
          &lt;systemProperties&gt;
              &lt;logs.dir&gt;logs&lt;/logs.dir&gt;
          &lt;/systemProperties&gt;
          &lt;useNaming&gt;true&lt;/useNaming&gt;
          &lt;contextFile&gt;${basedir}/src/test/resources/tomcatconf/context.xml&lt;/contextFile&gt;
          &lt;!-- 
          &lt;configurationDir&gt;${basedir}/src/main/tomcatconf&lt;/configurationDir&gt;
           --&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;run-tomcat&lt;/id&gt;
          &lt;phase&gt;pre-integration-test&lt;/phase&gt;
          &lt;goals&gt;
            &lt;goal&gt;run&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>The web service client program :</p>
  
  <pre><code>  static String address_WS   = "http://localhost:9966/services/GetGedFile";
  
    /**
     * @param args
     */
    public static void main(String[] args) {
  
      final EndpointReference targetService = new EndpointReference(address_WS);
  
      /* ... */
  
      try {
        Options options = new Options();
  
        ServiceClient client = new ServiceClient();
        options.setTo(targetService);
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
        options.setTimeOutInMilliSeconds(360000);
  
        client.setOptions(options); 
  
        OMElement result = client.sendReceive(serviceOp);
  
        String response = result.getFirstElement().getText();
        System.err.println("WS call result: " + response);
  
        OMNode node = result.getFirstElement().getFirstOMChild();
        if (node instanceof OMText) {                  
          OMText txt = (OMText) node;                  
  
          String data = txt.getText();
          byte[] dataBytes = Base64.decode(data);
  
          String realString = new String(dataBytes,"UTF-8");
          System.out.println("pseudo binary data received : " + realString);
        }
  
      } catch(AxisFault af) {
        af.printStackTrace();
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      }
    }
  </code></pre>
  
  <p>I have tried to clean windows services, to stop the antivirus, to use other ports (different from port 9966), replace localhost by the IP adress : in vain.
  I have monitored my system with TCPView to check that axis web service uses same port as configured in the tomcat plugin.</p>
  
  <p>Any other idea please ?</p>
  
  <p>EDIT: another error stacktrace</p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (org.apache.axis2.context.AbstractContext).
  log4j:WARN Please initialize the log4j system properly.
  org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxIOException: Unrecognized Windows Sockets error: -1: socket available
      at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
      at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
      at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
      at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
      at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
      at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
      at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
      at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
      at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
      at com.nm.bdl.Launcher.main(Launcher.java:82)
  Caused by: org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxIOException: Unrecognized Windows Sockets error: -1: socket available
      at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createXMLStreamReader(AbstractOMMetaFactory.java:63)
      at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:129)
      at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:426)
      at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:405)
      at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:55)
      at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:179)
      at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
      at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
      ... 8 more
  Caused by: com.ctc.wstx.exc.WstxIOException: Unrecognized Windows Sockets error: -1: socket available
      at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:548)
      at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:604)
      at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:629)
      at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:324)
      at org.apache.axiom.util.stax.wrapper.XMLInputFactoryWrapper.createXMLStreamReader(XMLInputFactoryWrapper.java:95)
      at org.apache.axiom.util.stax.wrapper.WrappingXMLInputFactory.createXMLStreamReader(WrappingXMLInputFactory.java:116)
      at org.apache.axiom.util.stax.wrapper.XMLInputFactoryWrapper.createXMLStreamReader(XMLInputFactoryWrapper.java:95)
      at org.apache.axiom.util.stax.wrapper.WrappingXMLInputFactory.createXMLStreamReader(WrappingXMLInputFactory.java:116)
      at org.apache.axiom.util.stax.wrapper.XMLInputFactoryWrapper.createXMLStreamReader(XMLInputFactoryWrapper.java:95)
      at org.apache.axiom.om.util.StAXUtils$1.run(StAXUtils.java:201)
      at java.security.AccessController.doPrivileged(AccessController.java:241)
      at org.apache.axiom.om.util.StAXUtils.createXMLStreamReader(StAXUtils.java:197)
      at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createXMLStreamReader(AbstractOMMetaFactory.java:55)
      ... 15 more
  Caused by: java.net.SocketException: Unrecognized Windows Sockets error: -1: socket available
      at java.net.PlainSocketImpl.socketAvailable(Native Method)
      at java.net.PlainSocketImpl.available(PlainSocketImpl.java:487)
      at java.net.SocketInputStream.available(SocketInputStream.java:246)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:332)
      at org.apache.commons.httpclient.WireLogInputStream.read(WireLogInputStream.java:69)
      at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:182)
      at java.io.FilterInputStream.read(FilterInputStream.java:134)
      at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108)
      at java.io.FilterInputStream.read(FilterInputStream.java:134)
      at org.apache.axiom.om.util.DetachableInputStream.read(DetachableInputStream.java:147)
      at java.io.FilterInputStream.read(FilterInputStream.java:134)
      at java.io.PushbackInputStream.read(PushbackInputStream.java:182)
      at java.io.FilterInputStream.read(FilterInputStream.java:113)
      at com.ctc.wstx.io.UTF8Reader.loadMore(UTF8Reader.java:365)
      at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:110)
      at com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.java:245)
      at com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.java:132)
      at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:543)
      ... 27 more
  </code></pre>