HTTP transport error: java.net.ConnectException: Connection timed out: connect in Soap ws client

我只是一个虾纸丫 提交于 2019-12-11 07:57:19

问题


In my JAR client that i developed, When trying to call a soap ws using jax-ws i got connection timeout exception, i want to know what can be the reasons that causes this exception. I am using a remote wsdl, and server certificate for https that must be run in VM arguments.

   -Djavax.net.debug=all
   -Djavax.net.ssl.trustStore=link to my certifacte

How can i run with this arguments? By adding them eclipse.ini file ? Thanks for your help.


回答1:


1. Select you project from the Project Explorer Pane, generally on the left

2. From the Run menu, depending on whether you want to just run it or debug it click either Run or Debug

3. In left pane, select "Java Application and right click and click New"

4. Since you've already selected your project and it contains a "Main" class, it will default the Run/Debug configuration "Name" to the class name. If you have multiple Main's, you may have to click the Search button or manually type in the package path and class name

5. Enter your arguments under "VM arguments" as shown

6. Click Apply, or Apply and the Run if you want to run it immediately

Some notes, you'll likely need the full path to the keystore such as:
-Djavax.net.ssl.trustStore=C:\ADirectory\AnotherDirectory\FinalDirectoryThatContainsYourKeystore\TrustStore.jks

-Djavax.net.debug=all - is going to turn on a MASSIVE amount of debug which if you're not used to reading it, it can be confusing. If the connection works remove that line. If the connection doesn't work - thats when all that debug is useful.

Update: to further troubleshoot HTTP connectivity problems, when at the heart of it thats what a SOAP request is, temporarily remove the -Djavax.net.debug=all and add the following instead:
-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
-Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true
-Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true
-Dcom.sun.xml.internal.ws.transport.http.HttpAdapter.dump=true

This will show you the HTTP headers, response code, request and response body contents. It will also show the URL you are trying to connect to.




回答2:


Adding an additional troubleshooting answer. A great way to test SSL connectivity. Source: 4ndrej awesome SSL Poke GitHUB example

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;

/** Establish a SSL connection to a host and port, writes a byte and
 * prints the response. See
 * http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
 * 
 * JGlass: Code modified for SO to hard code the host and port
 * 
 */
public class SSLPoke {
    public static void main(String[] args) {

        //add the full FQDN to the host here
        String host = "google.com";
        //your port may be 443
        int port = 8443;

        try {
            SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(host, port);

            InputStream in = sslsocket.getInputStream();
            OutputStream out = sslsocket.getOutputStream();

            // Write a test byte to get a reaction :)
            out.write(1);

            while (in.available() > 0) {
                System.out.print(in.read());
            }
            System.out.println("Successfully connected");

        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}


If everything works correctly you'll get "Successfully Connected"



来源:https://stackoverflow.com/questions/52871380/http-transport-error-java-net-connectexception-connection-timed-out-connect-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!