11 Replies Latest reply on Apr 3, 2015 8:27 AM by asoldano

    Wildfly 8.2 SOAP/SAAJ read time out

    georgemathias

      I recently migrated my project from jboss4 to wildfly 8.2 with java1.8. I have a webservice call using SAAJ which runs fine in command line. But when its run from within wildfly8.2, it times out after 60 seconds. I read from jboss forums that read requests have a default timeout of 60 seconds. So i changed my configuration in standalone.xml to

       

                      <ajp-listener name="ajp" socket-binding="ajp" max-parameters="10000"/>

                      **<http-listener name="default" socket-binding="http" max-parameters="10000" read-timeout="120000"/>**

                      <host name="default-host" alias="localhost">

                          <location name="/" handler="welcome-content"/>

                          <filter-ref name="server-header"/>

                          <filter-ref name="x-powered-by-header"/>

                      </host>

      But it still times out after 60 seconds with following errors.

       

          Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking http://test-server/test/v2.0.0/TestService?wsdl: Read timed out

           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_25]

           at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_25]

           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_25]

           at java.lang.reflect.Constructor.newInstance(Constructor.java:408) [rt.jar:1.8.0_25]

           at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1347)

           at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1331)

           at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)

           at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632)

           at org.jboss.wsf.stack.cxf.saaj.SOAPConnectionImpl.call(SOAPConnectionImpl.java:120)

           ... 38 more

          Caused by: java.net.SocketTimeoutException: Read timed out

           at java.net.SocketInputStream.socketRead0(Native Method) [rt.jar:1.8.0_25]

           at java.net.SocketInputStream.read(SocketInputStream.java:150) [rt.jar:1.8.0_25]

           at java.net.SocketInputStream.read(SocketInputStream.java:121) [rt.jar:1.8.0_25]

           at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) [rt.jar:1.8.0_25]

           at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) [rt.jar:1.8.0_25]

           at java.io.BufferedInputStream.read(BufferedInputStream.java:345) [rt.jar:1.8.0_25]

           at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:703) [rt.jar:1.8.0_25]

           at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647) [rt.jar:1.8.0_25]

           at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1534) [rt.jar:1.8.0_25]

           at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439) [rt.jar:1.8.0_25]

           at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) [rt.jar:1.8.0_25]

           at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.getResponseCode(URLConnectionHTTPConduit.java:266)

           at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1545)

           at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1515)

           at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1318)

       

      I read on stackexchange that i could set timeouts but I don't have to as the program runs fine without timing out from command line so its not saaj timeout issue. I am pretty sure wildfly/undertow is timing the socket read out for some reason.

       

      Currently I am using undertow 1.1 Final that came with wildfly8.2. I tried upgrading undertow to 1.2 beta, still same result.

      Call that fails:

       

                              msgFactory = MessageFactory.newInstance();

                              soapFactory = SOAPFactory.newInstance();

                              soapMessage = msgFactory.createMessage();

                              //Add headers

                              addSoapHeaders(soapMessage,soapFactory,

                                              serviceType,userName,remoteClientAddress,remoteClientHostname,

                                              remoteClientUser,

                                              clientApplicationId);

                              //Add Body

                              addBody(soapMessage,soapFactory,soapRequestDoc,serviceName);

                          logger.debug(soapMessage);

                          soapConnFactory = SOAPConnectionFactory.newInstance();

                          soapConn = soapConnFactory.createConnection();

                          logger.debug("Invoking service ["+serviceName+

                                      "] on WSDL ["+

                                      wsdlLoc+"] ...");

                          responseMsg = soapConn.call(soapMessage, wsdlLoc); // exception is thrown here after 60 seconds.

       

       

      Undertow configuration in wildfly8.2 :

       

              <subsystem xmlns="urn:jboss:domain:undertow:1.2">

                  <buffer-cache name="default"/>

                  <server name="default-server">

                      <ajp-listener name="ajp" socket-binding="ajp" max-parameters="10000"/>

                      <http-listener name="default" socket-binding="http" max-parameters="10000" read-timeout="120000"/>

                      <host name="default-host" alias="localhost">

                          <location name="/" handler="welcome-content"/>

                          <filter-ref name="server-header"/>

                          <filter-ref name="x-powered-by-header"/>

                      </host>

                  </server>

                  <servlet-container name="default">

                      <jsp-config/>

                      <websockets/>

                  </servlet-container>

                  <handlers>

                      <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>

                  </handlers>

                  <filters>

                      <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>

                      <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>

                  </filters>

              </subsystem>

       

      Any help is appreciated.

        • 1. Re: Wildfly 8.2/undertow read time out
          georgemathias

          This works find under jboss7.1.1 with JDK1.7, but does not work under wildfly 8.2 with jdk1.8. I have spent last two days trying to figure out what is terminating socket connection. Any help is greatly appreciated as I am running out of ideas at present.

           

          Thanks

          • 2. Re: Wildfly 8.2/undertow read time out
            georgemathias

            Just tested this in wildfly 8.1 and it occurs there as well. Thanks

            • 3. Re: Wildfly 8.2/undertow read time out
              georgemathias

              Jboss4 - jdk1.5.22 --- WORKS

              jboss 7.1.1 - jdk1.7 --- WORKS

              Wildfly 8.1 - JDK1.7 --- FAILS

              Wildfly 8.1 - JDK1.8 ---FAILS

              Wildfly 8.2 -- JDK1.8 ---FAILS

              WIldfly9.0-BETA---JDK1.8---FAILS

               

              At this point I don't know what else to try out. I don't even know which component is setting that 60 seconds socket read timeout.

               

              Any help is greatly appreciated.

              • 4. Re: Wildfly 8.2/undertow read time out
                ctomc

                According to your stack trace read timeout is happening on client and not on server.

                so setting read-timeout for undertow listeners won't change a thing.

                you need to change it for your WS client.

                • 5. Re: Wildfly 8.2/undertow read time out
                  georgemathias

                  Thanks for the reply and I am sorry if I did not make it clear in my original post. I am calling a another webservice from a servlet that is running in wildfly8.2. So caller is servlet in wildfly 8.2 and the target is on another jboss instance.

                  Call is this:                     responseMsg = soapConn.call(soapMessage, wsdlLoc); // exception is thrown here after 60 seconds.

                   

                  If I call the webservice from outside wildfly it works fine.

                   

                  Thanks

                  • 6. Re: Wildfly 8.2/undertow read time out
                    georgemathias

                    I tried few more things to rule general connection timeout out. I tried calling another TestServlet from a servlet running within wildfly which worked fine.

                    I have a TargetServlet running on another instance of jboss.

                     

                    I wrote following to call TestServet from a wildfly 8.2 container and that worked fine. So there are no issues in opening general socket connection.

                     

                    url = "http://localhost:3080/TestWeb/servlet/TestServlet";

                     

                    servletURL = new java.net.URL(url);
                    servletConnection = servletURL.openConnection();
                    System.out.println("Connected to servlet, Sending request ");
                    // inform the connection that we will send output and accept input
                    servletConnection.setDoInput(true);
                    servletConnection.setDoOutput(true);
                    // Don't use a cached version of URL connection.
                    servletConnection.setUseCaches(false);
                    servletConnection.setDefaultUseCaches(false);

                     

                    // Specify the content type that we will send binary data
                    servletConnection.setRequestProperty("Content-Type",contentType);
                    // send the student object to the servlet using serialization
                    outputToServlet = new java.io.ObjectOutputStream(servletConnection
                    .getOutputStream());

                     

                    // serialize the object
                    outputToServlet.writeObject(message);

                     

                    outputToServlet.flush();
                    outputToServlet.close();
                    System.out.println("Request sent, Waiting for the server response...");

                     

                     

                    inputFromServlet = new java.io.ObjectInputStream(servletConnection
                    .getInputStream());
                    returnObject = (Object) inputFromServlet.readObject();
                    System.out.println("Response recieved successfully.");

                     

                    And now, my webservice call that uses SOAPConnectionFactory from within wildfly times out in 60 seconds. There's gotta be a setting that wildfly has for socket timeout which defaults to 60. Looking for some pointers as to what that might be.

                     

                    Following is the code that timesout within servlet.

                     

                      SOAPConnection soapConn = null;

                      String wsdlLoc=endPointAddress;

                      String resp = "";

                      MessageFactory msgFactory;

                      SOAPFactory soapFactory;

                      SOAPMessage soapMessage;

                      SOAPConnectionFactory soapConnFactory;

                      SOAPMessage responseMsg;

                     

                     

                      try

                      {

                       if (wsdlLoc == null)

                       throw new SOAPException("Error: Endpoint address is NULL.");

                       msgFactory = MessageFactory.newInstance();

                       soapFactory = SOAPFactory.newInstance();

                       soapMessage = msgFactory.createMessage();

                       //Add headers

                       addSoapHeaders(soapMessage,soapFactory,

                       serviceType,userName,remoteClientAddress,remoteClientHostname,

                       remoteClientUser,

                       clientApplicationId);

                       //Add Body

                       addBody(soapMessage,soapFactory,soapRequestDoc,serviceName);

                                 System.out.println(soapMessage);

                          soapConnFactory = SOAPConnectionFactory.newInstance();     

                          soapConn = soapConnFactory.createConnection();

                          System.out.println("Invoking service ["+serviceName+

                       "] on WSDL ["+

                       wsdlLoc+"] ..."); 

                          responseMsg = soapConn.call(soapMessage, wsdlLoc);

                          System.out.println("Call completed ["+serviceName+

                       "] on WSDL ["+

                       wsdlLoc+"]!");

                          resp = processResponseMessageStringParser(responseMsg);

                       System.out.println("Return Document [" + resp + "]");

                      }

                      catch (Exception e)

                      {

                       e.printStackTrace();

                      }

                      finally

                      {

                       try

                       {

                       if (soapConn != null)

                       soapConn.close();

                       }

                       catch (Exception e)

                       {

                       e.printStackTrace();

                       }

                      }

                     

                    Thanks.

                    • 8. Re: Wildfly 8.2/undertow read time out
                      georgemathias

                      I tried following:

                       

                      1. Since i am using SAAJ and not JAX-RS' service call, I couldn't use BindingProverProperties to set the connection time out. Hence I tried adding following:

                          System.setProperty("com.sun.xml.internal.ws.request.timeout", "120000");

                      just before

                      msgFactory = MessageFactory.newInstance();
                      soapFactory = SOAPFactory.newInstance();
                      soapMessage = msgFactory.createMessage();

                       

                      Did not help.

                       

                      2. I also used following code to create connection with timeout settings, and that did not help either.

                       

                            new URL(new URL("http://yourserver.yourdomain.com/"),



                      wsdlLoc,
                                    new URLStreamHandler() {
                                      @Override
                                      protected URLConnection openConnection(URL url) throws IOException {
                                        URL target = new URL(url.toString());
                                        URLConnection connection = target.openConnection();
                                        // Connection settings
                                        connection.setConnectTimeout(10000); // 10 sec
                                        connection.setReadTimeout(120000); // 2 min
                                        return(connection);
                                      }
                                    });

                       

                          responseMsg = connection.call(soapMessage, endpoint);

                      Still timed out after 60 seconds.

                       

                      At this I am positive there is a setting that wildfly supplies that is defaulted to 60 seconds.

                       

                      Thanks

                      • 9. Re: Wildfly 8.2/undertow read time out
                        georgemathias

                        Looks like CXF defaults ReceiveTimeout to 60 seconds, but there is no way for me to override this value when using SAAJ webservice client calls. At this point I have no choice but either to go back to jboss7.1.1 or find another application server for project.

                        • 10. Re: Wildfly 8.2/undertow read time out
                          georgemathias

                          I was able to fix this by changing receive timeout in apache-cxf source and rebuilding it for wildfly8.2

                          • 11. Re: Wildfly 8.2/undertow read time out
                            asoldano

                            OK, I've commented on [WFLY-4476] Unable to configure cxf socket timeout in wildfly_8.2.Final - JBoss Issue Tracker , but let me shed some light here too, for better understanding.

                            You're tyring to use the SAAJ API, in particular the SOAPConnection, for sending SOAP messages. As the whole WS stack in JBoss AS / WildFly is internally based on Apache CXF, at a given point we've also provided an internally CXF based implementation of SOAPConnection. JavaEE says that SOAPConnection instances are to be retrieved using javax.xml.soap.SOAPConnectionFactory, which in turn is created with SOAPConnectionFactory#newInstance(). The SOAPConnectionFactory implementation to use is resolved with the Service API.

                            Now, what happened in some old JBoss AS versions is that the JBossWS/CXF implementation of SOAPConnectionFactory was not properly resolved, hence the user was ending up getting the SOAPConnectionFactory from its JDK, the same he gets when running out-of-container with no special classpath setup.

                            In order for change the timeout settings with the JBossWS/CXF implementation of SOAPConnection(Factory), you need to wait for JBWS-3901 to be included in WildFly (or you can patch Wildfly with latest JBossWS compiled from sources).

                            Alternatively, you can try specifying a different SOAPConnectionFactory to be used, through a javax.xml.soap.SOAPConnectionFactory system property or a META-INF/services/javax.xml.soap.SOAPConnectionFactory in your deployment (the RI should be com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory).