3 Replies Latest reply on May 7, 2015 10:52 AM by paul_s

    My WebService Client always gets "Connection refused" Exception

    virtuellesnugat

      Hello everybody,

       

      I'm facing the "Connection refused" execption when I try to use my JAX-WS based webservice on my JBoss AS 7.1.1.

      The Service itself seem to work properly, because the wsdl is generated and accessible via Browser and SoapUI.

      In SoapUI I've added my services and they work fine.

       

      The server-side is implemented this way:

      {code}

      @Stateless

      @WebService (

          portName = "AppointmentFacadePort",

          targetNamespace = "http://facade.appointment.wsServe.mmoell.de/")

      @SOAPBinding (style = Style.DOCUMENT, use = Use.LITERAL)

      public class AppointmentFacade {

      {code}

       

      I guess everything else is set anyway. But I'm not quite sure how to handle the "wsdlLocation" attribute of the @WebService Annotation.

       

      I've tried many ways to implement the ws-client, but everytime I get the connection refused Exception. So I've checked the following:

       

      •     the firewall doesn't block my requests (Browser, SoapUI, and remote calls via JNDI lookup succeed)
      •     I'm not using a proxy
      •     I'm using a host entry "master.de" which points to the correct address (everything else still works, and using the real ip doesn't help)

       

      So let's take a look at the client-side implementations I've tried:

       

      - using the generated classes by consuming the wsdl (I've used jboss' wsconsume tool and jdk's wsimport tool):

      {code}

      AppointmentFacadeService serv = new AppointmentFacadeService();

      AppointmentFacade port = serv.getPort(AppointmentFacade.class);

      System.out.println(port.getDateByString("05.09.2012 12:55"));

      {code}

       

      - another approach:

      {code}

      QName serviceName = new QName("http://facade.appointment.wsServe.mmoell.de/", "AppointmentFacadeService");

      String serviceURL = "http://master.de:8080/wsServe/AppointmentFacade";

      URL wsdlURL = new URL(serviceURL  + "?wsdl");

      Service service = Service.create(wsdlURL, serviceName);

      AppointmentFacade proxy = (AppointmentFacade)service.getPort(AppointmentFacade.class);

      System.out.println(proxy.getDateByString("05.09.2012 12:55"));

      {code}

       

      I tried a few more variations (for example the eclipse ws-client wizard), but the connection was still refused everytime.

      Exception Stack Trace I get, no matter which client-approach I use:

      {code}

      Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused: connect

       

          at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(Unknown Source)

       

          at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source)

       

          at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(Unknown Source)

       

          at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(Unknown Source)

       

          at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)

       

          at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)

       

          at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)

       

          at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)

       

          at com.sun.xml.internal.ws.client.Stub.process(Unknown Source)

       

          at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(Unknown Source)

       

          at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

       

          at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

       

          at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)

       

          at $Proxy29.getDateByString(Unknown Source)

       

          at de.mmoell.wsServe.client.Main.main(Main.java:25)

       

      Caused by: java.net.ConnectException: Connection refused: connect

       

          at java.net.DualStackPlainSocketImpl.connect0(Native Method)

       

          at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

       

          at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

       

          at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

       

          at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

       

          at java.net.PlainSocketImpl.connect(Unknown Source)

       

          at java.net.SocksSocketImpl.connect(Unknown Source)

       

          at java.net.Socket.connect(Unknown Source)

       

          at java.net.Socket.connect(Unknown Source)

       

          at sun.net.NetworkClient.doConnect(Unknown Source)

       

          at sun.net.www.http.HttpClient.openServer(Unknown Source)

       

          at sun.net.www.http.HttpClient.openServer(Unknown Source)

       

          at sun.net.www.http.HttpClient.<init>(Unknown Source)

       

          at sun.net.www.http.HttpClient.New(Unknown Source)

       

          at sun.net.www.http.HttpClient.New(Unknown Source)

       

          at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)

       

          at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)

       

          at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)

       

          at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)

       

          ... 15 more

      {code}

       

      Has anyone an idea how to solve this problem? I'm trying to solve it for weeks now, but I won't succeed.

      Any help would be greatly appreciated!

       

      Best regards, Matthias

        • 1. Re: My WebService Client always gets "Connection refused" Exception
          virtuellesnugat

          After I found out, thanks to wireshark, that the client tried to address localhost instead of the specified location, I knew what happened:

           

          In the generated wsdl was the following part included:

          {code:xml}

          <wsdl:service name="AppointmentFacadeService">

              <wsdl:port binding="tns:AppointmentFacadeServiceSoapBinding" name="AppointmentFacadePort">

                  <soap:address location="http://localhost:8080/wsServe/AppointmentFacade"/>

              </wsdl:port>

          </wsdl:service>

          {code:xml}

           

          As my server is running on a vm, it's pretty obvious what caused the problem.

           

          I was able to solve it by editing the standalone-full.xml

          {code:xml}

          <subsystem xmlns="urn:jboss:domain:webservices:1.1">

              <modify-wsdl-address>true</modify-wsdl-address>

              <wsdl-host>192.168.178.121</wsdl-host>

              <endpoint-config name="Standard-Endpoint-Config"/>

              <endpoint-config name="Recording-Endpoint-Config">

                  <pre-handler-chain name="recording-handlers" protocol-bindings="##SOAP11_HTTP ##SOAP11_HTTP_MTOM ##SOAP12_HTTP ##SOAP12_HTTP_MTOM">

                      <handler name="RecordingHandler" class="org.jboss.ws.common.invocation.RecordingServerHandler"/>

                  </pre-handler-chain>

              </endpoint-config>

          </subsystem>

          {code:xml}

           

          This way, the above mentioned part of the wsdl was changed to this:

          {code:xml}

          <wsdl:service name="AppointmentFacadeService">

              <wsdl:port binding="tns:AppointmentFacadeServiceSoapBinding" name="AppointmentFacadePort">

                  <soap:address location="http://192.168.178.121:8080/wsServe/AppointmentFacade"/>

              </wsdl:port>

          </wsdl:service>

          {code:xml}

           

          And now my java se client addresses the correct service, though it picked the correct url to retrieve the wsdl.

           

          I still got two questions left:

          1. Why was SoapUI able to call the correct service? I know, I had to edit the interface endpoint by changing the url. But which method can I use to change it manually on client side in the java code?
          2. It seems to be a very bad style to hardcode the machine's url into the configuration file in order to get the expected wsdl created. Is there a constant I can use like "{jboss-external-ipv4-address}"?

           

          Best regards, Matthias

          1 of 1 people found this helpful
          • 2. Re: My WebService Client always gets "Connection refused" Exception
            spyhunter99

            cast your port object to BindingProvider object. Then use that to get the request context and "put" a BindingProvider.ENDPOINT_ADDRESS_PROPERTY to override it.

            1 of 1 people found this helpful
            • 3. Re: My WebService Client always gets "Connection refused" Exception
              paul_s

              Probably too late for you, but maybe helpful to others:

              In JBoss EAP 6.4 you can change the

              {code:xml}

              <wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>

              {code:xml}

               

              to

              {code:xml}

              <wsdl-host>${jboss.bind.address:0.0.0.0}</wsdl-host>

              {code:xml}

               

              Which solves your second question