0 Replies Latest reply on Nov 11, 2019 5:36 AM by arun0281

    java.lang.RuntimeException: Couldn't parse stream - when making soap service calls from wildfly 11

    arun0281

      I am getting the below exception when trying to send a soap request to remote web service. I don't see any issues connecting to this remote web service when using soapUI tool or when running a standalone client program which uses JAXWS-RI. I am seeing this

      issue only when I call the soap service call from inside wildfly container as wildfly uses apache CXF. Client and server are instances of same application both running wildfly 11 where client instance is pulling some configuration from server instance for doing some migration activity.

       

      java.lang.RuntimeException: Couldn't parse stream.

              at

      org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1729)

              at

      org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:127)

              at

      org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)

              at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:805)

              at

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

              at

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

              at

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

              at

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

              at

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

              at

      org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)

              at

      org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)

              at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:518)

              at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:427)

              at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:328)

              at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:281)

              at

      org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)

              at

      org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139)

              at com.sun.proxy.$Proxy232.ping(Unknown Source)

      Caused by: com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x8b

      (at char #2, byte #-1)

              at

      com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:578)

              at

      com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:633)

              at

      com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:657)

              at

      com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:342)

              at

      __redirected.__XMLInputFactory.createXMLStreamReader(__XMLInputFactory.java:143)

      [jboss-modules.jar:1.6.1.Final]

              at

      org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1727)

              ... 87 more

      Caused by: java.io.CharConversionException: Invalid UTF-8 start byte 0x8b

      (at char #2, byte #-1)

              at

      com.ctc.wstx.io.UTF8Reader.reportInvalidInitial(UTF8Reader.java:304)

              at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:190)

              at

      com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.java:254)

              at

      com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.java:134)

              at

      com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:573)

              ... 92 more

       

      Sample code trusting all certificates:

       

      TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()

              {

                  @Override

                  public java.security.cert.X509Certificate[] getAcceptedIssuers()

                  {

                      try

                      {

                          KeyStore ks = KeyStore.getInstance("JKS");

                          TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("SunX509", "SunJSSE");

                          tmFactory.init(ks);

                          TrustManager[] tmfs = tmFactory.getTrustManagers();

                          for (TrustManager tmf : tmfs)

                          {

                              if (tmf instanceof X509TrustManager)

                              {

                                  return ((X509TrustManager) tmf).getAcceptedIssuers();

                              }

                          }

                      }

                      catch (Exception ex)

                      {

                          // exception handling

                      }

                      return new X509Certificate[] {};

                  }

       

                  @Override

                  public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)

                  {

                  }

       

                  @Override

                  public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)

                  {

                  }

              } };

        

          SSLContext sc = null;

          try

              {

                  System.setProperty("org.apache.axis.components.net.SecureSocketFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");

                  sc = SSLContext.getInstance("TLSv1.2");

                  sc.init(null, trustAllCerts, new java.security.SecureRandom());

                  HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

              }

              catch (Exception e)

              {

                  // exception handling          

              }

       

              HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()

              {

                  @Override

                  public boolean verify(String urlHostname, SSLSession certHostname)

                  {

                      return true;

                  }

              });

              if (System.getProperty("jboss.home.dir") != null)

              {

                  System.setProperty("org.jboss.security.ignoreHttpsHost", "true");

              }

       

       

      Http headers that are set in BindingProvider.

       

      Map<String, List&lt;String>> httpHeaders = new HashMap<String,List&lt;String>>();

      httpHeaders.put("Accept-Encoding",Collections.singletonList("gzip,deflate"));

      httpHeaders.put("Content-Type",Collections.singletonList("text/xml;charset=UTF-8"));

      ((BindingProvider) services).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

       

      Looks like SSL session is not established with remote server and request fails in client side only even before hitting remote server. I tried setting HttpConduit also but no luck.

       

      Client client = ClientProxy.getClient(port);

      HTTPConduit conduit = (HTTPConduit) client.getConduit();

      TLSClientParameters tlsParams = new TLSClientParameters();

      tlsParams.setSSLSocketFactory(sc.getSocketFactory());

      conduit.setTlsClientParameters(tlsParams);

       

      Added gzipFilter also in wildfly undertow's host configuration.

       

      <filter-ref name="gzipFilter" predicate="exists('%{o,Content-Type}') and regex(pattern='(?:application/javascript|text/css|text/html|text/xml|application/json)(;.*)?', value=%{o,Content-Type}, full-match=true)"/>

       

      Any help on this would be appreciated.