Spring MVC giving Connection refused when connecti

2019-09-01 16:52发布

问题:

Server Side: I have a REST service running on my Ubuntu Laptop ,its a spring boot app with the below in the application properties

server.port: 8443
server.ssl.key-store: keystore.p12
server.ssl.key-store-password: mypassword
server.ssl.keyStoreType: PKCS12
server.ssl.keyAlias: tomcat
server.address:<My Ip Address>

Client Side Code: I created a Web app which calls the Rest service ,and I have configured it to run on Https .Web app is running on Mac Laptop and I have configured in my Web APP.Web APP is a Spring MVC application.

HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
        {
            public boolean verify(String hostname, SSLSession session)
            {
                // ip address of the service URL(like.23.28.244.244)
                if (hostname.equals("10.0.0.191"))
                    return true;
                return false;
            }
        });

When i Click a button on the web page which calls the REST service (which is running on my ubuntu laptop) I get the below exception

org.springframework.web.client.ResourceAccessException: I/O error: Connection refused; nested exception is java.net.ConnectException: Connection refused
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:461)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:385)
    at com.pcap.webapp.HomeController.getPcapInfo(HomeController.java:172)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

So in brief My issue is How do I call my REST service (which is https ,running on ubuntu ,Spring boot ) from my web application (Spring MVC,https,Mac Laptop)

回答1:

I think it's a firewall issue and if it is then you need to add these lines.

    System.setProperty("proxyHost", "yourproxy.server.com");
System.setProperty("proxyPort", "8080");