1

I used JaxwsDynamicClientFactory to call https web service, and use the following code to work around the ssl checking, because the webservice ssl certificate is a self-signed one.

    String wsUrl = "https://218.17.179.67:8443/QhicPos/doService?wsdl";
    String method = "doPosRequest";
    QName qName = new QName("http://service.pos.qhic.com/", method);

    HttpsURLConnection.setDefaultSSLSocketFactory(TrustAnyFactory.getInstance().getSslContext().getSocketFactory());
    HostnameVerifier allHostsValid = (hostname, sslSession) -> true;

    // Install the all-trusting host verifier
    HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

    JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
    Client client = clientFactory.createClient(wsUrl);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

    conduit.getClient().setReceiveTimeout(0);
    httpClientPolicy.setConnectionTimeout(6000000);
    httpClientPolicy.setAllowChunking(false);
    httpClientPolicy.setReceiveTimeout(6000000);
    conduit.setClient(httpClientPolicy);

    try {
        Object[] rst = client.invoke(qName, new Object[]{xmlRequest});
        System.out.println(rst[0].toString());
    } catch (Exception e) {
        e.printStackTrace();
    }

But I when i invoke the code, i got the exception:

org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
Waring: Interceptor for   {http://service.pos.qhic.com/}PosServiceImplService#  {http://service.pos.qhic.com/}doPosRequest has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Operation timed out

at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:108)
at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:297)
at HttpsWebServiceClient.getClient(HttpsWebServiceClient.java:65)
at HttpsWebServiceClient.main(HttpsWebServiceClient.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: com.ctc.wstx.exc.WstxIOException: Operation timed out
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:255)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:106)
... 14 more

Caused by: java.net.ConnectException: Operation timed out
...

Which make me confused is that when I use HttpPost to send the soap message(Of course I used some work-around to skip ssl validation), it can successfully return response, but when using JaxwsDynamicClientFatory to generate dynamic client, it fails.

Is is something related with the ssl work-around part of the code?

Can anyone help me? Thanks very much.

  • i noticed that webservice used ip filtering, after making my ip as into the white list, now i was trapped into another exception : connection out – user2605926 Aug 18 '16 at 03:15

2 Answers2

0

java.net.ConnectException: Operation timed out means that your request did not get a response within the timeframe. Check https://stackoverflow.com/a/5663054/6371459

I have reproduced the problem executing your code. The WSDL points to 218.17.179.67/QhicPos/doService that is not accesible for me. This problem is previous to any SSL connection (that in fact is not needed because endpoint is published with http)

Maybe there is a firewall protection or is needed a proxy

Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142
  • I guess I need to specify a SSLContextFactory, but for TLSClientParameters, there is not method called 'setHostnameVerifier', is there somewhere that I can set this? – user2605926 Aug 18 '16 at 13:26
  • The method exists: https://cxf.apache.org/javadoc/latest/org/apache/cxf/configuration/jsse/TLSClientParameters.html#setHostnameVerifier(javax.net.ssl.HostnameVerifier). Maybe is not present in your version. What CXF version are you using? I think `TLSClientParameters.setDisableCNCheck` will also work – pedrofb Aug 18 '16 at 13:34
  • my version is 2.2.12, but actually i can pass the ssl checking phrase, but the webservice invoking raise exception: org.apache.cxf.interceptor.Fault: Operation timed out. Do you have any idea of this problem? Is it due to the server problem or my client's wrong invoking ? – user2605926 Aug 18 '16 at 14:07
  • This means that your request did not get a response within the timeframe. This problem is before SSL. Is there a firewall in your network or do you need to configure a proxy? Check this http://stackoverflow.com/a/5663054/6371459 – pedrofb Aug 18 '16 at 14:26
  • I cannot check whether there is a firewall at home. I will check this when I'm at work tomorrow. Anyway, thank you so much ! – user2605926 Aug 18 '16 at 14:35
  • I have reproduced the problem executing your code. The WSDL points to http://218.17.179.67/QhicPos/doService that is not accesible for me. Maybe is the same problem for you. The TLS parameters I have provided are not needed. I had assumed that the connection to the service would also be SSL and It is plain http – pedrofb Aug 19 '16 at 06:15
0
Following code worked for me
 BusFactory bf = CXFBusFactory.newInstance();
        Bus bus = bf.createBus();
        bus.getInInterceptors().add(new LoggingInInterceptor());
        bus.getOutInterceptors().add(new LoggingOutInterceptor());


        //MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();

        bus.setExtension(new MyHTTPConduitConfigurer(), HTTPConduitConfigurer.class);

        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);


private static class SoapHTTPConduitConfigurer implements HTTPConduitConfigurer {
        public void configure(String name, String address, HTTPConduit c) {

            try{

                if(logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST,"\n Setting TLS and Connection TimeOut :" );
                }
                HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();           
                httpClientPolicy.setConnectionTimeout(itfConfig.getConnectionTimeout());
                httpClientPolicy.setReceiveTimeout(itfConfig.getSoTimeout()); 
                c.setClient(httpClientPolicy);
                if(tlsParams!=null)
                 c.setTlsClientParameters(tlsParams);


            }catch(Exception ex){

            }


        }
    }
Krishna
  • 1
  • 1